torch API Reference
Full documentation for torch (2.13.0+cpu)
torch.AVG
Python Library Documentation: AggregationType in module torch object class AggregationType(pybind11_builtins.pybind11_object) | Method resolution order: | AggregationType | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __eq__(...) | __eq__(self: object, other: object, /) -> bool | | __getstate__(...) | __getstate__(self: object, /) -> int | | __hash__(...) | __hash__(self: object, /) -> int | | __index__(...) | __index__(self: torch._C.AggregationType, /) -> int | | __init__(...) | __init__(self: torch._C.AggregationType, value: typing.SupportsInt | typing.SupportsIndex) -> None | | __int__(...) | __int__(self: torch._C.AggregationType, /) -> int | | __ne__(...) | __ne__(self: object, other: object, /) -> bool | | __repr__(...) | __repr__(self: object, /) -> str | | __setstate__(...) | __setstate__(self: torch._C.AggregationType, state: typing.SupportsInt | typing.SupportsIndex, /) -> None | | __str__(...) | __str__(self: object, /) -> str | | ---------------------------------------------------------------------- | Readonly properties defined here: | | __members__ | | name | name(self: object, /) -> str | | value | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | AVG = <AggregationType.AVG: 1> | | SUM = <AggregationType.SUM: 0> | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.AcceleratorError
Python Library Documentation: class AcceleratorError in module torch class AcceleratorError(builtins.RuntimeError) | Exception raised while executing on device | | Method resolution order: | AcceleratorError | builtins.RuntimeError | builtins.Exception | builtins.BaseException | builtins.object | | Data descriptors defined here: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Methods inherited from builtins.RuntimeError: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods inherited from builtins.RuntimeError: | | __new__(*args, **kwargs) class method of builtins.RuntimeError | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
torch.AggregationType
Python Library Documentation: class AggregationType in module torch class AggregationType(pybind11_builtins.pybind11_object) | Method resolution order: | AggregationType | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __eq__(...) | __eq__(self: object, other: object, /) -> bool | | __getstate__(...) | __getstate__(self: object, /) -> int | | __hash__(...) | __hash__(self: object, /) -> int | | __index__(...) | __index__(self: torch._C.AggregationType, /) -> int | | __init__(...) | __init__(self: torch._C.AggregationType, value: typing.SupportsInt | typing.SupportsIndex) -> None | | __int__(...) | __int__(self: torch._C.AggregationType, /) -> int | | __ne__(...) | __ne__(self: object, other: object, /) -> bool | | __repr__(...) | __repr__(self: object, /) -> str | | __setstate__(...) | __setstate__(self: torch._C.AggregationType, state: typing.SupportsInt | typing.SupportsIndex, /) -> None | | __str__(...) | __str__(self: object, /) -> str | | ---------------------------------------------------------------------- | Readonly properties defined here: | | __members__ | | name | name(self: object, /) -> str | | value | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | AVG = <AggregationType.AVG: 1> | | SUM = <AggregationType.SUM: 0> | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.AliasDb
Python Library Documentation: class AliasDb in module torch class AliasDb(pybind11_builtins.pybind11_object) | Method resolution order: | AliasDb | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __str__(...) | __str__(self: torch._C.AliasDb) -> str | | dump(...) | dump(self: torch._C.AliasDb) -> None | | has_writers(...) | has_writers(self: torch._C.AliasDb, arg0: torch::jit::Value) -> bool | | may_contain_alias(...) | may_contain_alias(self: torch._C.AliasDb, arg0: torch::jit::Value, arg1: torch::jit::Value) -> bool | | move_after_topologically_valid(...) | move_after_topologically_valid(self: torch._C.AliasDb, arg0: torch::jit::Node, arg1: torch::jit::Node) -> bool | | move_before_topologically_valid(...) | move_before_topologically_valid(self: torch._C.AliasDb, arg0: torch::jit::Node, arg1: torch::jit::Node) -> bool | | to_graphviz_str(...) | to_graphviz_str(self: torch._C.AliasDb) -> str | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.AnyType
Python Library Documentation: class AnyType in module torch class AnyType(Type) | Method resolution order: | AnyType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.AnyType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Argument
Python Library Documentation: class Argument in module torch class Argument(pybind11_builtins.pybind11_object) | Method resolution order: | Argument | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.Argument, arg0: str, arg1: c10::Type, arg2: typing.SupportsInt | typing.SupportsIndex | None, arg3: IValue | None, arg4: bool, arg5: c10::AliasInfo | None) -> None | | has_default_value(...) | has_default_value(self: torch._C.Argument) -> bool | | ---------------------------------------------------------------------- | Readonly properties defined here: | | N | | alias_info | | default_value | | is_out | | is_write | | kwarg_only | | name | | real_type | | type | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ArgumentSpec
Python Library Documentation: class ArgumentSpec in module torch class ArgumentSpec(pybind11_builtins.pybind11_object) | Method resolution order: | ArgumentSpec | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.AwaitType
Python Library Documentation: class AwaitType in module torch class AwaitType(Type) | Method resolution order: | AwaitType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.AwaitType, arg0: torch._C.Type) -> None | | getElementType(...) | getElementType(self: torch._C.AwaitType) -> torch._C.Type | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.BFloat16Storage
Python Library Documentation: class BFloat16Storage in module torch
class BFloat16Storage(torch.storage._LegacyStorage)
| BFloat16Storage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| BFloat16Storage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.bfloat16
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.BFloat16Tensor
Python Library Documentation: class BFloat16Tensor in module torch
class BFloat16Tensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.bfloat16
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
torch.BenchmarkConfig
Python Library Documentation: class BenchmarkConfig in module torch class BenchmarkConfig(pybind11_builtins.pybind11_object) | Method resolution order: | BenchmarkConfig | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.BenchmarkConfig) -> None | | ---------------------------------------------------------------------- | Data descriptors defined here: | | num_calling_threads | | num_iters | | num_warmup_iters | | num_worker_threads | | profiler_output_path | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.BenchmarkExecutionStats
Python Library Documentation: class BenchmarkExecutionStats in module torch class BenchmarkExecutionStats(pybind11_builtins.pybind11_object) | Method resolution order: | BenchmarkExecutionStats | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | latency_avg_ms | | num_iters | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Block
Python Library Documentation: class Block in module torch class Block(pybind11_builtins.pybind11_object) | Method resolution order: | Block | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | addInputToBlock(...) | addInputToBlock(self: torch._C.Block) -> torch._C.Value | | addNode(...) | addNode(self: torch._C.Block, arg0: str, arg1: collections.abc.Sequence[torch._C.Value]) -> torch::jit::Node | | findAllNodes(...) | findAllNodes(self: torch._C.Block, kind: str, recurse: bool = True) -> list[torch::jit::Node] | | Find all nodes | | findNode(...) | findNode(self: torch._C.Block, kind: str, recurse: bool = True) -> torch::jit::Node | | Find Node | | inputs(...) | inputs(self: torch._C.Block) -> collections.abc.Iterator[torch._C.Value] | | nodes(...) | nodes(self: torch._C.Block) -> collections.abc.Iterator[torch::jit::Node] | | outputs(...) | outputs(self: torch._C.Block) -> collections.abc.Iterator[torch._C.Value] | | owningNode(...) | owningNode(self: torch._C.Block) -> torch::jit::Node | | paramNode(...) | paramNode(self: torch._C.Block) -> torch::jit::Node | | registerOutput(...) | registerOutput(self: torch._C.Block, arg0: torch._C.Value) -> int | | returnNode(...) | returnNode(self: torch._C.Block) -> torch::jit::Node | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.BoolStorage
Python Library Documentation: class BoolStorage in module torch
class BoolStorage(torch.storage._LegacyStorage)
| BoolStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| BoolStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.bool
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.BoolTensor
Python Library Documentation: class BoolTensor in module torch
class BoolTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.bool
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
torch.BoolType
Python Library Documentation: class BoolType in module torch class BoolType(Type) | Method resolution order: | BoolType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.BoolType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.BufferDict
Python Library Documentation: class BufferDict in module torch class BufferDict(pybind11_builtins.pybind11_object) | Method resolution order: | BufferDict | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.BufferDict, arg0: torch._C.ScriptModule) -> None | | contains(...) | contains(self: torch._C.BufferDict, arg0: str) -> bool | | getattr(...) | getattr(self: torch._C.BufferDict, arg0: str) -> object | | items(...) | items(self: torch._C.BufferDict) -> list[tuple[str, object]] | | setattr(...) | setattr(self: torch._C.BufferDict, arg0: str, arg1: object) -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ByteStorage
Python Library Documentation: class ByteStorage in module torch
class ByteStorage(torch.storage._LegacyStorage)
| ByteStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| # NOTE: New <type>Storage classes should never be added. When adding a new
| # dtype, use torch.storage.TypedStorage directly.
|
| Method resolution order:
| ByteStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.uint8
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.ByteTensor
Python Library Documentation: class ByteTensor in module torch
class ByteTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.uint8
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
torch.CallStack
Python Library Documentation: class CallStack in module torch class CallStack(pybind11_builtins.pybind11_object) | Method resolution order: | CallStack | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.CallStack, arg0: str, arg1: torch._C._jit_tree_views.SourceRange) -> None | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Capsule
Python Library Documentation: class Capsule in module torch class Capsule(pybind11_builtins.pybind11_object) | Method resolution order: | Capsule | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.CharStorage
Python Library Documentation: class CharStorage in module torch
class CharStorage(torch.storage._LegacyStorage)
| CharStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| CharStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.int8
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.CharTensor
Python Library Documentation: class CharTensor in module torch
class CharTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.int8
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
torch.ClassType
Python Library Documentation: class ClassType in module torch class ClassType(Type) | Method resolution order: | ClassType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.ClassType, arg0: str) -> None | | method_names(...) | method_names(self: torch._C.ClassType) -> list[str] | | name(...) | name(self: torch._C.ClassType) -> str | | qualified_name(...) | qualified_name(self: torch._C.ClassType) -> str | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Code
Python Library Documentation: class Code in module torch class Code(pybind11_builtins.pybind11_object) | Method resolution order: | Code | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | differentiable_op_executor_states(...) | differentiable_op_executor_states(self: torch._C.Code) -> list[torch::jit::GraphExecutorState] | | grad_executor_states(...) | grad_executor_states(self: torch._C.Code) -> list[torch::jit::GraphExecutorState] | | num_bailouts(...) | num_bailouts(self: torch._C.Code) -> int | | request_bailout(...) | request_bailout(self: torch._C.Code, arg0: typing.SupportsInt | typing.SupportsIndex) -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.CompilationUnit
Python Library Documentation: class CompilationUnit in module torch.jit class CompilationUnit(pybind11_builtins.pybind11_object) | Method resolution order: | CompilationUnit | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __getattr__(...) | __getattr__(self: torch._C.CompilationUnit, arg0: str) -> torch::jit::StrongFunctionPtr | | __init__(...) | __init__(self: torch._C.CompilationUnit, lang: str = '', _frames_up: typing.SupportsInt | typing.SupportsIndex = 0) -> None | | create_function(...) | create_function(self: torch._C.CompilationUnit, qualified_name: str, graph: torch._C.Graph, should_mangle: bool = False) -> torch::jit::StrongFunctionPtr | | define(...) | define(self: torch._C.CompilationUnit, src: str, rcb: collections.abc.Callable[[str], object] = None, _frames_up: typing.SupportsInt | typing.SupportsIndex = 0) -> None | | drop_all_functions(...) | drop_all_functions(self: torch._C.CompilationUnit) -> None | | find_function(...) | find_function(self: torch._C.CompilationUnit, arg0: str) -> torch::jit::StrongFunctionPtr | None | | get_class(...) | get_class(self: torch._C.CompilationUnit, arg0: str) -> torch._C.ClassType | | get_functions(...) | get_functions(self: torch._C.CompilationUnit) -> list[torch::jit::StrongFunctionPtr] | | get_interface(...) | get_interface(self: torch._C.CompilationUnit, arg0: str) -> torch._C.InterfaceType | | set_optimized(...) | set_optimized(self: torch._C.CompilationUnit, arg0: bool) -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.CompleteArgumentSpec
Python Library Documentation: class CompleteArgumentSpec in module torch class CompleteArgumentSpec(pybind11_builtins.pybind11_object) | Method resolution order: | CompleteArgumentSpec | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __repr__(...) | __repr__(self: torch._C.CompleteArgumentSpec) -> str | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ComplexDoubleStorage
Python Library Documentation: class ComplexDoubleStorage in module torch
class ComplexDoubleStorage(torch.storage._LegacyStorage)
| ComplexDoubleStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| ComplexDoubleStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.complex128
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.ComplexFloatStorage
Python Library Documentation: class ComplexFloatStorage in module torch
class ComplexFloatStorage(torch.storage._LegacyStorage)
| ComplexFloatStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| ComplexFloatStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.complex64
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.ComplexType
Python Library Documentation: class ComplexType in module torch class ComplexType(Type) | Method resolution order: | ComplexType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.ComplexType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ConcreteModuleType
Python Library Documentation: class ConcreteModuleType in module torch class ConcreteModuleType(pybind11_builtins.pybind11_object) | Method resolution order: | ConcreteModuleType | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | dump(...) | dump(self: torch._C.ConcreteModuleType) -> None | | equals(...) | equals(*args, **kwargs) | Overloaded function. | | 1. equals(self: torch._C.ConcreteModuleType, arg0: torch._C.ConcreteModuleType) -> bool | | 2. equals(self: torch._C.ConcreteModuleType, arg0: torch._C.ConcreteModuleTypeBuilder) -> bool | | get_attributes(...) | get_attributes(self: torch._C.ConcreteModuleType) -> dict[str, tuple[torch._C.Type, bool]] | | get_constants(...) | get_constants(self: torch._C.ConcreteModuleType) -> dict[str, object] | | get_modules(...) | get_modules(self: torch._C.ConcreteModuleType) -> list[tuple[str, torch._C.ConcreteModuleType]] | | is_ignored_attribute(...) | is_ignored_attribute(self: torch._C.ConcreteModuleType, arg0: str) -> bool | | ---------------------------------------------------------------------- | Static methods defined here: | | from_jit_type(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | from_jit_type(arg0: torch._C.Type) -> torch._C.ConcreteModuleType | | ---------------------------------------------------------------------- | Readonly properties defined here: | | jit_type | | py_class | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ConcreteModuleTypeBuilder
Python Library Documentation: class ConcreteModuleTypeBuilder in module torch class ConcreteModuleTypeBuilder(pybind11_builtins.pybind11_object) | Method resolution order: | ConcreteModuleTypeBuilder | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.ConcreteModuleTypeBuilder, arg0: object) -> None | | add_attribute(...) | add_attribute(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: torch._C.Type, arg2: bool, arg3: bool) -> None | | add_builtin_function(...) | add_builtin_function(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: str) -> None | | add_constant(...) | add_constant(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: object) -> None | | add_failed_attribute(...) | add_failed_attribute(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: str) -> None | | add_forward_hook(...) | add_forward_hook(self: torch._C.ConcreteModuleTypeBuilder, arg0: object) -> None | | add_forward_pre_hook(...) | add_forward_pre_hook(self: torch._C.ConcreteModuleTypeBuilder, arg0: object) -> None | | add_function_attribute(...) | add_function_attribute(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: torch._C.Type, arg2: object) -> None | | add_ignored_attribute(...) | add_ignored_attribute(self: torch._C.ConcreteModuleTypeBuilder, arg0: str) -> None | | add_ignored_attributes(...) | add_ignored_attributes(self: torch._C.ConcreteModuleTypeBuilder, arg0: collections.abc.Sequence[str]) -> None | | add_module(...) | add_module(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: torch::jit::ConcreteModuleType) -> None | | add_overload(...) | add_overload(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: collections.abc.Sequence[str]) -> None | | build(...) | build(self: torch._C.ConcreteModuleTypeBuilder) -> torch::jit::ConcreteModuleType | | equals(...) | equals(self: torch._C.ConcreteModuleTypeBuilder, arg0: torch._C.ConcreteModuleTypeBuilder) -> bool | | set_module_dict(...) | set_module_dict(self: torch._C.ConcreteModuleTypeBuilder) -> None | | set_module_list(...) | set_module_list(self: torch._C.ConcreteModuleTypeBuilder) -> None | | set_parameter_dict(...) | set_parameter_dict(self: torch._C.ConcreteModuleTypeBuilder) -> None | | set_parameter_list(...) | set_parameter_list(self: torch._C.ConcreteModuleTypeBuilder) -> None | | set_poisoned(...) | set_poisoned(self: torch._C.ConcreteModuleTypeBuilder) -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.DeepCopyMemoTable
Python Library Documentation: class DeepCopyMemoTable in module torch class DeepCopyMemoTable(pybind11_builtins.pybind11_object) | Method resolution order: | DeepCopyMemoTable | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.DeserializationStorageContext
Python Library Documentation: class DeserializationStorageContext in module torch class DeserializationStorageContext(pybind11_builtins.pybind11_object) | Method resolution order: | DeserializationStorageContext | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.DeserializationStorageContext) -> None | | add_storage(...) | add_storage(self: torch._C.DeserializationStorageContext, arg0: str, arg1: torch.Tensor) -> None | | get_storage(...) | get_storage(self: torch._C.DeserializationStorageContext, arg0: str, arg1: object) -> torch.Tensor | | has_storage(...) | has_storage(self: torch._C.DeserializationStorageContext, arg0: str) -> bool | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.DeviceObjType
Python Library Documentation: class DeviceObjType in module torch class DeviceObjType(Type) | Method resolution order: | DeviceObjType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.DeviceObjType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.DictType
Python Library Documentation: class DictType in module torch class DictType(Type) | Method resolution order: | DictType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.DictType, arg0: torch._C.Type, arg1: torch._C.Type) -> None | | getKeyType(...) | getKeyType(self: torch._C.DictType) -> torch._C.Type | | getValueType(...) | getValueType(self: torch._C.DictType) -> torch._C.Type | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.DisableTorchFunction
Python Library Documentation: class DisableTorchFunction in module torch._C class DisableTorchFunction(builtins.object) | Methods defined here: | | __enter__(...) | | __exit__(...) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature.
torch.DisableTorchFunctionSubclass
Python Library Documentation: class DisableTorchFunctionSubclass in module torch._C class DisableTorchFunctionSubclass(builtins.object) | Methods defined here: | | __enter__(...) | | __exit__(...) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature.
torch.DispatchKey
Python Library Documentation: class DispatchKey in module torch class DispatchKey(pybind11_builtins.pybind11_object) | Method resolution order: | DispatchKey | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __eq__(...) | __eq__(self: object, other: object, /) -> bool | | __getstate__(...) | __getstate__(self: object, /) -> int | | __hash__(...) | __hash__(self: object, /) -> int | | __index__(...) | __index__(self: torch._C.DispatchKey, /) -> int | | __init__(...) | __init__(self: torch._C.DispatchKey, value: typing.SupportsInt | typing.SupportsIndex) -> None | | __int__(...) | __int__(self: torch._C.DispatchKey, /) -> int | | __ne__(...) | __ne__(self: object, other: object, /) -> bool | | __repr__(...) | __repr__(self: object, /) -> str | | __setstate__(...) | __setstate__(self: torch._C.DispatchKey, state: typing.SupportsInt | typing.SupportsIndex, /) -> None | | __str__(...) | __str__(self: object, /) -> str | | ---------------------------------------------------------------------- | Readonly properties defined here: | | __members__ | | name | name(self: object, /) -> str | | value | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | ADInplaceOrView = <DispatchKey.ADInplaceOrView: 19> | | AutocastCPU = <DispatchKey.AutocastCPU: 24> | | AutocastCUDA = <DispatchKey.AutocastCUDA: 32> | | AutocastHPU = <DispatchKey.AutocastHPU: 29> | | AutocastIPU = <DispatchKey.AutocastIPU: 28> | | AutocastMPS = <DispatchKey.AutocastMPS: 31> | | AutocastPrivateUse1 = <DispatchKey.AutocastPrivateUse1: 33> | | AutocastXPU = <DispatchKey.AutocastXPU: 27> | | Autograd = <DispatchKey.Autograd: 150> | | AutogradCPU = <DispatchKey.AutogradCPU: 134> | | AutogradCUDA = <DispatchKey.AutogradCUDA: 135> | | AutogradFunctionality = <DispatchKey.AutogradFunctionality: 21> | | AutogradHIP = <DispatchKey.AutogradHIP: 136> | | AutogradHPU = <DispatchKey.AutogradHPU: 141> | | AutogradIPU = <DispatchKey.AutogradIPU: 139> | | AutogradLazy = <DispatchKey.AutogradLazy: 143> | | AutogradMAIA = <DispatchKey.AutogradMAIA: 145> | | AutogradMPS = <DispatchKey.AutogradMPS: 138> | | AutogradMTIA = <DispatchKey.AutogradMTIA: 144> | | AutogradMeta = <DispatchKey.AutogradMeta: 149> | | AutogradNestedTensor = <DispatchKey.AutogradNestedTensor: 22> | | AutogradOther = <DispatchKey.AutogradOther: 20> | | AutogradPrivateUse1 = <DispatchKey.AutogradPrivateUse1: 146> | | AutogradPrivateUse2 = <DispatchKey.AutogradPrivateUse2: 147> | | AutogradPrivateUse3 = <DispatchKey.AutogradPrivateUse3: 148> | | AutogradVE = <DispatchKey.AutogradVE: 142> | | AutogradXLA = <DispatchKey.AutogradXLA: 137> | | AutogradXPU = <DispatchKey.AutogradXPU: 140> | | BackendSelect = <DispatchKey.BackendSelect: 11> | | CPU = <DispatchKey.CPU: 49> | | CUDA = <DispatchKey.CUDA: 50> | | CompositeExplicitAutograd = <DispatchKey.CompositeExplicitAutograd: 15... | | CompositeExplicitAutogradNonFunctional = <DispatchKey.CompositeExplici... | | CompositeImplicitAutograd = <DispatchKey.CompositeImplicitAutograd: 15... | | CompositeImplicitAutogradNestedTensor = <DispatchKey.CompositeImplicit... | | Conjugate = <DispatchKey.Conjugate: 16> | | Dense = <DispatchKey.Dense: 1> | | EndOfAutogradFunctionalityBackends = <DispatchKey.AutogradMeta: 149> | | EndOfDenseBackends = <DispatchKey.Meta: 64> | | EndOfNestedTensorBackends = <DispatchKey.NestedTensorMeta: 132> | | EndOfQuantizedBackends = <DispatchKey.QuantizedMeta: 81> | | EndOfSparseBackends = <DispatchKey.SparseMeta: 98> | | EndOfSparseCsrBackends = <DispatchKey.SparseCsrMeta: 115> | | FuncTorchBatched = <DispatchKey.FuncTorchBatched: 34> | | FuncTorchBatchedDecomposition = <DispatchKey.FuncTorchBatchedDecomposi... | | FuncTorchDynamicLayerBackMode = <DispatchKey.FuncTorchDynamicLayerBack... | | FuncTorchDynamicLayerFrontMode = <DispatchKey.FuncTorchDynamicLayerFro... | | FuncTorchGradWrapper = <DispatchKey.FuncTorchGradWrapper: 39> | | FuncTorchVmapMode = <DispatchKey.FuncTorchVmapMode: 36> | | Functionalize = <DispatchKey.Functionalize: 15> | | HIP = <DispatchKey.HIP: 51> | | HPU = <DispatchKey.HPU: 56> | | IPU = <DispatchKey.IPU: 54> | | Lazy = <DispatchKey.Lazy: 58> | | MAIA = <DispatchKey.MAIA: 60> | | MPS = <DispatchKey.MPS: 53> | | MTIA = <DispatchKey.MTIA: 59> | | Meta = <DispatchKey.Meta: 64> | | Negative = <DispatchKey.Negative: 17> | | NestedTensor = <DispatchKey.NestedTensor: 10> | | NestedTensorCPU = <DispatchKey.NestedTensorCPU: 117> | | NestedTensorCUDA = <DispatchKey.NestedTensorCUDA: 118> | | NestedTensorHIP = <DispatchKey.NestedTensorHIP: 119> | | NestedTensorHPU = <DispatchKey.NestedTensorHPU: 124> | | NestedTensorIPU = <DispatchKey.NestedTensorIPU: 122> | | NestedTensorLazy = <DispatchKey.NestedTensorLazy: 126> | | NestedTensorMAIA = <DispatchKey.NestedTensorMAIA: 128> | | NestedTensorMPS = <DispatchKey.NestedTensorMPS: 121> | | NestedTensorMTIA = <DispatchKey.NestedTensorMTIA: 127> | | NestedTensorMeta = <DispatchKey.NestedTensorMeta: 132> | | NestedTensorPrivateUse1 = <DispatchKey.NestedTensorPrivateUse1: 129> | | NestedTensorPrivateUse2 = <DispatchKey.NestedTensorPrivateUse2: 130> | | NestedTensorPrivateUse3 = <DispatchKey.NestedTensorPrivateUse3: 131> | | NestedTensorVE = <DispatchKey.NestedTensorVE: 125> | | NestedTensorXLA = <DispatchKey.NestedTensorXLA: 120> | | NestedTensorXPU = <DispatchKey.NestedTensorXPU: 123> | | PreDispatch = <DispatchKey.PreDispatch: 45> | | PrivateUse1 = <DispatchKey.PrivateUse1: 61> | | PrivateUse2 = <DispatchKey.PrivateUse2: 62> | | PrivateUse3 = <DispatchKey.PrivateUse3: 63> | | Python = <DispatchKey.Python: 13> | | PythonDispatcher = <DispatchKey.PythonDispatcher: 46> | | PythonTLSSnapshot = <DispatchKey.PythonTLSSnapshot: 41> | | Quantized = <DispatchKey.Quantized: 5> | | QuantizedCPU = <DispatchKey.QuantizedCPU: 66> | | QuantizedCUDA = <DispatchKey.QuantizedCUDA: 67> | | QuantizedHIP = <DispatchKey.QuantizedHIP: 68> | | QuantizedHPU = <DispatchKey.QuantizedHPU: 73> | | QuantizedIPU = <DispatchKey.QuantizedIPU: 71> | | QuantizedLazy = <DispatchKey.QuantizedLazy: 75> | | QuantizedMAIA = <DispatchKey.QuantizedMAIA: 77> | | QuantizedMPS = <DispatchKey.QuantizedMPS: 70> | | QuantizedMTIA = <DispatchKey.QuantizedMTIA: 76> | | QuantizedMeta = <DispatchKey.QuantizedMeta: 81> | | QuantizedPrivateUse1 = <DispatchKey.QuantizedPrivateUse1: 78> | | QuantizedPrivateUse2 = <DispatchKey.QuantizedPrivateUse2: 79> | | QuantizedPrivateUse3 = <DispatchKey.QuantizedPrivateUse3: 80> | | QuantizedVE = <DispatchKey.QuantizedVE: 74> | | QuantizedXLA = <DispatchKey.QuantizedXLA: 69> | | QuantizedXPU = <DispatchKey.QuantizedXPU: 72> | | Sparse = <DispatchKey.Sparse: 8> | | SparseCPU = <DispatchKey.SparseCPU: 83> | | SparseCUDA = <DispatchKey.SparseCUDA: 84> | | SparseCsr = <DispatchKey.SparseCsr: 9> | | SparseCsrCPU = <DispatchKey.SparseCsrCPU: 100> | | SparseCsrCUDA = <DispatchKey.SparseCsrCUDA: 101> | | SparseCsrHIP = <DispatchKey.SparseCsrHIP: 102> | | SparseCsrHPU = <DispatchKey.SparseCsrHPU: 107> | | SparseCsrIPU = <DispatchKey.SparseCsrIPU: 105> | | SparseCsrLazy = <DispatchKey.SparseCsrLazy: 109> | | SparseCsrMAIA = <DispatchKey.SparseCsrMAIA: 111> | | SparseCsrMPS = <DispatchKey.SparseCsrMPS: 104> | | SparseCsrMTIA = <DispatchKey.SparseCsrMTIA: 110> | | SparseCsrMeta = <DispatchKey.SparseCsrMeta: 115> | | SparseCsrPrivateUse1 = <DispatchKey.SparseCsrPrivateUse1: 112> | | SparseCsrPrivateUse2 = <DispatchKey.SparseCsrPrivateUse2: 113> | | SparseCsrPrivateUse3 = <DispatchKey.SparseCsrPrivateUse3: 114> | | SparseCsrVE = <DispatchKey.SparseCsrVE: 108> | | SparseCsrXLA = <DispatchKey.SparseCsrXLA: 103> | | SparseCsrXPU = <DispatchKey.SparseCsrXPU: 106> | | SparseHIP = <DispatchKey.SparseHIP: 85> | | SparseHPU = <DispatchKey.SparseHPU: 90> | | SparseIPU = <DispatchKey.SparseIPU: 88> | | SparseLazy = <DispatchKey.SparseLazy: 92> | | SparseMAIA = <DispatchKey.SparseMAIA: 94> | | SparseMPS = <DispatchKey.SparseMPS: 87> | | SparseMTIA = <DispatchKey.SparseMTIA: 93> | | SparseMeta = <DispatchKey.SparseMeta: 98> | | SparsePrivateUse1 = <DispatchKey.SparsePrivateUse1: 95> | | SparsePrivateUse2 = <DispatchKey.SparsePrivateUse2: 96> | | SparsePrivateUse3 = <DispatchKey.SparsePrivateUse3: 97> | | SparseVE = <DispatchKey.SparseVE: 91> | | SparseXLA = <DispatchKey.SparseXLA: 86> | | SparseXPU = <DispatchKey.SparseXPU: 89> | | StartOfAutogradFunctionalityBackends = <DispatchKey.StartOfAutogradFun... | | StartOfDenseBackends = <DispatchKey.StartOfDenseBackends: 48> | | StartOfNestedTensorBackends = <DispatchKey.StartOfNestedTensorBackends... | | StartOfQuantizedBackends = <DispatchKey.StartOfQuantizedBackends: 65> | | StartOfSparseBackends = <DispatchKey.StartOfSparseBackends: 82> | | StartOfSparseCsrBackends = <DispatchKey.StartOfSparseCsrBackends: 99> | | Undefined = <DispatchKey.Undefined: 0> | | VE = <DispatchKey.VE: 57> | | XLA = <DispatchKey.XLA: 52> | | XPU = <DispatchKey.XPU: 55> | | ZeroTensor = <DispatchKey.ZeroTensor: 18> | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.DispatchKeySet
Python Library Documentation: class DispatchKeySet in module torch class DispatchKeySet(pybind11_builtins.pybind11_object) | Method resolution order: | DispatchKeySet | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __and__(...) | __and__(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKeySet) -> torch._C.DispatchKeySet | | __eq__(...) | __eq__(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKeySet) -> bool | | __getstate__(...) | __getstate__(self: torch._C.DispatchKeySet, /) -> tuple[int] | | __init__(...) | __init__(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKey) -> None | | __or__(...) | __or__(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKeySet) -> torch._C.DispatchKeySet | | __repr__(...) | __repr__(self: torch._C.DispatchKeySet) -> str | | __setstate__(...) | __setstate__(self: torch._C.DispatchKeySet, arg0: tuple) -> None | | __sub__(...) | __sub__(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKeySet) -> torch._C.DispatchKeySet | | add(...) | add(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKey) -> torch._C.DispatchKeySet | | has(...) | has(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKey) -> bool | | highestPriorityTypeId(...) | highestPriorityTypeId(self: torch._C.DispatchKeySet) -> torch._C.DispatchKey | | raw_repr(...) | raw_repr(self: torch._C.DispatchKeySet) -> int | | remove(...) | remove(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKey) -> torch._C.DispatchKeySet | | ---------------------------------------------------------------------- | Static methods defined here: | | from_raw_repr(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | from_raw_repr(arg0: typing.SupportsInt | typing.SupportsIndex) -> torch._C.DispatchKeySet | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.DoubleStorage
Python Library Documentation: class DoubleStorage in module torch
class DoubleStorage(torch.storage._LegacyStorage)
| DoubleStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| DoubleStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.float64
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.DoubleTensor
Python Library Documentation: class DoubleTensor in module torch
class DoubleTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.float64
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
torch.EnumType
Python Library Documentation: class EnumType in module torch class EnumType(Type) | Method resolution order: | EnumType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.EnumType, arg0: str, arg1: torch._C.Type, arg2: collections.abc.Sequence[object]) -> None | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ErrorReport
Python Library Documentation: class ErrorReport in module torch class ErrorReport(pybind11_builtins.pybind11_object) | Method resolution order: | ErrorReport | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.ErrorReport, arg0: torch._C._jit_tree_views.SourceRange) -> None | | what(...) | what(self: torch._C.ErrorReport) -> str | | ---------------------------------------------------------------------- | Static methods defined here: | | call_stack(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | call_stack() -> str | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Event
Python Library Documentation: class Event in module torch class Event(builtins.object) | Event(device=None, *, enable_timing=False, blocking=False, interprocess=False) | | Query and record Stream status to identify or control dependencies across Stream and measure timing. | | Arguments: | device (:class:`torch.device`, optional): the desired device for the Event. | If not given, the current :ref:`accelerator<accelerators>` type will be used. | enable_timing (bool, optional): indicates if the event should measure time (default: ``False``) | blocking (bool, optional): if ``True``, :meth:`wait` will be blocking (default: ``False``) | interprocess (bool): if ``True``, the event can be shared between processes (default: ``False``) | | .. warning:: | | Both blocking and interprocess are not supported right now and are noops. | | Returns: | Event: An torch.Event object. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> event = torch.Event() | >>> e_cuda = torch.Event(device='cuda') | | Methods defined here: | | __repr__(self, /) | Return repr(self). | | elapsed_time(...) | Event.elapsed_time(end_event) -> float | | Returns the elapsed time in milliseconds between when this event and the :attr:`end_event` are | each recorded via :func:`torch.Stream.record_event`. | | Arguments: | end_event (:class:`torch.Event`): The ending event has been recorded. | | Returns: | float: Time between starting and ending event in milliseconds. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> s_cuda = torch.Stream(device='cuda') | >>> e1_cuda = s_cuda.record_event() | >>> e2_cuda = s_cuda.record_event() | >>> ms = e1_cuda.elapsed_time(e2_cuda) | | ipc_handle(...) | | query(...) | Event.query() -> bool | | Check if the stream where this event was recorded already moved past the point where the event was recorded. | Always returns ``True`` if the Event was not recorded. | | Returns: | bool: A boolean indicating if all work currently captured by event has completed. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> s_cuda = torch.Stream(device='cuda') | >>> e_cuda = s_cuda.record_event() | >>> e_cuda.query() | True | | record(...) | Event.record(stream=None) -> None | | Record the event in a given stream. The stream's device must match the event's device. | This function is equivalent to ``stream.record_event(self)``. | | Arguments: | stream (:class:`torch.Stream`, optional): A stream to be recorded. | If not given, the current stream will be used. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> e_cuda = torch.Event(device='cuda') | >>> e_cuda.record() | | synchronize(...) | Event.synchronize() -> None | | Wait for the event to complete. This prevents the CPU thread from proceeding until the event completes. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> s_cuda = torch.Stream(device='cuda') | >>> e_cuda = s_cuda.record_event() | >>> e_cuda.synchronize() | | wait(...) | Event.wait(stream=None) -> None | | Make all future work submitted to the given stream wait for this event. | | Arguments: | stream (:class:`torch.Stream`, optional): A stream to synchronize. | If not given, the current stream will be used. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> s1_cuda = torch.Stream(device='cuda') | >>> s2_cuda = torch.Stream(device='cuda') | >>> e_cuda = s1_cuda.record() | >>> e_cuda.wait(s2) | | ---------------------------------------------------------------------- | Class methods defined here: | | from_ipc_handle(...) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | device | | event_id
torch.ExcludeDispatchKeyGuard
Python Library Documentation: class ExcludeDispatchKeyGuard in module torch class ExcludeDispatchKeyGuard(pybind11_builtins.pybind11_object) | Method resolution order: | ExcludeDispatchKeyGuard | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __enter__(...) | __enter__(self: torch._C.ExcludeDispatchKeyGuard) -> None | | __exit__(...) | __exit__(self: torch._C.ExcludeDispatchKeyGuard, arg0: object, arg1: object, arg2: object) -> None | | __init__(...) | __init__(self: torch._C.ExcludeDispatchKeyGuard, arg0: torch._C.DispatchKeySet) -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ExecutionPlan
Python Library Documentation: class ExecutionPlan in module torch class ExecutionPlan(pybind11_builtins.pybind11_object) | Method resolution order: | ExecutionPlan | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | code | | graph | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.FatalError
Python Library Documentation: class FatalError in module torch class FatalError(builtins.Exception) | Method resolution order: | FatalError | builtins.Exception | builtins.BaseException | builtins.object | | Data descriptors defined here: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Methods inherited from builtins.Exception: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
torch.FileCheck
Python Library Documentation: class FileCheck in module torch class FileCheck(pybind11_builtins.pybind11_object) | Method resolution order: | FileCheck | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.FileCheck) -> None | | check(...) | check(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck | | check_count(...) | check_count(*args, **kwargs) | Overloaded function. | | 1. check_count(self: torch._C.FileCheck, arg0: str, arg1: typing.SupportsInt | typing.SupportsIndex, arg2: bool) -> torch._C.FileCheck | | 2. check_count(self: torch._C.FileCheck, str: str, count: typing.SupportsInt | typing.SupportsIndex, exactly: bool = False) -> torch._C.FileCheck | | Check Count | | check_dag(...) | check_dag(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck | | check_next(...) | check_next(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck | | check_not(...) | check_not(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck | | check_regex(...) | check_regex(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck | | check_same(...) | check_same(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck | | check_source_highlighted(...) | check_source_highlighted(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck | | run(...) | run(*args, **kwargs) | Overloaded function. | | 1. run(self: torch._C.FileCheck, arg0: str) -> None | | 2. run(self: torch._C.FileCheck, arg0: torch._C.Graph) -> None | | 3. run(self: torch._C.FileCheck, checks_file: str, test_file: str) -> None | | Run | | 4. run(self: torch._C.FileCheck, checks_file: str, graph: torch._C.Graph) -> None | | Run | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.FloatStorage
Python Library Documentation: class FloatStorage in module torch
class FloatStorage(torch.storage._LegacyStorage)
| FloatStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| FloatStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.float32
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.FloatTensor
Python Library Documentation: class FloatTensor in module torch
class FloatTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.float32
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
torch.FloatType
Python Library Documentation: class FloatType in module torch class FloatType(Type) | Method resolution order: | FloatType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.FloatType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.FunctionSchema
Python Library Documentation: class FunctionSchema in module torch class FunctionSchema(pybind11_builtins.pybind11_object) | Method resolution order: | FunctionSchema | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __eq__(...) | __eq__(self: torch._C.FunctionSchema, arg0: torch._C.FunctionSchema) -> bool | | __getstate__(...) | __getstate__(self: torch._C.FunctionSchema, /) -> str | | __hash__(...) | __hash__(self: torch._C.FunctionSchema) -> int | | __init__(...) | __init__(self: torch._C.FunctionSchema, arg0: str, arg1: str, arg2: collections.abc.Sequence[c10::Argument], arg3: collections.abc.Sequence[c10::Argument], arg4: bool, arg5: bool) -> None | | __repr__(...) | __repr__(self: torch._C.FunctionSchema) -> str | | __setstate__(...) | __setstate__(self: torch._C.FunctionSchema, arg0: str) -> None | | __str__(...) | __str__(self: torch._C.FunctionSchema) -> str | | check_forward_compatible_with(...) | check_forward_compatible_with(self: torch._C.FunctionSchema, arg0: torch._C.FunctionSchema) -> tuple[bool, str] | | is_backward_compatible_with(...) | is_backward_compatible_with(self: torch._C.FunctionSchema, arg0: torch._C.FunctionSchema) -> bool | | ---------------------------------------------------------------------- | Readonly properties defined here: | | arguments | | is_mutable | | name | | overload_name | | returns | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Future
Python Library Documentation: class Future in module torch class Future(pybind11_builtins.pybind11_object) | Method resolution order: | Future | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __getstate__(...) | __getstate__(self: torch._C.Future, /) -> tuple | | __init__(...) | __init__(self: torch._C.Future, arg0: collections.abc.Sequence[torch.device]) -> None | | __setstate__(...) | __setstate__(self: torch._C.Future, arg0: tuple) -> None | | add_done_callback(...) | add_done_callback(self: torch._C.Future, arg0: collections.abc.Callable) -> None | | done(...) | done(self: torch._C.Future) -> bool | | set_result(...) | set_result(self: torch._C.Future, arg0: object) -> None | | then(...) | then(self: torch._C.Future, arg0: collections.abc.Callable) -> torch._C.Future | | value(...) | value(self: torch._C.Future) -> object | | wait(...) | wait(self: torch._C.Future) -> object | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.FutureType
Python Library Documentation: class FutureType in module torch class FutureType(Type) | Method resolution order: | FutureType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.FutureType, arg0: torch._C.Type) -> None | | getElementType(...) | getElementType(self: torch._C.FutureType) -> torch._C.Type | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Generator
Python Library Documentation: class Generator in module torch._C class Generator(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __setstate__(...) | | clone_state(...) | Generator.clone_state() -> torch.Generator | | Clones the current state of the generator and returns a new generator pointing to this cloned state. | This method is beneficial for preserving a particular state of a generator to restore at a later point. | | Returns: | torch.Generator: A Generator pointing to the newly cloned state. | | Example: | >>> g_cuda = torch.Generator(device='cuda') | >>> cloned_state = g_cuda.clone_state() | | get_offset(...) | | get_state(...) | Generator.get_state() -> Tensor | | Returns the Generator state as a ``torch.ByteTensor``. | | Returns: | Tensor: A ``torch.ByteTensor`` which contains all the necessary bits | to restore a Generator to a specific point in time. | | Example:: | | >>> g_cpu = torch.Generator() | >>> g_cpu.get_state() | | graphsafe_get_state(...) | Generator.graphsafe_get_state() -> torch.Generator | | Retrieves the current state of the generator in a manner that is safe for graph capture. | This method is crucial for ensuring that the generator's state can be captured in the CUDA graph. | | Returns: | torch.Generator: A Generator point to the current state of the generator | | Example: | >>> g_cuda = torch.Generator(device='cuda') | >>> current_state = g_cuda.graphsafe_get_state() | | graphsafe_set_state(...) | Generator.graphsafe_set_state(state) -> None | | Sets the state of the generator to the specified state in a manner that is safe for use in graph capture. | This method is crucial for ensuring that the generator's state can be captured in the CUDA graph. | | Arguments: | state (torch.Generator): A Generator point to the new state for the generator, typically obtained from `graphsafe_get_state`. | | Example: | >>> g_cuda = torch.Generator(device='cuda') | >>> g_cuda_other = torch.Generator(device='cuda') | >>> current_state = g_cuda_other.graphsafe_get_state() | >>> g_cuda.graphsafe_set_state(current_state) | | initial_seed(...) | Generator.initial_seed() -> int | | Returns the initial seed for generating random numbers. | | Example:: | | >>> g_cpu = torch.Generator() | >>> g_cpu.initial_seed() | 2147483647 | | manual_seed(...) | Generator.manual_seed(seed) -> Generator | | Sets the seed for generating random numbers. Returns a `torch.Generator` object. Any 32-bit integer is a valid seed. | | Arguments: | seed (int): The desired seed. Value must be within the inclusive range | `[-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]`. Otherwise, a RuntimeError | is raised. Negative inputs are remapped to positive values with the formula | `0xffff_ffff_ffff_ffff + seed`. | | Returns: | Generator: An torch.Generator object. | | Example:: | | >>> g_cpu = torch.Generator() | >>> g_cpu.manual_seed(2147483647) | | seed(...) | Generator.seed() -> int | | Gets a non-deterministic random number from std::random_device or the current | time and uses it to seed a Generator. | | Example:: | | >>> g_cpu = torch.Generator() | >>> g_cpu.seed() | 1516516984916 | | set_offset(...) | | set_state(...) | Generator.set_state(new_state) -> void | | Sets the Generator state. | | Arguments: | new_state (torch.ByteTensor): The desired state. | | Example:: | | >>> g_cpu = torch.Generator() | >>> g_cpu_other = torch.Generator() | >>> g_cpu.set_state(g_cpu_other.get_state()) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | device | Generator.device -> device | | Gets the current device of the generator. | | Example:: | | >>> g_cpu = torch.Generator() | >>> g_cpu.device | device(type='cpu')
torch.GradScaler
Python Library Documentation: class GradScaler in module torch.amp.grad_scaler
class GradScaler(builtins.object)
| GradScaler(device: 'str' = 'cuda', init_scale: 'float' = 65536.0, growth_factor: 'float' = 2.0, backoff_factor: 'float' = 0.5, growth_interval: 'int' = 2000, enabled: 'bool' = True) -> 'None'
|
| An instance ``scaler`` of :class:`GradScaler`.
|
| Helps perform the steps of gradient scaling
| conveniently.
|
| * ``scaler.scale(loss)`` multiplies a given loss by ``scaler``'s current scale factor.
| * ``scaler.step(optimizer)`` safely unscales gradients and calls ``optimizer.step()``.
| * ``scaler.update()`` updates ``scaler``'s scale factor.
|
| Example::
|
| # Creates a GradScaler once at the beginning of training.
| scaler = GradScaler()
|
| for epoch in epochs:
| for input, target in data:
| optimizer.zero_grad()
| output = model(input)
| loss = loss_fn(output, target)
|
| # Scales loss. Calls backward() on scaled loss to create scaled gradients.
| scaler.scale(loss).backward()
|
| # scaler.step() first unscales gradients of the optimizer's params.
| # If gradients don't contain infs/NaNs, optimizer.step() is then called,
| # otherwise, optimizer.step() is skipped.
| scaler.step(optimizer)
|
| # Updates the scale for next iteration.
| scaler.update()
|
| See the :ref:`Automatic Mixed Precision examples<amp-examples>` for usage
| (along with autocasting) in more complex cases like gradient clipping, gradient accumulation, gradient penalty,
| and multiple losses/optimizers.
|
| ``scaler`` dynamically estimates the scale factor each iteration. To minimize gradient underflow,
| a large scale factor should be used. However, ``float16`` values can "overflow" (become inf or NaN) if
| the scale factor is too large. Therefore, the optimal scale factor is the largest factor that can be used
| without incurring inf or NaN gradient values.
| ``scaler`` approximates the optimal scale factor over time by checking the gradients for infs and NaNs during every
| ``scaler.step(optimizer)`` (or optional separate ``scaler.unscale_(optimizer)``, see :meth:`unscale_`).
|
| * If infs/NaNs are found, ``scaler.step(optimizer)`` skips the underlying ``optimizer.step()`` (so the params
| themselves remain uncorrupted) and ``update()`` multiplies the scale by ``backoff_factor``.
|
| * If no infs/NaNs are found, ``scaler.step(optimizer)`` runs the underlying ``optimizer.step()`` as usual.
| If ``growth_interval`` unskipped iterations occur consecutively, ``update()`` multiplies the scale by
| ``growth_factor``.
|
| The scale factor often causes infs/NaNs to appear in gradients for the first few iterations as its
| value calibrates. ``scaler.step`` will skip the underlying ``optimizer.step()`` for these
| iterations. After that, step skipping should occur rarely (once every few hundred or thousand iterations).
|
| Args:
| device (str, optional, default="cuda"): Device type to use. Possible values are: 'cuda' and 'cpu'.
| The type is the same as the `type` attribute of a :class:`torch.device`.
| Thus, you may obtain the device type of a tensor using `Tensor.device.type`.
| init_scale (float, optional, default=2.**16): Initial scale factor.
| growth_factor (float, optional, default=2.0): Factor by which the scale is multiplied during
| :meth:`update` if no inf/NaN gradients occur for ``growth_interval`` consecutive iterations.
| backoff_factor (float, optional, default=0.5): Factor by which the scale is multiplied during
| :meth:`update` if inf/NaN gradients occur in an iteration.
| growth_interval (int, optional, default=2000): Number of consecutive iterations without inf/NaN gradients
| that must occur for the scale to be multiplied by ``growth_factor``.
| enabled (bool, optional): If ``False``, disables gradient scaling. :meth:`step` simply
| invokes the underlying ``optimizer.step()``, and other methods become no-ops.
| Default: ``True``
|
| Methods defined here:
|
| __getstate__(self) -> 'dict[str, Any]'
| Helper for pickle.
|
| __init__(self, device: 'str' = 'cuda', init_scale: 'float' = 65536.0, growth_factor: 'float' = 2.0, backoff_factor: 'float' = 0.5, growth_interval: 'int' = 2000, enabled: 'bool' = True) -> 'None'
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state: 'dict[str, Any]') -> 'None'
|
| get_backoff_factor(self) -> 'float'
| Return a Python float containing the scale backoff factor.
|
| get_growth_factor(self) -> 'float'
| Return a Python float containing the scale growth factor.
|
| get_growth_interval(self) -> 'int'
| Return a Python int containing the growth interval.
|
| get_scale(self) -> 'float'
| Return a Python float containing the current scale, or 1.0 if scaling is disabled.
|
| .. warning::
| :meth:`get_scale` incurs a CPU-GPU sync.
|
| is_enabled(self) -> 'bool'
| Return a bool indicating whether this instance is enabled.
|
| load_state_dict(self, state_dict: 'dict[str, Any]') -> 'None'
| Load the scaler state.
|
| If this instance is disabled, :meth:`load_state_dict` is a no-op.
|
| Args:
| state_dict(dict): scaler state. Should be an object returned from a call to :meth:`state_dict`.
|
| scale(self, outputs: 'torch.Tensor | Iterable[torch.Tensor]') -> 'torch.Tensor | Iterable[torch.Tensor]'
| Multiplies ('scales') a tensor or list of tensors by the scale factor.
|
| Returns scaled outputs. If this instance of :class:`GradScaler` is not enabled, outputs are returned
| unmodified.
|
| Args:
| outputs (Tensor or iterable of Tensors): Outputs to scale.
|
| set_backoff_factor(self, new_factor: 'float') -> 'None'
| Set a new scale backoff factor.
|
| Args:
| new_scale (float): Value to use as the new scale backoff factor.
|
| set_growth_factor(self, new_factor: 'float') -> 'None'
| Set a new scale growth factor.
|
| Args:
| new_scale (float): Value to use as the new scale growth factor.
|
| set_growth_interval(self, new_interval: 'int') -> 'None'
| Set a new growth interval.
|
| Args:
| new_interval (int): Value to use as the new growth interval.
|
| state_dict(self) -> 'dict[str, Any]'
| Return the state of the scaler as a :class:`dict`.
|
| It contains five entries:
|
| * ``"scale"`` - a Python float containing the current scale
| * ``"growth_factor"`` - a Python float containing the current growth factor
| * ``"backoff_factor"`` - a Python float containing the current backoff factor
| * ``"growth_interval"`` - a Python int containing the current growth interval
| * ``"_growth_tracker"`` - a Python int containing the number of recent consecutive unskipped steps.
|
| If this instance is not enabled, returns an empty dict.
|
| .. note::
| If you wish to checkpoint the scaler's state after a particular iteration, :meth:`state_dict`
| should be called after :meth:`update`.
|
| step(self, optimizer: 'torch.optim.Optimizer', *args: 'Any', **kwargs: 'Any') -> 'float | None'
| Invoke ``unscale_(optimizer)`` followed by parameter update, if gradients are not infs/NaN.
|
| :meth:`step` carries out the following two operations:
|
| 1. Internally invokes ``unscale_(optimizer)`` (unless :meth:`unscale_` was explicitly called for ``optimizer``
| earlier in the iteration). As part of the :meth:`unscale_`, gradients are checked for infs/NaNs.
| 2. If no inf/NaN gradients are found, invokes ``optimizer.step()`` using the unscaled
| gradients. Otherwise, ``optimizer.step()`` is skipped to avoid corrupting the params.
|
| ``*args`` and ``**kwargs`` are forwarded to ``optimizer.step()``.
|
| Returns the return value of ``optimizer.step(*args, **kwargs)``.
|
| Args:
| optimizer (torch.optim.Optimizer): Optimizer that applies the gradients.
| args: Any arguments.
| kwargs: Any keyword arguments.
|
| .. warning::
| Closure use is not currently supported.
|
| unscale_(self, optimizer: 'torch.optim.Optimizer') -> 'None'
| Divides ("unscales") the optimizer's gradient tensors by the scale factor.
|
| :meth:`unscale_` is optional, serving cases where you need to
| :ref:`modify or inspect gradients<working-with-unscaled-gradients>`
| between the backward pass(es) and :meth:`step`.
| If :meth:`unscale_` is not called explicitly, gradients will be unscaled automatically during :meth:`step`.
|
| Simple example, using :meth:`unscale_` to enable clipping of unscaled gradients::
|
| ...
| scaler.scale(loss).backward()
| scaler.unscale_(optimizer)
| torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm)
| scaler.step(optimizer)
| scaler.update()
|
| Args:
| optimizer (torch.optim.Optimizer): Optimizer that owns the gradients to be unscaled.
|
| .. note::
| :meth:`unscale_` does not incur a CPU-GPU sync.
|
| .. warning::
| :meth:`unscale_` should only be called once per optimizer per :meth:`step` call,
| and only after all gradients for that optimizer's assigned parameters have been accumulated.
| Calling :meth:`unscale_` twice for a given optimizer between each :meth:`step` triggers a RuntimeError.
|
| .. warning::
| :meth:`unscale_` may unscale sparse gradients out of place, replacing the ``.grad`` attribute.
|
| update(self, new_scale: 'float | torch.Tensor | None' = None) -> 'None'
| Update the scale factor.
|
| If any optimizer steps were skipped the scale is multiplied by ``backoff_factor``
| to reduce it. If ``growth_interval`` unskipped iterations occurred consecutively,
| the scale is multiplied by ``growth_factor`` to increase it.
|
| Passing ``new_scale`` sets the new scale value manually. (``new_scale`` is not
| used directly, it's used to fill GradScaler's internal scale tensor. So if
| ``new_scale`` was a tensor, later in-place changes to that tensor will not further
| affect the scale GradScaler uses internally.)
|
| Args:
| new_scale (float or :class:`torch.Tensor`, optional, default=None): New scale factor.
|
| .. warning::
| :meth:`update` should only be called at the end of the iteration, after ``scaler.step(optimizer)`` has
| been invoked for all optimizers used this iteration.
|
| .. warning::
| For performance reasons, we do not check the scale factor value to avoid synchronizations,
| so the scale factor is not guaranteed to be above 1. If the scale falls below 1 and/or
| you are seeing NaNs in your gradients or loss, something is likely wrong. For example,
| bf16-pretrained models are often incompatible with AMP/fp16 due to differing dynamic ranges.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
torch.Gradient
Python Library Documentation: class Gradient in module torch class Gradient(pybind11_builtins.pybind11_object) | Method resolution order: | Gradient | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | df | | df_input_captured_inputs | | df_input_captured_outputs | | df_input_vjps | | df_output_vjps | | f | | f_real_outputs | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Graph
Python Library Documentation: class Graph in module torch class Graph(pybind11_builtins.pybind11_object) | Method resolution order: | Graph | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.Graph) -> None | | __repr__(...) | __repr__(self: torch._C.Graph) -> str | | addInput(...) | addInput(self: torch._C.Graph, name: str = '') -> torch::jit::Value | | Add input to graph with optional name seed | | alias_db(...) | alias_db(self: torch._C.Graph, isFrozen: bool = False, descend_function_calls: bool = False) -> torch._C.AliasDb | | appendNode(...) | appendNode(self: torch._C.Graph, arg0: torch::jit::Node) -> torch::jit::Node | | block(...) | block(self: torch._C.Graph) -> torch::jit::Block | | copy(...) | copy(self: torch._C.Graph) -> torch._C.Graph | | create(...) | create(*args, **kwargs) | Overloaded function. | | 1. create(self: torch._C.Graph, arg0: str) -> torch::jit::Node | | 2. create(self: torch._C.Graph, arg0: str, arg1: typing.SupportsInt | typing.SupportsIndex) -> torch::jit::Node | | 3. create(self: torch._C.Graph, arg0: str, arg1: collections.abc.Sequence[torch::jit::Value]) -> torch::jit::Node | | 4. create(self: torch._C.Graph, arg0: str, arg1: collections.abc.Sequence[torch::jit::Value], arg2: typing.SupportsInt | typing.SupportsIndex) -> torch::jit::Node | | createClone(...) | createClone(self: torch._C.Graph, arg0: torch::jit::Node, arg1: object) -> torch::jit::Node | | createCudaFusionGroup(...) | createCudaFusionGroup(self: torch._C.Graph) -> torch::jit::Node | | createFusionGroup(...) | createFusionGroup(self: torch._C.Graph) -> torch::jit::Node | | dump_alias_db(...) | dump_alias_db(self: torch._C.Graph) -> None | | eraseInput(...) | eraseInput(self: torch._C.Graph, arg0: typing.SupportsInt | typing.SupportsIndex) -> None | | eraseOutput(...) | eraseOutput(self: torch._C.Graph, arg0: typing.SupportsInt | typing.SupportsIndex) -> None | | findAllNodes(...) | findAllNodes(self: torch._C.Graph, kind: str, recurse: bool = True) -> list[torch::jit::Node] | | Find all nodes | | findNode(...) | findNode(self: torch._C.Graph, kind: str, recurse: bool = True) -> torch::jit::Node | | Find Node | | inputs(...) | inputs(self: torch._C.Graph) -> collections.abc.Iterator[torch::jit::Value] | | insert(...) | insert(self: torch._C.Graph, arg0: Symbol, arg1: collections.abc.Sequence[torch::jit::Value]) -> torch::jit::Value | | insertConstant(...) | insertConstant(self: torch._C.Graph, arg0: IValue) -> torch::jit::Value | | insertGraph(...) | insertGraph(*args, **kwargs) | Overloaded function. | | 1. insertGraph(self: torch._C.Graph, arg0: torch._C.Graph, arg1: collections.abc.Sequence[torch::jit::Value]) -> list[torch::jit::Value] | | 2. insertGraph(self: torch._C.Graph, arg0: torch._C.Graph, arg1: collections.abc.Sequence[torch::jit::Value], arg2: collections.abc.Mapping[torch::jit::Value, torch::jit::Value]) -> list[torch::jit::Value] | | insertNode(...) | insertNode(self: torch._C.Graph, arg0: torch::jit::Node) -> torch::jit::Node | | insertPoint(...) | insertPoint(self: torch._C.Graph) -> torch::jit::Node | | insert_point_guard(...) | insert_point_guard(*args, **kwargs) | Overloaded function. | | 1. insert_point_guard(self: torch._C.Graph, arg0: torch::jit::Node) -> object | | 2. insert_point_guard(self: torch._C.Graph, arg0: torch::jit::Block) -> object | | lint(...) | lint(self: torch._C.Graph) -> None | | makeMultiOutputIntoTuple(...) | makeMultiOutputIntoTuple(self: torch._C.Graph) -> None | | nodes(...) | nodes(self: torch._C.Graph) -> collections.abc.Iterator[torch::jit::Node] | | outputs(...) | outputs(self: torch._C.Graph) -> collections.abc.Iterator[torch::jit::Value] | | param_node(...) | param_node(self: torch._C.Graph) -> torch::jit::Node | | permuteInputs(...) | permuteInputs(self: torch._C.Graph, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> None | | prependNode(...) | prependNode(self: torch._C.Graph, arg0: torch::jit::Node) -> torch::jit::Node | | registerOutput(...) | registerOutput(self: torch._C.Graph, arg0: torch::jit::Value) -> int | | return_node(...) | return_node(self: torch._C.Graph) -> torch::jit::Node | | setInsertPoint(...) | setInsertPoint(*args, **kwargs) | Overloaded function. | | 1. setInsertPoint(self: torch._C.Graph, arg0: torch::jit::Node) -> None | | 2. setInsertPoint(self: torch._C.Graph, arg0: torch::jit::Block) -> None | | str(...) | str(self: torch._C.Graph, print_source_ranges: bool = True) -> str | | ---------------------------------------------------------------------- | Static methods defined here: | | set_global_print_source_ranges(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | set_global_print_source_ranges(enabled: bool = True) -> None | | ---------------------------------------------------------------------- | Readonly properties defined here: | | global_print_source_ranges | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.GraphExecutorState
Python Library Documentation: class GraphExecutorState in module torch class GraphExecutorState(pybind11_builtins.pybind11_object) | Method resolution order: | GraphExecutorState | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | execution_plans | | fallback | | graph | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.HalfStorage
Python Library Documentation: class HalfStorage in module torch
class HalfStorage(torch.storage._LegacyStorage)
| HalfStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| HalfStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.float16
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.HalfTensor
Python Library Documentation: class HalfTensor in module torch
class HalfTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.float16
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
torch.IODescriptor
Python Library Documentation: class IODescriptor in module torch class IODescriptor(pybind11_builtins.pybind11_object) | Method resolution order: | IODescriptor | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.InferredType
Python Library Documentation: class InferredType in module torch class InferredType(pybind11_builtins.pybind11_object) | Method resolution order: | InferredType | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(*args, **kwargs) | Overloaded function. | | 1. __init__(self: torch._C.InferredType, arg0: torch._C.Type) -> None | | 2. __init__(self: torch._C.InferredType, arg0: str) -> None | | reason(...) | reason(self: torch._C.InferredType) -> str | | success(...) | success(self: torch._C.InferredType) -> bool | | type(...) | type(self: torch._C.InferredType) -> torch._C.Type | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.IntStorage
Python Library Documentation: class IntStorage in module torch
class IntStorage(torch.storage._LegacyStorage)
| IntStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| IntStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.int32
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.IntTensor
Python Library Documentation: class IntTensor in module torch
class IntTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.int32
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
torch.IntType
Python Library Documentation: class IntType in module torch class IntType(Type) | Method resolution order: | IntType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.IntType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.InterfaceType
Python Library Documentation: class InterfaceType in module torch class InterfaceType(Type) | Method resolution order: | InterfaceType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.InterfaceType, arg0: str) -> None | | getMethod(...) | getMethod(self: torch._C.InterfaceType, arg0: str) -> torch._C.FunctionSchema | | getMethodNames(...) | getMethodNames(self: torch._C.InterfaceType) -> list[str] | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.JITException
Python Library Documentation: class Error in module torch.jit class Error(builtins.Exception) | Method resolution order: | Error | builtins.Exception | builtins.BaseException | builtins.object | | Data descriptors defined here: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Methods inherited from builtins.Exception: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
torch.ListType
Python Library Documentation: class ListType in module torch class ListType(Type) | Method resolution order: | ListType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.ListType, arg0: torch._C.Type) -> None | | getElementType(...) | getElementType(self: torch._C.ListType) -> torch._C.Type | | ---------------------------------------------------------------------- | Static methods defined here: | | ofBools(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | ofBools() -> torch._C.ListType | | ofComplexDoubles(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | ofComplexDoubles() -> torch._C.ListType | | ofFloats(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | ofFloats() -> torch._C.ListType | | ofInts(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | ofInts() -> torch._C.ListType | | ofStrings(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | ofStrings() -> torch._C.ListType | | ofTensors(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | ofTensors() -> torch._C.ListType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.LiteScriptModule
Python Library Documentation: class LiteScriptModule in module torch class LiteScriptModule(pybind11_builtins.pybind11_object) | Method resolution order: | LiteScriptModule | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.LiteScriptModule, arg0: c10::ivalue::Object, arg1: torch::jit::mobile::CompilationUnit) -> None | | find_method(...) | find_method(self: torch._C.LiteScriptModule, method_name: str) -> bool | | forward(...) | forward(self: torch._C.LiteScriptModule, input_tuple: tuple) -> IValue | | run_method(...) | run_method(self: torch._C.LiteScriptModule, method_name: str, input_tuple: tuple) -> IValue | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.LockingLogger
Python Library Documentation: class LockingLogger in module torch class LockingLogger(torch._C.LoggerBase) | Method resolution order: | LockingLogger | torch._C.LoggerBase | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.LockingLogger) -> None | | get_counter_val(...) | get_counter_val(self: torch._C.LockingLogger, arg0: str) -> int | | set_aggregation_type(...) | set_aggregation_type(self: torch._C.LockingLogger, arg0: str, arg1: torch._C.AggregationType) -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.LoggerBase
Python Library Documentation: class LoggerBase in module torch._C class LoggerBase(pybind11_builtins.pybind11_object) | Method resolution order: | LoggerBase | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.LongStorage
Python Library Documentation: class LongStorage in module torch
class LongStorage(torch.storage._LegacyStorage)
| LongStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| LongStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.int64
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.LongTensor
Python Library Documentation: class LongTensor in module torch
class LongTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.int64
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
torch.ModuleDict
Python Library Documentation: class ModuleDict in module torch class ModuleDict(pybind11_builtins.pybind11_object) | Method resolution order: | ModuleDict | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.ModuleDict, arg0: torch._C.ScriptModule) -> None | | contains(...) | contains(self: torch._C.ModuleDict, arg0: str) -> bool | | getattr(...) | getattr(self: torch._C.ModuleDict, arg0: str) -> object | | items(...) | items(self: torch._C.ModuleDict) -> list[tuple[str, object]] | | setattr(...) | setattr(self: torch._C.ModuleDict, arg0: str, arg1: object) -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Node
Python Library Documentation: class Node in module torch class Node(pybind11_builtins.pybind11_object) | Method resolution order: | Node | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __repr__(...) | __repr__(self: torch._C.Node) -> str | | addBlock(...) | addBlock(self: torch._C.Node) -> torch._C.Block | | addInput(...) | addInput(self: torch._C.Node, arg0: torch._C.Value) -> torch._C.Value | | addOutput(...) | addOutput(self: torch._C.Node) -> torch._C.Value | | attributeNames(...) | attributeNames(self: torch._C.Node) -> list[str] | | blocks(...) | blocks(self: torch._C.Node) -> collections.abc.Iterator[torch._C.Block] | | c(...) | c(self: torch._C.Node, arg0: str) -> complex | | c_(...) | c_(self: torch._C.Node, arg0: str, arg1: complex) -> torch._C.Node | | cconv(...) | cconv(self: torch._C.Node) -> str | | copyAttributes(...) | copyAttributes(self: torch._C.Node, arg0: torch._C.Node) -> torch._C.Node | | copyMetadata(...) | copyMetadata(self: torch._C.Node, arg0: torch._C.Node) -> torch._C.Node | | destroy(...) | destroy(self: torch._C.Node) -> None | | eraseOutput(...) | eraseOutput(self: torch._C.Node, arg0: typing.SupportsInt | typing.SupportsIndex) -> None | | f(...) | f(self: torch._C.Node, arg0: str) -> float | | f_(...) | f_(self: torch._C.Node, arg0: str, arg1: typing.SupportsFloat | typing.SupportsIndex) -> torch._C.Node | | findAllNodes(...) | findAllNodes(self: torch._C.Node, kind: str, recurse: bool = True) -> list[torch._C.Node] | | Find all nodes | | findNode(...) | findNode(self: torch._C.Node, kind: str, recurse: bool = True) -> torch._C.Node | | Find Node | | fs(...) | fs(self: torch._C.Node, arg0: str) -> list[float] | | fs_(...) | fs_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex]) -> torch._C.Node | | g(...) | g(self: torch._C.Node, arg0: str) -> torch._C.Graph | | g_(...) | g_(self: torch._C.Node, arg0: str, arg1: torch._C.Graph) -> torch._C.Node | | getModuleHierarchy(...) | getModuleHierarchy(self: torch._C.Node) -> str | | gs(...) | gs(self: torch._C.Node, arg0: str) -> list[torch._C.Graph] | | gs_(...) | gs_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[torch._C.Graph]) -> torch._C.Node | | hasAttribute(...) | hasAttribute(self: torch._C.Node, arg0: str) -> bool | | hasAttributes(...) | hasAttributes(self: torch._C.Node) -> bool | | hasMultipleOutputs(...) | hasMultipleOutputs(self: torch._C.Node) -> bool | | hasUses(...) | hasUses(self: torch._C.Node) -> bool | | i(...) | i(self: torch._C.Node, arg0: str) -> int | | i_(...) | i_(self: torch._C.Node, arg0: str, arg1: typing.SupportsInt | typing.SupportsIndex) -> torch._C.Node | | input(...) | input(self: torch._C.Node) -> torch._C.Value | | inputs(...) | inputs(self: torch._C.Node) -> collections.abc.Iterator[torch._C.Value] | | inputsAt(...) | inputsAt(self: torch._C.Node, arg0: typing.SupportsInt | typing.SupportsIndex) -> torch._C.Value | | inputsSize(...) | inputsSize(self: torch._C.Node) -> int | | insertAfter(...) | insertAfter(self: torch._C.Node, arg0: torch._C.Node) -> torch._C.Node | | insertBefore(...) | insertBefore(self: torch._C.Node, arg0: torch._C.Node) -> torch._C.Node | | is(...) | is(self: torch._C.Node, arg0: str) -> list[int] | | isAfter(...) | isAfter(self: torch._C.Node, arg0: torch._C.Node) -> bool | | isBefore(...) | isBefore(self: torch._C.Node, arg0: torch._C.Node) -> bool | | isNondeterministic(...) | isNondeterministic(self: torch._C.Node) -> bool | | is_(...) | is_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> torch._C.Node | | ival(...) | ival(self: torch._C.Node, arg0: str) -> IValue | | ival_(...) | ival_(self: torch._C.Node, arg0: str, arg1: IValue) -> torch._C.Node | | kind(...) | kind(self: torch._C.Node) -> Symbol | | kindOf(...) | kindOf(self: torch._C.Node, arg0: str) -> AttributeKind | | matches(...) | matches(self: torch._C.Node, arg0: str) -> bool | | moveAfter(...) | moveAfter(self: torch._C.Node, arg0: torch._C.Node) -> None | | moveBefore(...) | moveBefore(self: torch._C.Node, arg0: torch._C.Node) -> None | | mustBeNone(...) | mustBeNone(self: torch._C.Node) -> bool | | namedInput(...) | namedInput(self: torch._C.Node, arg0: str) -> torch._C.Value | | output(...) | output(self: torch._C.Node) -> torch._C.Value | | outputs(...) | outputs(self: torch._C.Node) -> collections.abc.Iterator[torch._C.Value] | | outputsAt(...) | outputsAt(self: torch._C.Node, arg0: typing.SupportsInt | typing.SupportsIndex) -> torch._C.Value | | outputsSize(...) | outputsSize(self: torch._C.Node) -> int | | owningBlock(...) | owningBlock(self: torch._C.Node) -> torch._C.Block | | prev(...) | prev(self: torch._C.Node) -> torch._C.Node | | pyname(...) | pyname(self: torch._C.Node) -> str | | pyobj(...) | pyobj(self: torch._C.Node) -> object | | removeAllInputs(...) | removeAllInputs(self: torch._C.Node) -> None | | removeAttribute(...) | removeAttribute(self: torch._C.Node, arg0: str) -> torch._C.Node | | removeInput(...) | removeInput(self: torch._C.Node, arg0: typing.SupportsInt | typing.SupportsIndex) -> None | | replaceAllUsesWith(...) | replaceAllUsesWith(self: torch._C.Node, arg0: torch._C.Node) -> None | | replaceInput(...) | replaceInput(self: torch._C.Node, arg0: typing.SupportsInt | typing.SupportsIndex, arg1: torch._C.Value) -> torch._C.Value | | replaceInputWith(...) | replaceInputWith(self: torch._C.Node, arg0: torch._C.Value, arg1: torch._C.Value) -> None | | s(...) | s(self: torch._C.Node, arg0: str) -> str | | s_(...) | s_(self: torch._C.Node, arg0: str, arg1: str) -> torch._C.Node | | scalar_args(...) | scalar_args(self: torch._C.Node) -> list | | schema(...) | schema(self: torch._C.Node) -> str | | scopeName(...) | scopeName(self: torch._C.Node) -> str | | sourceRange(...) | sourceRange(self: torch._C.Node) -> str | | ss(...) | ss(self: torch._C.Node, arg0: str) -> list[str] | | ss_(...) | ss_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[str]) -> torch._C.Node | | t(...) | t(self: torch._C.Node, arg0: str) -> torch.Tensor | | t_(...) | t_(self: torch._C.Node, arg0: str, arg1: torch.Tensor) -> torch._C.Node | | ts(...) | ts(self: torch._C.Node, arg0: str) -> list[torch.Tensor] | | ts_(...) | ts_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[torch.Tensor]) -> torch._C.Node | | ty(...) | ty(self: torch._C.Node, arg0: str) -> c10::Type | | ty_(...) | ty_(self: torch._C.Node, arg0: str, arg1: c10::Type) -> torch._C.Node | | tys(...) | tys(self: torch._C.Node, arg0: str) -> list[c10::Type] | | tys_(...) | tys_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[c10::Type]) -> torch._C.Node | | z(...) | z(self: torch._C.Node, arg0: str) -> torch.Tensor | | z_(...) | z_(self: torch._C.Node, arg0: str, arg1: torch.Tensor) -> torch._C.Node | | zs(...) | zs(self: torch._C.Node, arg0: str) -> list[torch.Tensor] | | zs_(...) | zs_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[torch.Tensor]) -> torch._C.Node | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.NoneType
Python Library Documentation: class NoneType in module torch class NoneType(Type) | Method resolution order: | NoneType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.NoneType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.NoopLogger
Python Library Documentation: class NoopLogger in module torch class NoopLogger(torch._C.LoggerBase) | Method resolution order: | NoopLogger | torch._C.LoggerBase | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.NoopLogger) -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.NumberType
Python Library Documentation: class NumberType in module torch class NumberType(Type) | Method resolution order: | NumberType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.NumberType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.OperatorInfo
Python Library Documentation: class OperatorInfo in module torch class OperatorInfo(pybind11_builtins.pybind11_object) | Method resolution order: | OperatorInfo | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | num_schema_args | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.OptionalType
Python Library Documentation: class OptionalType in module torch class OptionalType(Type) | Method resolution order: | OptionalType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.OptionalType, arg0: torch._C.Type) -> None | | getElementType(...) | getElementType(self: torch._C.OptionalType) -> torch._C.Type | | ---------------------------------------------------------------------- | Static methods defined here: | | ofTensor(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | ofTensor() -> torch._C.Type | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.OutOfMemoryError
Python Library Documentation: class OutOfMemoryError in module torch class OutOfMemoryError(builtins.RuntimeError) | Exception raised when device is out of memory | | Method resolution order: | OutOfMemoryError | builtins.RuntimeError | builtins.Exception | builtins.BaseException | builtins.object | | Data descriptors defined here: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Methods inherited from builtins.RuntimeError: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods inherited from builtins.RuntimeError: | | __new__(*args, **kwargs) class method of builtins.RuntimeError | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
torch.PRIVATE_OPS
Python Library Documentation: tuple object class tuple(object) | tuple(iterable=(), /) | | Built-in immutable sequence. | | If no argument is given, the constructor returns an empty tuple. | If iterable is specified the tuple is initialized from iterable's items. | | If the argument is a tuple, the return value is the same object. | | Built-in subclasses: | asyncgen_hooks | UnraisableHookArgs | | Methods defined here: | | __add__(self, value, /) | Return self+value. | | __contains__(self, key, /) | Return bool(key in self). | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getitem__(self, key, /) | Return self[key]. | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __iter__(self, /) | Implement iter(self). | | __le__(self, value, /) | Return self<=value. | | __len__(self, /) | Return len(self). | | __lt__(self, value, /) | Return self<value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __repr__(self, /) | Return repr(self). | | __rmul__(self, value, /) | Return value*self. | | count(self, value, /) | Return number of occurrences of value. | | index(self, value, start=0, stop=9223372036854775807, /) | Return first index of value. | | Raises ValueError if the value is not present. | | ---------------------------------------------------------------------- | Class methods defined here: | | __class_getitem__(...) | See PEP 585 | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature.
torch.ParameterDict
Python Library Documentation: class ParameterDict in module torch class ParameterDict(pybind11_builtins.pybind11_object) | Method resolution order: | ParameterDict | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.ParameterDict, arg0: torch._C.ScriptModule) -> None | | contains(...) | contains(self: torch._C.ParameterDict, arg0: str) -> bool | | getattr(...) | getattr(self: torch._C.ParameterDict, arg0: str) -> object | | items(...) | items(self: torch._C.ParameterDict) -> list[tuple[str, object]] | | setattr(...) | setattr(self: torch._C.ParameterDict, arg0: str, arg1: object) -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.PyObjectType
Python Library Documentation: class PyObjectType in module torch class PyObjectType(Type) | Method resolution order: | PyObjectType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.PyObjectType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.PyTorchFileReader
Python Library Documentation: class PyTorchFileReader in module torch class PyTorchFileReader(pybind11_builtins.pybind11_object) | Method resolution order: | PyTorchFileReader | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(*args, **kwargs) | Overloaded function. | | 1. __init__(self: torch._C.PyTorchFileReader, arg0: str) -> None | | 2. __init__(self: torch._C.PyTorchFileReader, arg0: object) -> None | | get_all_records(...) | get_all_records(self: torch._C.PyTorchFileReader) -> list[str] | | get_record(...) | get_record(self: torch._C.PyTorchFileReader, arg0: str) -> bytes | | get_record_header_offset(...) | get_record_header_offset(self: torch._C.PyTorchFileReader, arg0: str) -> int | | get_record_offset(...) | get_record_offset(self: torch._C.PyTorchFileReader, arg0: str) -> int | | get_record_offset_no_read(...) | get_record_offset_no_read(self: torch._C.PyTorchFileReader, arg0: typing.SupportsInt | typing.SupportsIndex, arg1: str, arg2: typing.SupportsInt | typing.SupportsIndex, arg3: typing.SupportsInt | typing.SupportsIndex) -> int | | get_record_size(...) | get_record_size(self: torch._C.PyTorchFileReader, arg0: str) -> int | | get_storage_from_record(...) | get_storage_from_record(self: torch._C.PyTorchFileReader, arg0: str, arg1: typing.SupportsInt | typing.SupportsIndex, arg2: object) -> torch.Tensor | | has_record(...) | has_record(self: torch._C.PyTorchFileReader, arg0: str) -> bool | | serialization_id(...) | serialization_id(self: torch._C.PyTorchFileReader) -> str | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.PyTorchFileWriter
Python Library Documentation: class PyTorchFileWriter in module torch class PyTorchFileWriter(pybind11_builtins.pybind11_object) | Method resolution order: | PyTorchFileWriter | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(*args, **kwargs) | Overloaded function. | | 1. __init__(self: torch._C.PyTorchFileWriter, file_name: str, compute_crc32: bool = True, storage_alignment: typing.SupportsInt | typing.SupportsIndex = 64) -> None | | 2. __init__(self: torch._C.PyTorchFileWriter, buffer: object, compute_crc32: bool = True, storage_alignment: typing.SupportsInt | typing.SupportsIndex = 64) -> None | | 3. __init__(self: torch._C.PyTorchFileWriter, writer_func: collections.abc.Callable[[typing_extensions.CapsuleType, typing.SupportsInt | typing.SupportsIndex], int], compute_crc32: bool = True, storage_alignment: typing.SupportsInt | typing.SupportsIndex = 64) -> None | | archive_name(...) | archive_name(self: torch._C.PyTorchFileWriter) -> str | | get_all_written_records(...) | get_all_written_records(self: torch._C.PyTorchFileWriter) -> set[str] | | serialization_id(...) | serialization_id(self: torch._C.PyTorchFileWriter) -> str | | set_min_version(...) | set_min_version(self: torch._C.PyTorchFileWriter, arg0: typing.SupportsInt | typing.SupportsIndex) -> None | | write_end_of_file(...) | write_end_of_file(self: torch._C.PyTorchFileWriter) -> None | | write_record(...) | write_record(*args, **kwargs) | Overloaded function. | | 1. write_record(self: torch._C.PyTorchFileWriter, arg0: str, arg1: str, arg2: typing.SupportsInt | typing.SupportsIndex) -> None | | 2. write_record(self: torch._C.PyTorchFileWriter, arg0: str, arg1: bytes, arg2: typing.SupportsInt | typing.SupportsIndex) -> None | | 3. write_record(self: torch._C.PyTorchFileWriter, arg0: str, arg1: torch.StorageBase, arg2: typing.SupportsInt | typing.SupportsIndex) -> None | | 4. write_record(self: torch._C.PyTorchFileWriter, arg0: str, arg1: typing.SupportsInt | typing.SupportsIndex, arg2: typing.SupportsInt | typing.SupportsIndex) -> None | | write_record_metadata(...) | write_record_metadata(self: torch._C.PyTorchFileWriter, arg0: str, arg1: typing.SupportsInt | typing.SupportsIndex) -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.QInt32Storage
Python Library Documentation: class QInt32Storage in module torch
class QInt32Storage(torch.storage._LegacyStorage)
| QInt32Storage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| QInt32Storage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.qint32
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.QInt8Storage
Python Library Documentation: class QInt8Storage in module torch
class QInt8Storage(torch.storage._LegacyStorage)
| QInt8Storage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| QInt8Storage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.qint8
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.QUInt2x4Storage
Python Library Documentation: class QUInt2x4Storage in module torch
class QUInt2x4Storage(torch.storage._LegacyStorage)
| QUInt2x4Storage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| QUInt2x4Storage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.quint2x4
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.QUInt4x2Storage
Python Library Documentation: class QUInt4x2Storage in module torch
class QUInt4x2Storage(torch.storage._LegacyStorage)
| QUInt4x2Storage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| QUInt4x2Storage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.quint4x2
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.QUInt8Storage
Python Library Documentation: class QUInt8Storage in module torch
class QUInt8Storage(torch.storage._LegacyStorage)
| QUInt8Storage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| QUInt8Storage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.quint8
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.RRefType
Python Library Documentation: class RRefType in module torch class RRefType(Type) | Method resolution order: | RRefType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.RRefType, arg0: torch._C.Type) -> None | | getElementType(...) | getElementType(self: torch._C.RRefType) -> torch._C.Type | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.SUM
Python Library Documentation: AggregationType in module torch object class AggregationType(pybind11_builtins.pybind11_object) | Method resolution order: | AggregationType | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __eq__(...) | __eq__(self: object, other: object, /) -> bool | | __getstate__(...) | __getstate__(self: object, /) -> int | | __hash__(...) | __hash__(self: object, /) -> int | | __index__(...) | __index__(self: torch._C.AggregationType, /) -> int | | __init__(...) | __init__(self: torch._C.AggregationType, value: typing.SupportsInt | typing.SupportsIndex) -> None | | __int__(...) | __int__(self: torch._C.AggregationType, /) -> int | | __ne__(...) | __ne__(self: object, other: object, /) -> bool | | __repr__(...) | __repr__(self: object, /) -> str | | __setstate__(...) | __setstate__(self: torch._C.AggregationType, state: typing.SupportsInt | typing.SupportsIndex, /) -> None | | __str__(...) | __str__(self: object, /) -> str | | ---------------------------------------------------------------------- | Readonly properties defined here: | | __members__ | | name | name(self: object, /) -> str | | value | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | AVG = <AggregationType.AVG: 1> | | SUM = <AggregationType.SUM: 0> | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ScriptClass
Python Library Documentation: class ScriptClass in module torch class ScriptClass(pybind11_builtins.pybind11_object) | Method resolution order: | ScriptClass | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __call__(...) | __call__(self: torch._C.ScriptClass, *args, **kwargs) -> object | | __getattr__(...) | __getattr__(self: torch._C.ScriptClass, arg0: str) -> torch._C.ScriptClassFunction | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ScriptClassFunction
Python Library Documentation: class ScriptClassFunction in module torch class ScriptClassFunction(pybind11_builtins.pybind11_object) | Method resolution order: | ScriptClassFunction | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __call__(...) | __call__(*args, **kwargs) -> object | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ScriptDict
Python Library Documentation: class ScriptDict in module torch class ScriptDict(pybind11_builtins.pybind11_object) | Method resolution order: | ScriptDict | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __bool__(...) | __bool__(self: torch._C.ScriptDict) -> object | | __contains__(...) | __contains__(self: torch._C.ScriptDict, arg0: object) -> object | | __delitem__(...) | __delitem__(self: torch._C.ScriptDict, arg0: object) -> None | | __getitem__(...) | __getitem__(self: torch._C.ScriptDict, arg0: object) -> object | | __init__(...) | __init__(self: torch._C.ScriptDict, arg0: dict) -> None | | __iter__(...) | __iter__(self: torch._C.ScriptDict) -> torch._C.ScriptDictKeyIterator | | __len__(...) | __len__(self: torch._C.ScriptDict) -> object | | __repr__(...) | __repr__(self: torch._C.ScriptDict) -> object | | __setitem__(...) | __setitem__(self: torch._C.ScriptDict, arg0: object, arg1: object) -> None | | items(...) | items(self: torch._C.ScriptDict) -> torch._C.ScriptDictIterator | | keys(...) | keys(self: torch._C.ScriptDict) -> torch._C.ScriptDictKeyIterator | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ScriptDictIterator
Python Library Documentation: class ScriptDictIterator in module torch class ScriptDictIterator(pybind11_builtins.pybind11_object) | Method resolution order: | ScriptDictIterator | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __iter__(...) | __iter__(self: torch._C.ScriptDictIterator) -> torch._C.ScriptDictIterator | | __next__(...) | __next__(self: torch._C.ScriptDictIterator) -> object | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ScriptDictKeyIterator
Python Library Documentation: class ScriptDictKeyIterator in module torch class ScriptDictKeyIterator(pybind11_builtins.pybind11_object) | Method resolution order: | ScriptDictKeyIterator | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __iter__(...) | __iter__(self: torch._C.ScriptDictKeyIterator) -> torch._C.ScriptDictKeyIterator | | __next__(...) | __next__(self: torch._C.ScriptDictKeyIterator) -> object | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ScriptFunction
Python Library Documentation: class ScriptFunction in module torch.jit
class ScriptFunction(pybind11_builtins.pybind11_object)
| Functionally equivalent to a :class:`ScriptModule`, but represents a single
| function and does not have any attributes or Parameters.
|
| Method resolution order:
| ScriptFunction
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __call__(...)
| __call__(*args, **kwargs) -> object
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce__ = _reduce(cls) from torch.jit._script
| # Throws an error if a jit function is pickled.
| # Helps to avoid Python crashes for Python versions 3.9.5 + when protocol 0 or 1 is given as an argument.
|
| get_debug_state(...)
| get_debug_state(self: torch._C.ScriptFunction) -> torch._C.GraphExecutorState
|
| graph_for = _graph_for(self, *args, **kwargs) from torch.jit._fuser
|
| save(...)
| save(self: torch._C.ScriptFunction, filename: str, _extra_files: collections.abc.Mapping[str, str] = {}) -> None
|
| save_to_buffer(...)
| save_to_buffer(self: torch._C.ScriptFunction, _extra_files: collections.abc.Mapping[str, str] = {}) -> bytes
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| code
|
| graph
|
| inlined_graph
|
| name
|
| qualified_name
|
| schema
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
torch.ScriptList
Python Library Documentation: class ScriptList in module torch class ScriptList(pybind11_builtins.pybind11_object) | Method resolution order: | ScriptList | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __bool__(...) | __bool__(self: torch._C.ScriptList) -> object | | __contains__(...) | __contains__(self: torch._C.ScriptList, arg0: object) -> object | | __delitem__(...) | __delitem__(self: torch._C.ScriptList, arg0: typing.SupportsInt | typing.SupportsIndex) -> None | | __getitem__(...) | __getitem__(*args, **kwargs) | Overloaded function. | | 1. __getitem__(self: torch._C.ScriptList, arg0: typing.SupportsInt | typing.SupportsIndex) -> object | | 2. __getitem__(self: torch._C.ScriptList, arg0: slice) -> torch._C.ScriptList | | __getstate__(...) | __getstate__(self: torch._C.ScriptList, /) -> list | | __init__(...) | __init__(self: torch._C.ScriptList, arg0: list) -> None | | __iter__(...) | __iter__(self: torch._C.ScriptList) -> torch._C.ScriptListIterator | | __len__(...) | __len__(self: torch._C.ScriptList) -> object | | __repr__(...) | __repr__(self: torch._C.ScriptList) -> object | | __setitem__(...) | __setitem__(*args, **kwargs) | Overloaded function. | | 1. __setitem__(self: torch._C.ScriptList, arg0: typing.SupportsInt | typing.SupportsIndex, arg1: object) -> None | | 2. __setitem__(self: torch._C.ScriptList, arg0: slice, arg1: list) -> None | | __setstate__(...) | __setstate__(self: torch._C.ScriptList, arg0: list) -> None | | append(...) | append(self: torch._C.ScriptList, arg0: object) -> None | | clear(...) | clear(self: torch._C.ScriptList) -> None | | count(...) | count(self: torch._C.ScriptList, arg0: object) -> int | | extend(...) | extend(*args, **kwargs) | Overloaded function. | | 1. extend(self: torch._C.ScriptList, arg0: list) -> None | | 2. extend(self: torch._C.ScriptList, arg0: collections.abc.Iterable) -> None | | insert(...) | insert(self: torch._C.ScriptList, arg0: typing.SupportsInt | typing.SupportsIndex, arg1: object) -> None | | pop(...) | pop(*args, **kwargs) | Overloaded function. | | 1. pop(self: torch._C.ScriptList) -> object | | 2. pop(self: torch._C.ScriptList, arg0: typing.SupportsInt | typing.SupportsIndex) -> object | | remove(...) | remove(self: torch._C.ScriptList, arg0: object) -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ScriptListIterator
Python Library Documentation: class ScriptListIterator in module torch class ScriptListIterator(pybind11_builtins.pybind11_object) | Method resolution order: | ScriptListIterator | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __iter__(...) | __iter__(self: torch._C.ScriptListIterator) -> torch._C.ScriptListIterator | | __next__(...) | __next__(self: torch._C.ScriptListIterator) -> object | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ScriptMethod
Python Library Documentation: class ScriptMethod in module torch class ScriptMethod(pybind11_builtins.pybind11_object) | Method resolution order: | ScriptMethod | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __call__(...) | __call__(*args, **kwargs) -> object | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | graph_for = _script_method_graph_for(self, parent, *args, **kwargs) from torch.jit._fuser | | ---------------------------------------------------------------------- | Readonly properties defined here: | | code | | code_with_constants | | graph | | inlined_graph | | name | | owner | | raw_owner | | schema | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ScriptModule
Python Library Documentation: class ScriptModule in module torch
class ScriptModule(ScriptObject)
| Method resolution order:
| ScriptModule
| ScriptObject
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __copy__(...)
| __copy__(self: torch._C.ScriptModule) -> torch._C.ScriptModule
|
| __deepcopy__(...)
| __deepcopy__(self: torch._C.ScriptModule, arg0: dict) -> torch._C.ScriptModule
|
| __eq__(...)
| __eq__(self: torch._C.ScriptModule, arg0: object) -> bool
|
| __hash__(...)
| __hash__(self: torch._C.ScriptModule) -> int
|
| __init__(...)
| __init__(self: torch._C.ScriptModule, arg0: str, arg1: torch::jit::CompilationUnit, arg2: bool) -> None
|
| apply(...)
| apply(self: torch._C.ScriptModule, arg0: collections.abc.Callable[[torch._C.ScriptModule], None]) -> None
|
| children(...)
| children(self: torch._C.ScriptModule) -> torch::jit::slot_list_impl<torch::jit::detail::ModulePolicy>
|
| dump(...)
| dump(self: torch._C.ScriptModule, code: bool = True, attrs: bool = True, params: bool = True) -> None
|
| dump_to_str(...)
| dump_to_str(self: torch._C.ScriptModule, code: bool = True, attrs: bool = True, params: bool = True) -> str
|
| get_debug_state(...)
| get_debug_state(self: torch._C.ScriptModule) -> torch._C.GraphExecutorState
|
| save(...)
| save(self: torch._C.ScriptModule, filename: str, _extra_files: collections.abc.Mapping[str, str] = {}) -> None
|
| save_to_buffer(...)
| save_to_buffer(self: torch._C.ScriptModule, _extra_files: collections.abc.Mapping[str, str] = {}) -> bytes
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| code
|
| code_with_constants
|
| qualified_name
|
| ----------------------------------------------------------------------
| Methods inherited from ScriptObject:
|
| __abs__(...)
| __abs__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __add__(...)
| __add__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __and__(...)
| __and__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __concat__(...)
| __concat__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __contains__(...)
| __contains__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __delitem__(...)
| __delitem__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __floordiv__(...)
| __floordiv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ge__(...)
| __ge__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __getattr__(...)
| __getattr__(self: torch._C.ScriptObject, arg0: str) -> object
|
| __getitem__(...)
| __getitem__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __getstate__(...)
| __getstate__(self: torch._C.ScriptObject, /) -> tuple[object, str]
|
| __gt__(...)
| __gt__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __iadd__(...)
| __iadd__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __iand__(...)
| __iand__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __iconcat__(...)
| __iconcat__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ifloordiv__(...)
| __ifloordiv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ilshift__(...)
| __ilshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __imatmul__(...)
| __imatmul__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __imod__(...)
| __imod__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __imul__(...)
| __imul__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __index__(...)
| __index__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __inv__(...)
| __inv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __invert__(...)
| __invert__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ior__(...)
| __ior__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ipow__(...)
| __ipow__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __irshift__(...)
| __irshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __isub__(...)
| __isub__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __itruediv__(...)
| __itruediv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ixor__(...)
| __ixor__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __le__(...)
| __le__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __len__(...)
| __len__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __lshift__(...)
| __lshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __lt__(...)
| __lt__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __matmul__(...)
| __matmul__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __mod__(...)
| __mod__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __mul__(...)
| __mul__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ne__(...)
| __ne__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __neg__(...)
| __neg__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __not__(...)
| __not__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __or__(...)
| __or__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __pos__(...)
| __pos__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __pow__(...)
| __pow__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __repr__(...)
| __repr__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __rshift__(...)
| __rshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __setattr__(...)
| __setattr__(self: torch._C.ScriptObject, arg0: str, arg1: object) -> None
|
| __setitem__(...)
| __setitem__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __setstate__(...)
| __setstate__(self: torch._C.ScriptObject, arg0: tuple[object, str]) -> None
|
| __str__(...)
| __str__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __sub__(...)
| __sub__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __truediv__(...)
| __truediv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __xor__(...)
| __xor__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| getattr(...)
| getattr(self: torch._C.ScriptObject, arg0: str) -> object
|
| hasattr(...)
| hasattr(self: torch._C.ScriptObject, arg0: str) -> bool
|
| setattr(...)
| setattr(self: torch._C.ScriptObject, arg0: str, arg1: object) -> None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
torch.ScriptModuleSerializer
Python Library Documentation: class ScriptModuleSerializer in module torch class ScriptModuleSerializer(pybind11_builtins.pybind11_object) | Method resolution order: | ScriptModuleSerializer | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.ScriptModuleSerializer, arg0: torch._C.PyTorchFileWriter) -> None | | serialize(...) | serialize(self: torch._C.ScriptModuleSerializer, arg0: torch::jit::Module, arg1: typing.SupportsInt | typing.SupportsIndex) -> None | | storage_context(...) | storage_context(self: torch._C.ScriptModuleSerializer) -> torch::jit::SerializationStorageContext | | write_files(...) | write_files(self: torch._C.ScriptModuleSerializer, code_dir: str = '.data/ts_code/code/') -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ScriptObject
Python Library Documentation: class ScriptObject in module torch class ScriptObject(pybind11_builtins.pybind11_object) | Method resolution order: | ScriptObject | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __abs__(...) | __abs__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __add__(...) | __add__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __and__(...) | __and__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __concat__(...) | __concat__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __contains__(...) | __contains__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __copy__(...) | __copy__(self: torch._C.ScriptObject) -> torch._C.ScriptObject | | __deepcopy__(...) | __deepcopy__(*args, **kwargs) | Overloaded function. | | 1. __deepcopy__(self: torch._C.ScriptObject, arg0: dict) -> torch._C.ScriptObject | | 2. __deepcopy__(self: torch._C.ScriptObject, arg0: dict) -> torch._C.ScriptObject | | __delitem__(...) | __delitem__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __eq__(...) | __eq__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __floordiv__(...) | __floordiv__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __ge__(...) | __ge__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __getattr__(...) | __getattr__(self: torch._C.ScriptObject, arg0: str) -> object | | __getitem__(...) | __getitem__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __getstate__(...) | __getstate__(self: torch._C.ScriptObject, /) -> tuple[object, str] | | __gt__(...) | __gt__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __hash__(...) | __hash__(self: torch._C.ScriptObject) -> int | | __iadd__(...) | __iadd__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __iand__(...) | __iand__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __iconcat__(...) | __iconcat__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __ifloordiv__(...) | __ifloordiv__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __ilshift__(...) | __ilshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __imatmul__(...) | __imatmul__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __imod__(...) | __imod__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __imul__(...) | __imul__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __index__(...) | __index__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __inv__(...) | __inv__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __invert__(...) | __invert__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __ior__(...) | __ior__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __ipow__(...) | __ipow__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __irshift__(...) | __irshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __isub__(...) | __isub__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __itruediv__(...) | __itruediv__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __ixor__(...) | __ixor__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __le__(...) | __le__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __len__(...) | __len__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __lshift__(...) | __lshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __lt__(...) | __lt__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __matmul__(...) | __matmul__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __mod__(...) | __mod__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __mul__(...) | __mul__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __ne__(...) | __ne__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __neg__(...) | __neg__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __not__(...) | __not__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __or__(...) | __or__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __pos__(...) | __pos__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __pow__(...) | __pow__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __repr__(...) | __repr__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __rshift__(...) | __rshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __setattr__(...) | __setattr__(self: torch._C.ScriptObject, arg0: str, arg1: object) -> None | | __setitem__(...) | __setitem__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __setstate__(...) | __setstate__(self: torch._C.ScriptObject, arg0: tuple[object, str]) -> None | | __str__(...) | __str__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __sub__(...) | __sub__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __truediv__(...) | __truediv__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | __xor__(...) | __xor__(self: torch._C.ScriptObject, *args, **kwargs) -> object | | getattr(...) | getattr(self: torch._C.ScriptObject, arg0: str) -> object | | hasattr(...) | hasattr(self: torch._C.ScriptObject, arg0: str) -> bool | | setattr(...) | setattr(self: torch._C.ScriptObject, arg0: str, arg1: object) -> None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ScriptObjectProperty
Python Library Documentation: class ScriptObjectProperty in module torch class ScriptObjectProperty(pybind11_builtins.pybind11_object) | Method resolution order: | ScriptObjectProperty | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | getter | | name | | setter | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.SerializationStorageContext
Python Library Documentation: class SerializationStorageContext in module torch class SerializationStorageContext(pybind11_builtins.pybind11_object) | Method resolution order: | SerializationStorageContext | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | get_or_add_storage(...) | get_or_add_storage(self: torch._C.SerializationStorageContext, arg0: torch.StorageBase) -> int | | has_storage(...) | has_storage(self: torch._C.SerializationStorageContext, arg0: torch.StorageBase) -> bool | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ShortStorage
Python Library Documentation: class ShortStorage in module torch
class ShortStorage(torch.storage._LegacyStorage)
| ShortStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| ShortStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.int16
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.ShortTensor
Python Library Documentation: class ShortTensor in module torch
class ShortTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.int16
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
torch.Size
Python Library Documentation: class Size in module torch class Size(builtins.tuple) | Size(iterable=(), /) | | Method resolution order: | Size | builtins.tuple | builtins.object | | Methods defined here: | | __add__(self, value, /) | Return self+value. | | __getitem__(self, key, /) | Return self[key]. | | __mul__(self, value, /) | Return self*value. | | __radd__(self, value, /) | Return value+self. | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __rmul__(self, value, /) | Return value*self. | | numel(...) | numel() -> int | | Returns the number of elements a :class:`torch.Tensor` with the given size would contain. | | More formally, for a tensor ``x = tensor.ones(10, 10)`` with size ``s = torch.Size([10, 10])``, | ``x.numel() == x.size().numel() == s.numel() == 100`` holds true. | | Example:: | | >>> x=torch.ones(10, 10) | >>> s=x.size() | >>> s | torch.Size([10, 10]) | >>> s.numel() | 100 | >>> x.numel() == s.numel() | True | | | .. warning:: | | This function does not return the number of dimensions described by :class:`torch.Size`, but instead the number | of elements a :class:`torch.Tensor` with that size would contain. | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.tuple: | | __contains__(self, key, /) | Return bool(key in self). | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __iter__(self, /) | Implement iter(self). | | __le__(self, value, /) | Return self<=value. | | __len__(self, /) | Return len(self). | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | count(self, value, /) | Return number of occurrences of value. | | index(self, value, start=0, stop=9223372036854775807, /) | Return first index of value. | | Raises ValueError if the value is not present. | | ---------------------------------------------------------------------- | Class methods inherited from builtins.tuple: | | __class_getitem__(...) | See PEP 585
torch.StaticModule
Python Library Documentation: class StaticModule in module torch class StaticModule(pybind11_builtins.pybind11_object) | Method resolution order: | StaticModule | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __call__(...) | __call__(self: torch._C.StaticModule, *args, **kwargs) -> object | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | benchmark(...) | benchmark(self: torch._C.StaticModule, arg0: collections.abc.Sequence[torch.Tensor], arg1: collections.abc.Mapping[str, torch.Tensor], arg2: typing.SupportsInt | typing.SupportsIndex, arg3: typing.SupportsInt | typing.SupportsIndex) -> None | | benchmark_individual_ops(...) | benchmark_individual_ops(self: torch._C.StaticModule, arg0: collections.abc.Sequence[torch.Tensor], arg1: collections.abc.Mapping[str, torch.Tensor], arg2: typing.SupportsInt | typing.SupportsIndex, arg3: typing.SupportsInt | typing.SupportsIndex) -> torch._C.StaticModule.IndividualMetrics | | runAsync(...) | runAsync(self: torch._C.StaticModule, arg0: tuple, arg1: dict) -> object | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | IndividualMetrics = <class 'torch._C.StaticModule.IndividualMetrics'> | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Storage
Python Library Documentation: class FloatStorage in module torch
class FloatStorage(torch.storage._LegacyStorage)
| FloatStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| FloatStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.float32
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.StorageBase
Python Library Documentation: class StorageBase in module torch._C class StorageBase(builtins.object) | Methods defined here: | | __delitem__(self, key, /) | Delete self[key]. | | __getitem__(self, key, /) | Return self[key]. | | __len__(self, /) | Return len(self). | | __setitem__(self, key, value, /) | Set self[key] to value. | | copy_(...) | | data_ptr(...) | | element_size(...) | | fill_(...) | | is_shared(...) | | nbytes(...) | | new(...) | | resizable(...) | | resize_(...) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | from_buffer(...) | | from_file(...) | from_file(filename, shared=False, nbytes=0) -> Storage | | Creates a CPU storage backed by a memory-mapped file. | | If ``shared`` is ``True``, then memory is shared between all processes. | All changes are written to the file. If ``shared`` is ``False``, then the changes on | the storage do not affect the file. | | ``nbytes`` is the number of bytes of storage. If ``shared`` is ``False``, | then the file must contain at least ``nbytes`` bytes. If ``shared`` is | ``True`` the file will be created if needed. (Note that for ``UntypedStorage`` | this argument differs from that of ``TypedStorage.from_file``) | | Args: | filename (str): file name to map | shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the | underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_) | nbytes (int): number of bytes of storage | | ---------------------------------------------------------------------- | Data descriptors defined here: | | device
torch.Stream
Python Library Documentation: class Stream in module torch class Stream(builtins.object) | Stream(device, *, priority) -> Stream | | An in-order queue of executing the respective tasks asynchronously in first in first out (FIFO) order. | It can control or synchronize the execution of other Stream or block the current host thread to ensure | the correct task sequencing. It supports with statement as a context manager to ensure the operators | within the with block are running on the corresponding stream. | | See in-depth description of the CUDA behavior at :ref:`cuda-semantics` for details | on the exact semantic that applies to all devices. | | Arguments: | device (:class:`torch.device`, optional): the desired device for the Stream. | If not given, the current :ref:`accelerator<accelerators>` type will be used. | priority (int, optional): priority of the stream, should be 0 or negative, where negative | numbers indicate higher priority. By default, streams have priority 0. | | Returns: | Stream: An torch.Stream object. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> with torch.Stream(device='cuda') as s_cuda: | >>> a = torch.randn(10, 5, device='cuda') | >>> b = torch.randn(5, 10, device='cuda') | >>> c = torch.mm(a, b) | | Methods defined here: | | __enter__(...) | | __eq__(self, value, /) | Return self==value. | | __exit__(...) | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __repr__(self, /) | Return repr(self). | | is_capturing(...) | Stream.is_capturing() -> bool | | Return true if this stream is currently recording work for graph capture. | | Returns: | bool: A boolean indicating if the stream is capturing. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> s_cuda = torch.Stream(device='cuda') | >>> s_cuda.is_capturing() | | query(...) | Stream.query() -> bool | | Check if all the work submitted has been completed. | | Returns: | bool: A boolean indicating if all kernels in this stream are completed. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> s_cuda = torch.Stream(device='cuda') | >>> s_cuda.query() | True | | record_event(...) | Stream.record_event(event) -> Event | | Record an event. En-queuing it into the Stream to allow further synchronization from the current point in the FIFO queue. | | Arguments: | event (:class:`torch.Event`, optional): event to record. If not given, a new one will be allocated. | | Returns: | Event: Recorded event. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> s_cuda = torch.Stream(device='cuda') | >>> e_cuda = s_cuda.record_event() | | synchronize(...) | Stream.synchronize() -> None | | Wait for all the kernels in this stream to complete. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> s_cuda = torch.Stream(device='cuda') | >>> s_cuda.synchronize() | | wait_event(...) | Stream.wait_event(event) -> None | | Make all future work submitted to the stream wait for an event. | | Arguments: | event (:class:`torch.Event`): an event to wait for. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> s1_cuda = torch.Stream(device='cuda') | >>> s2_cuda = torch.Stream(device='cuda') | >>> e_cuda = s1_cuda.record_event() | >>> s2_cuda.wait_event(e_cuda) | | wait_stream(...) | Stream.wait_stream(stream) -> None | | Synchronize with another stream. All future work submitted to this stream will wait until all kernels | already submitted to the given stream are completed. | | Arguments: | stream (:class:`torch.Stream`): a stream to synchronize. | | Example:: | | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA) | >>> s1_cuda = torch.Stream(device='cuda') | >>> s2_cuda = torch.Stream(device='cuda') | >>> s2_cuda.wait_stream(s1_cuda) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | device | | device_index | | device_type | | native_handle | | stream_id
torch.StreamObjType
Python Library Documentation: class StreamObjType in module torch class StreamObjType(Type) | Method resolution order: | StreamObjType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.StreamObjType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.StringType
Python Library Documentation: class StringType in module torch class StringType(Type) | Method resolution order: | StringType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.StringType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.SymBool
Python Library Documentation: class SymBool in module torch class SymBool(builtins.object) | SymBool(node) | | Like a bool (including magic methods), but redirects all operations on the | wrapped node. This is used in particular to symbolically record operations | in the symbolic shape workflow. | | Unlike regular bools, regular boolean operators will force extra guards instead | of symbolically evaluate. Use the bitwise operators instead to handle this. | | Methods defined here: | | __add__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __and__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __bool__(self) | | __eq__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __hash__(self) | Return hash(self). | | __init__(self, node) | Initialize self. See help(type(self)) for accurate signature. | | __int__(self) | | __mul__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __or__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __radd__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rand__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __repr__(self) | Return repr(self). | | __rmul__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __ror__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rsub__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __sub__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __sym_float__(self) | Provides a SymFloat representation (0.0 or 1.0) for this SymBool. | Called by torch.sym_float() when casting SymBool to float. | | __sym_ite__ = sym_ite_magic_impl(pred: 'SymBool', then_val: 'object', else_val: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __sym_not__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
torch.SymBoolType
Python Library Documentation: class SymBoolType in module torch class SymBoolType(Type) | Method resolution order: | SymBoolType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.SymBoolType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.SymFloat
Python Library Documentation: class SymFloat in module torch class SymFloat(builtins.object) | SymFloat(node) | | Like a float (including magic methods), but redirects all operations on the | wrapped node. This is used in particular to symbolically record operations | in the symbolic shape workflow. | | Methods defined here: | | __abs__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __add__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __bool__(self) | | __ceil__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __eq__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __float__(self) | | __float_pow__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __float_truediv__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __floor__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __floordiv__(self, other) | | __ge__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __gt__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __hash__(self) | Return hash(self). | | __init__(self, node) | Initialize self. See help(type(self)) for accurate signature. | | __int__(self) | | __int_floordiv__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __int_truediv__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __le__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __lshift__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __lt__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __mod__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __mul__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __ne__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __neg__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __pos__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __pow__(self, other) | # Symbolic power does NOT work with negative base, this is to avoid | # potential complex outputs | | __pow_by_natural__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __radd__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __repr__(self) | Return repr(self). | | __rfloat_pow__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rfloat_truediv__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rfloordiv__(self, other) | | __rint_floordiv__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rint_truediv__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rlshift__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rmod__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rmul__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __round__ = round_magic_impl(self: 'SymFloat', ndigits: 'int | None' = None) -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rpow__(self, other) | | __rpow_by_natural__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rrshift__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rshift__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rsub__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rtruediv__(self, other) | | __sub__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __sym_acos__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_asin__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_atan__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_cos__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_cosh__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_float__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_int__(self) | | __sym_log2__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_max__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __sym_min__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __sym_sin__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_sinh__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_sqrt__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_tan__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_tanh__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __truediv__(self, other) | | __trunc__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | as_integer_ratio(self) -> tuple[int, int] | Represent this float as an exact integer ratio | | conjugate(self) -> 'SymFloat' | Returns the complex conjugate of the float. | | hex(self) -> str | Returns the hexadecimal representation of the float. | | is_integer(self) | Return True if the float is an integer. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
torch.SymInt
Python Library Documentation: class SymInt in module torch class SymInt(builtins.object) | SymInt(node) | | Like an int (including magic methods), but redirects all operations on the | wrapped node. This is used in particular to symbolically record operations | in the symbolic shape workflow. | | Methods defined here: | | __abs__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __add__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __and__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __bool__(self) | | __ceil__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __eq__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __float_pow__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __float_truediv__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __floor__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __floordiv__(self, other) | | __ge__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __gt__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __hash__(self) -> int | Return hash(self). | | __index__(self) | | __init__(self, node) | Initialize self. See help(type(self)) for accurate signature. | | __int__(self) | | __int_floordiv__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __int_truediv__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __le__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __lshift__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __lt__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __mod__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __mul__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __ne__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __neg__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __or__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __pos__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __pow__(self, other) | # nb: complex is impossible to handle correctly lol, with | # negative base and integral float need to diverge semantics and | # just always return complex. Neener neener pretend this problem | # doesn't exist | | __pow_by_natural__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __radd__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rand__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __repr__(self) | Return repr(self). | | __rfloat_pow__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rfloat_truediv__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rfloordiv__(self, other) | | __rint_floordiv__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rint_truediv__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rlshift__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rmod__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rmul__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __ror__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __round__(self, ndigits=None) | | __rpow__(self, other) | | __rpow_by_natural__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rrshift__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rshift__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rsub__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __rtruediv__(self, other) | | __rxor__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __sub__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __sym_acos__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_asin__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_atan__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_cos__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_cosh__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_float__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_max__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __sym_min__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | __sym_sin__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_sinh__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_sqrt__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_tan__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __sym_tanh__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __truediv__(self, other) | | __trunc__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | # Before and after performing the operation, check if any operands are constant. | # If so, extract out the constant values first. If `self` itself is a | # constant, then "redispatch" by calling back into the operator. Sometimes | # this means that operations involving SymBool return plain bools. | # Alternatively, we could also rewrap into constant Symbool (i.e. by | # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that | # today for no particular reason. | | __xor__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals> | | as_integer_ratio(self) -> tuple['SymInt', int] | Represent this int as an exact integer ratio | | bit_length(self) -> int | | conjugate(self) -> 'SymInt' | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
torch.SymIntType
Python Library Documentation: class SymIntType in module torch class SymIntType(Type) | Method resolution order: | SymIntType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.SymIntType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.TYPE_CHECKING
Python Library Documentation: bool object class bool(int) | bool(x) -> bool | | Returns True when the argument x is true, False otherwise. | The builtins True and False are the only two instances of the class bool. | The class bool is a subclass of the class int, and cannot be subclassed. | | Method resolution order: | bool | int | object | | Methods defined here: | | __and__(self, value, /) | Return self&value. | | __invert__(self, /) | ~self | | __or__(self, value, /) | Return self|value. | | __rand__(self, value, /) | Return value&self. | | __repr__(self, /) | Return repr(self). | | __ror__(self, value, /) | Return value|self. | | __rxor__(self, value, /) | Return value^self. | | __xor__(self, value, /) | Return self^value. | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __format__(self, format_spec, /) | Convert to a string according to format_spec. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number
torch.Tag
Python Library Documentation: class Tag in module torch class Tag(pybind11_builtins.pybind11_object) | Method resolution order: | Tag | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __eq__(...) | __eq__(self: object, other: object, /) -> bool | | __getstate__(...) | __getstate__(self: object, /) -> int | | __hash__(...) | __hash__(self: object, /) -> int | | __index__(...) | __index__(self: torch._C.Tag, /) -> int | | __init__(...) | __init__(self: torch._C.Tag, value: typing.SupportsInt | typing.SupportsIndex) -> None | | __int__(...) | __int__(self: torch._C.Tag, /) -> int | | __ne__(...) | __ne__(self: object, other: object, /) -> bool | | __repr__(...) | __repr__(self: object, /) -> str | | __setstate__(...) | __setstate__(self: torch._C.Tag, state: typing.SupportsInt | typing.SupportsIndex, /) -> None | | __str__(...) | __str__(self: object, /) -> str | | ---------------------------------------------------------------------- | Readonly properties defined here: | | __members__ | | name | name(self: object, /) -> str | | value | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | core = <Tag.core: 0> | | cudagraph_unsafe = <Tag.cudagraph_unsafe: 1> | | data_dependent_output = <Tag.data_dependent_output: 2> | | dynamic_output_shape = <Tag.dynamic_output_shape: 3> | | flexible_layout = <Tag.flexible_layout: 4> | | generated = <Tag.generated: 5> | | inplace = <Tag.inplace: 6> | | inplace_view = <Tag.inplace_view: 7> | | maybe_aliasing_or_mutating = <Tag.maybe_aliasing_or_mutating: 8> | | needs_contiguous_strides = <Tag.needs_contiguous_strides: 9> | | needs_exact_strides = <Tag.needs_exact_strides: 10> | | needs_fixed_stride_order = <Tag.needs_fixed_stride_order: 11> | | nondeterministic_bitwise = <Tag.nondeterministic_bitwise: 12> | | nondeterministic_seeded = <Tag.nondeterministic_seeded: 13> | | out = <Tag.out: 14> | | out_variant = <Tag.out_variant: 15> | | pointwise = <Tag.pointwise: 16> | | pt2_compliant_tag = <Tag.pt2_compliant_tag: 17> | | reduction = <Tag.reduction: 18> | | view_copy = <Tag.view_copy: 19> | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Tensor
Python Library Documentation: class Tensor in module torch
class Tensor(torch._C.TensorBase)
| Method resolution order:
| Tensor
| torch._C.TensorBase
| builtins.object
|
| Methods defined here:
|
| __abs__ = abs(...)
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __neg__ = neg(...)
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| solve(self, other) from torch._tensor.Tensor
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C.TensorBase:
|
| __add__(...)
|
| __and__(...)
|
| __bool__(...)
|
| __complex__(...)
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __div__(...)
|
| __eq__(...)
| Return self==value.
|
| __float__(...)
|
| __ge__(...)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(...)
| Return self>value.
|
| __iadd__(...)
|
| __iand__(...)
|
| __idiv__(...)
|
| __ifloordiv__(...)
|
| __ilshift__(...)
|
| __imod__(...)
|
| __imul__(...)
|
| __index__(...)
|
| __int__(...)
|
| __invert__(...)
|
| __ior__(...)
|
| __irshift__(...)
|
| __isub__(...)
|
| __ixor__(...)
|
| __le__(...)
| Return self<=value.
|
| __long__(...)
|
| __lshift__(...)
|
| __lt__(...)
| Return self<value.
|
| __matmul__(...)
|
| __mod__(...)
|
| __mul__(...)
|
| __ne__(...)
| Return self!=value.
|
| __nonzero__(...)
|
| __or__(...)
| Return self|value.
|
| __radd__(...)
|
| __rand__(...)
|
| __rmul__(...)
|
| __ror__(...)
| Return value|self.
|
| __rshift__(...)
|
| __rxor__(...)
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sub__(...)
|
| __truediv__(...)
|
| __xor__(...)
|
| abs(...)
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...)
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...)
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...)
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...)
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...)
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...)
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...)
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...)
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...)
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...)
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...)
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...)
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...)
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...)
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...)
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...)
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...)
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...)
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...)
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...)
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...)
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...)
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...)
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...)
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...)
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...)
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...)
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...)
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...)
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...)
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...)
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...)
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...)
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...)
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...)
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...)
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...)
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...)
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...)
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...)
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...)
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...)
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...)
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...)
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...)
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...)
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...)
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...)
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...)
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...)
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...)
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...)
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...)
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...)
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...)
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...)
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...)
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...)
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| baddbmm(...)
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...)
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...)
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...)
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...)
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...)
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...)
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...)
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...)
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...)
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...)
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...)
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...)
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...)
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...)
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...)
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...)
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...)
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...)
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...)
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...)
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...)
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...)
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...)
|
| cdouble(...)
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...)
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...)
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...)
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...)
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...)
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...)
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...)
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...)
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...)
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...)
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...)
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...)
|
| clamp_max_(...)
|
| clamp_min(...)
|
| clamp_min_(...)
|
| clip(...)
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...)
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...)
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...)
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...)
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...)
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...)
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...)
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...)
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...)
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...)
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...)
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...)
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...)
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...)
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...)
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...)
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...)
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...)
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...)
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...)
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...)
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...)
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...)
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...)
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...)
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...)
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...)
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...)
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...)
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...)
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...)
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...)
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...)
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...)
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...)
| det() -> Tensor
|
| See :func:`torch.det`
|
| diag(...)
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...)
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...)
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...)
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...)
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...)
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...)
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...)
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...)
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dist(...)
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...)
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...)
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...)
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...)
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...)
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...)
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...)
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| element_size(...)
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...)
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...)
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...)
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...)
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...)
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...)
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...)
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...)
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...)
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...)
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...)
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...)
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...)
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...)
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...)
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...)
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...)
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...)
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...)
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...)
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...)
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...)
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...)
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...)
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...)
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...)
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...)
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...)
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...)
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...)
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...)
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...)
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...)
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...)
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...)
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...)
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...)
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...)
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...)
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...)
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...)
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...)
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...)
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...)
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...)
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...)
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...)
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...)
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...)
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...)
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...)
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...)
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...)
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...)
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...)
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...)
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...)
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...)
|
| heaviside(...)
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...)
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...)
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...)
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...)
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...)
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...)
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...)
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...)
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...)
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...)
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...)
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...)
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index_add(...)
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...)
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...)
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...)
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...)
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...)
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...)
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...)
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...)
|
| index_reduce_(...)
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...)
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...)
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...)
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...)
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...)
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...)
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...)
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...)
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...)
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...)
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...)
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...)
|
| is_floating_point(...)
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...)
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...)
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...)
|
| is_pinned(...)
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...)
|
| is_set_to(...)
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_signed(...)
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...)
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...)
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...)
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...)
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...)
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...)
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...)
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| item(...)
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...)
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...)
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...)
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...)
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...)
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...)
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...)
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...)
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...)
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...)
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...)
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...)
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...)
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...)
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...)
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...)
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...)
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...)
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...)
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...)
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...)
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...)
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...)
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...)
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...)
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...)
|
| logaddexp(...)
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...)
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...)
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...)
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...)
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...)
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...)
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...)
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...)
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...)
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...)
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...)
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...)
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...)
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...)
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...)
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lt(...)
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...)
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu_solve(...)
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...)
|
| map_(...)
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...)
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...)
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...)
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...)
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...)
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...)
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...)
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...)
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...)
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...)
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...)
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...)
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...)
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...)
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...)
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...)
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| moveaxis(...)
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...)
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...)
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...)
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...)
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...)
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...)
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...)
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...)
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...)
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...)
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...)
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...)
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...)
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...)
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...)
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...)
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...)
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...)
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...)
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...)
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...)
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...)
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...)
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...)
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...)
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...)
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...)
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...)
|
| new_empty(...)
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...)
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...)
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...)
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...)
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...)
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...)
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...)
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...)
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...)
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| normal_(...)
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...)
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...)
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...)
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...)
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...)
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...)
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...)
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...)
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...)
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...)
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...)
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...)
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...)
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...)
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...)
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...)
|
| prod(...)
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...)
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...)
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...)
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...)
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...)
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...)
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...)
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...)
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...)
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...)
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...)
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...)
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...)
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...)
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...)
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...)
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...)
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| relu(...)
|
| relu_(...)
|
| remainder(...)
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...)
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...)
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...)
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...)
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...)
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...)
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...)
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...)
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize_(...)
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as_(...)
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...)
|
| resolve_conj(...)
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...)
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...)
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...)
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...)
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...)
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...)
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...)
|
| rsqrt(...)
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...)
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...)
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...)
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...)
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...)
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...)
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...)
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...)
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...)
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...)
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...)
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...)
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| short(...)
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...)
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...)
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...)
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...)
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...)
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...)
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...)
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...)
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...)
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...)
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...)
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...)
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...)
|
| slice_scatter(...)
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...)
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...)
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...)
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| sort(...)
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...)
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...)
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...)
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...)
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split_with_sizes(...)
|
| sqrt(...)
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...)
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...)
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...)
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...)
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...)
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...)
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...)
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| storage_offset(...)
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| stride(...)
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...)
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...)
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...)
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...)
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...)
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...)
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...)
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...)
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...)
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...)
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...)
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| t(...)
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...)
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...)
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...)
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...)
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...)
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...)
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...)
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...)
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...)
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...)
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...)
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...)
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...)
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...)
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...)
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...)
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_csc(...)
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...)
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...)
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...)
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...)
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...)
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...)
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...)
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...)
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...)
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...)
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...)
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...)
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...)
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...)
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...)
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...)
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...)
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...)
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unfold(...)
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...)
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unsafe_chunk(...)
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...)
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...)
|
| unsqueeze(...)
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...)
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...)
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...)
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...)
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...)
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...)
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...)
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...)
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...)
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...)
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...)
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...)
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...)
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch._C.TensorBase:
|
| __new__(*args, **kwargs) class method of torch._C.TensorBase
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C.TensorBase:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| dtype
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_cuda
| Is ``True`` if the Tensor is stored on the GPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_sparse
| Is ``True`` if the Tensor uses sparse COO storage layout, ``False`` otherwise.
|
| is_sparse_csr
| Is ``True`` if the Tensor uses sparse CSR storage layout, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| is_xpu
| Is ``True`` if the Tensor is stored on the XPU, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| layout
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
torch.TensorType
Python Library Documentation: class TensorType in module torch class TensorType(Type) | Method resolution order: | TensorType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods defined here: | | create_from_tensor(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | create_from_tensor(arg0: torch.Tensor) -> torch._C.TensorType | | get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | get() -> torch._C.TensorType | | getInferred(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance | getInferred() -> torch._C.TensorType | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.ThroughputBenchmark
Python Library Documentation: class ThroughputBenchmark in module torch class ThroughputBenchmark(pybind11_builtins.pybind11_object) | Method resolution order: | ThroughputBenchmark | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(*args, **kwargs) | Overloaded function. | | 1. __init__(self: torch._C.ThroughputBenchmark, arg0: torch._C.ScriptModule) -> None | | 2. __init__(self: torch._C.ThroughputBenchmark, arg0: object) -> None | | add_input(...) | add_input(self: torch._C.ThroughputBenchmark, *args, **kwargs) -> None | | benchmark(...) | benchmark(self: torch._C.ThroughputBenchmark, arg0: torch._C.BenchmarkConfig) -> torch._C.BenchmarkExecutionStats | | run_once(...) | run_once(self: torch._C.ThroughputBenchmark, *args, **kwargs) -> object | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.TracingState
Python Library Documentation: class TracingState in module torch class TracingState(pybind11_builtins.pybind11_object) | Method resolution order: | TracingState | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __repr__(...) | __repr__(self: torch._C.TracingState) -> str | | __str__(...) | __str__(self: torch._C.TracingState) -> str | | current_scope(...) | current_scope(self: torch._C.TracingState) -> str | | graph(...) | graph(self: torch._C.TracingState) -> torch._C.Graph | | pop_scope(...) | pop_scope(self: torch._C.TracingState) -> None | | push_scope(...) | push_scope(self: torch._C.TracingState, arg0: str) -> None | | set_graph(...) | set_graph(self: torch._C.TracingState, arg0: torch._C.Graph) -> None | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.TupleType
Python Library Documentation: class TupleType in module torch class TupleType(Type) | Method resolution order: | TupleType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.TupleType, arg0: collections.abc.Sequence[torch._C.Type]) -> None | | elements(...) | elements(self: torch._C.TupleType) -> list[torch._C.Type] | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Type
Python Library Documentation: class Type in module torch class Type(pybind11_builtins.pybind11_object) | Method resolution order: | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties defined here: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.TypedStorage
Python Library Documentation: class TypedStorage in module torch.storage
class TypedStorage(builtins.object)
| TypedStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Methods defined here:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
torch.USE_GLOBAL_DEPS
Python Library Documentation: bool object class bool(int) | bool(x) -> bool | | Returns True when the argument x is true, False otherwise. | The builtins True and False are the only two instances of the class bool. | The class bool is a subclass of the class int, and cannot be subclassed. | | Method resolution order: | bool | int | object | | Methods defined here: | | __and__(self, value, /) | Return self&value. | | __invert__(self, /) | ~self | | __or__(self, value, /) | Return self|value. | | __rand__(self, value, /) | Return value&self. | | __repr__(self, /) | Return repr(self). | | __ror__(self, value, /) | Return value|self. | | __rxor__(self, value, /) | Return value^self. | | __xor__(self, value, /) | Return self^value. | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __format__(self, format_spec, /) | Convert to a string according to format_spec. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number
torch.USE_RTLD_GLOBAL_WITH_LIBTORCH
Python Library Documentation: bool object class bool(int) | bool(x) -> bool | | Returns True when the argument x is true, False otherwise. | The builtins True and False are the only two instances of the class bool. | The class bool is a subclass of the class int, and cannot be subclassed. | | Method resolution order: | bool | int | object | | Methods defined here: | | __and__(self, value, /) | Return self&value. | | __invert__(self, /) | ~self | | __or__(self, value, /) | Return self|value. | | __rand__(self, value, /) | Return value&self. | | __repr__(self, /) | Return repr(self). | | __ror__(self, value, /) | Return value|self. | | __rxor__(self, value, /) | Return value^self. | | __xor__(self, value, /) | Return self^value. | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __format__(self, format_spec, /) | Convert to a string according to format_spec. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number
torch.UnionType
Python Library Documentation: class UnionType in module torch class UnionType(Type) | Method resolution order: | UnionType | Type | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(...) | __init__(self: torch._C.UnionType, arg0: collections.abc.Sequence[torch._C.Type]) -> None | | ---------------------------------------------------------------------- | Methods inherited from Type: | | __eq__(...) | __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool | | __repr__(...) | __repr__(self: torch._C.Type) -> str | | containedTypes(...) | containedTypes(self: torch._C.Type) -> list[torch._C.Type] | | contiguous(...) | contiguous(self: torch._C.Type) -> torch._C.Type | | device(...) | device(self: torch._C.Type) -> object | | dim(...) | dim(self: torch._C.Type) -> object | | dtype(...) | dtype(self: torch._C.Type) -> object | | isSubtypeOf(...) | isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool | | is_interface_type(...) | is_interface_type(self: torch._C.Type) -> bool | | kind(...) | kind(self: torch._C.Type) -> str | | requires_grad(...) | requires_grad(self: torch._C.Type) -> bool | | scalarType(...) | scalarType(self: torch._C.Type) -> str | | sizes(...) | sizes(self: torch._C.Type) -> object | | str(...) | str(self: torch._C.Type) -> str | | strides(...) | strides(self: torch._C.Type) -> object | | symbolic_sizes(...) | symbolic_sizes(self: torch._C.Type) -> object | | undefined(...) | undefined(self: torch._C.Type) -> object | | varyingSizes(...) | varyingSizes(self: torch._C.Type) -> object | | with_device(...) | with_device(self: torch._C.Type, arg0: object) -> object | | with_dtype(...) | with_dtype(self: torch._C.Type, arg0: object) -> object | | with_sizes(...) | with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object | | ---------------------------------------------------------------------- | Readonly properties inherited from Type: | | annotation_str | | ---------------------------------------------------------------------- | Data and other attributes inherited from Type: | | __hash__ = None | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.UntypedStorage
Python Library Documentation: class UntypedStorage in module torch.storage
class UntypedStorage(torch._C.StorageBase, _StorageBase)
| UntypedStorage(*args, **kwargs)
|
| Method resolution order:
| UntypedStorage
| torch._C.StorageBase
| _StorageBase
| builtins.object
|
| Methods defined here:
|
| __getitem__(self, *args, **kwargs)
| Return self[key].
|
| share_memory_(self, *args, **kwargs)
| Moves the storage to shared memory.
|
| This is a no-op for storages already in shared memory and for CUDA
| storages, which do not need to be moved for sharing across processes.
| Storages in shared memory cannot be resized.
|
| Note that to mitigate issues like `this <https://github.com/pytorch/pytorch/issues/95606>`_
| it is thread safe to call this function from multiple threads on the same object.
| It is NOT thread safe though to call any other function on self without proper
| synchronization. Please see :doc:`/notes/multiprocessing` for more details.
|
| .. note::
| When all references to a storage in shared memory are deleted, the associated shared memory
| object will also be deleted. PyTorch has a special cleanup process to ensure that this happens
| even if the current process exits unexpectedly.
|
| It is worth noting the difference between :meth:`share_memory_` and :meth:`from_file` with ``shared = True``
|
| #. ``share_memory_`` uses `shm_open(3) <https://man7.org/linux/man-pages/man3/shm_open.3.html>`_ to create a
| POSIX shared memory object while :meth:`from_file` uses
| `open(2) <https://man7.org/linux/man-pages/man2/open.2.html>`_ to open the filename passed by the user.
| #. Both use an `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_ with ``MAP_SHARED``
| to map the file/object into the current virtual address space
| #. ``share_memory_`` will call ``shm_unlink(3)`` on the object after mapping it to make sure the shared memory
| object is freed when no process has the object open. ``torch.from_file(shared=True)`` does not unlink the
| file. This file is persistent and will remain until it is deleted by the user.
|
| Returns:
| ``self``
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| filename
| Returns the file name associated with this storage.
|
| The file name will be a string if the storage is on CPU and was created via
| :meth:`~torch.from_file()` with ``shared`` as ``True``. This attribute is ``None`` otherwise.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C.StorageBase:
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __len__(self, /)
| Return len(self).
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| copy_(...)
|
| data_ptr(...)
|
| element_size(...)
|
| fill_(...)
|
| is_shared(...)
|
| nbytes(...)
|
| new(...)
|
| resizable(...)
|
| resize_(...)
|
| ----------------------------------------------------------------------
| Static methods inherited from torch._C.StorageBase:
|
| __new__(*args, **kwargs) class method of torch._C.StorageBase
| Create and return a new object. See help(type) for accurate signature.
|
| from_buffer(...)
|
| from_file(...)
| from_file(filename, shared=False, nbytes=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``nbytes`` is the number of bytes of storage. If ``shared`` is ``False``,
| then the file must contain at least ``nbytes`` bytes. If ``shared`` is
| ``True`` the file will be created if needed. (Note that for ``UntypedStorage``
| this argument differs from that of ``TypedStorage.from_file``)
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| nbytes (int): number of bytes of storage
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C.StorageBase:
|
| device
|
| ----------------------------------------------------------------------
| Methods inherited from _StorageBase:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| byteswap(self, dtype)
| Swap bytes in underlying data.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> '_StorageBase | TypedStorage'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| double(self)
| Casts this storage to double type.
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> '_StorageBase | TypedStorage'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU storage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| long(self)
| Casts this storage to long type.
|
| mps(self)
| Return a MPS copy of this storage if it's not already on the MPS.
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU storage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| short(self)
| Casts this storage to short type.
|
| size(self) -> '_int'
|
| to(self, *, device: 'DeviceLikeType', non_blocking: '_bool' = False)
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: '_bool' = False) -> '_StorageBase | TypedStorage'
|
| untyped(self)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from _StorageBase:
|
| is_sparse = False
|
| is_sparse_csr = False
torch.Use
Python Library Documentation: class Use in module torch class Use(pybind11_builtins.pybind11_object) | Method resolution order: | Use | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | isAfter(...) | isAfter(self: torch._C.Use, arg0: torch._C.Use) -> bool | | ---------------------------------------------------------------------- | Readonly properties defined here: | | offset | | user | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.Value
Python Library Documentation: class Value in module torch class Value(pybind11_builtins.pybind11_object) | Method resolution order: | Value | pybind11_builtins.pybind11_object | builtins.object | | Methods defined here: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __repr__(...) | __repr__(self: torch._C.Value) -> str | | copyMetadata(...) | copyMetadata(self: torch._C.Value, arg0: torch._C.Value) -> torch._C.Value | | debugName(...) | debugName(self: torch._C.Value) -> str | | inferTypeFrom(...) | inferTypeFrom(*args, **kwargs) | Overloaded function. | | 1. inferTypeFrom(self: torch._C.Value, arg0: torch.Tensor) -> None | | 2. inferTypeFrom(self: torch._C.Value, arg0: c10::ivalue::Object) -> None | | isCompleteTensor(...) | isCompleteTensor(self: torch._C.Value) -> bool | | node(...) | node(self: torch._C.Value) -> torch::jit::Node | | offset(...) | offset(self: torch._C.Value) -> int | | replaceAllUsesAfterNodeWith(...) | replaceAllUsesAfterNodeWith(self: torch._C.Value, arg0: torch::jit::Node, arg1: torch._C.Value) -> None | | replaceAllUsesWith(...) | replaceAllUsesWith(self: torch._C.Value, arg0: torch._C.Value) -> None | | requiresGrad(...) | requiresGrad(self: torch._C.Value) -> bool | None | | requires_grad(...) | requires_grad(self: torch._C.Value) -> bool | | setDebugName(...) | setDebugName(self: torch._C.Value, arg0: str) -> torch._C.Value | | setType(...) | setType(self: torch._C.Value, arg0: c10::Type) -> torch._C.Value | | setTypeAs(...) | setTypeAs(self: torch._C.Value, arg0: torch._C.Value) -> torch._C.Value | | toIValue(...) | toIValue(self: torch._C.Value) -> IValue | None | | type(...) | type(*args, **kwargs) | Overloaded function. | | 1. type(self: torch._C.Value) -> c10::Type | | 2. type(self: torch._C.Value) -> c10::Type | | unique(...) | unique(self: torch._C.Value) -> int | | uses(...) | uses(self: torch._C.Value) -> list[torch::jit::Use] | | ---------------------------------------------------------------------- | Static methods inherited from pybind11_builtins.pybind11_object: | | __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object | Create and return a new object. See help(type) for accurate signature.
torch.abs
Python Library Documentation: built-in function abs in module torch
abs(...)
abs(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Computes the absolute value of each element in :attr:`input`.
.. math::
\text{out}_{i} = |\text{input}_{i}|
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.abs(torch.tensor([-1, -2, 3]))
tensor([ 1, 2, 3])
torch.abs_
Python Library Documentation: built-in function abs_ in module torch abs_(...)
torch.absolute
Python Library Documentation: built-in function absolute in module torch
absolute(...)
absolute(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.abs`
torch.accelerator
Python Library Documentation: package torch.accelerator in torch
NAME
torch.accelerator - This package introduces support for the current :ref:`accelerator<accelerators>` in python.
PACKAGE CONTENTS
_utils
graphs
memory
CLASSES
builtins.object
device_index
torch._C._acceleratorGraph(pybind11_builtins.pybind11_object)
torch.accelerator.graphs.Graph
class Graph(torch._C._acceleratorGraph)
| Graph(keep_graph: bool = False, *, pool: tuple[int, int] | None = None, capture_error_mode: Literal['default', 'global', 'thread_local', 'relaxed'] = 'default') -> Self
|
| Wrapper around an :ref:`accelerator<accelerators>` graph that supports capture and replay.
|
| A graph captures a sequence of operations and their dependencies, allowing them to be
| replayed efficiently with reduced overhead. This class can be used as a context manager
| to automatically capture operations on the current stream.
|
| Arguments:
| keep_graph (bool, optional): If ``False``, the underlying graph is destroyed and the
| executable graph is instantiated on the GPU at the end of ``capture_end``.
| If ``True``, the underlying graph is preserved after ``capture_end``. In this case,
| the executable graph is not instantiated automatically; it must be explicitly created
| by calling ``instantiate``, or it will be instantiated on the first call to ``replay``.
| Defaults to ``False``.
| pool (tuple[int, int], optional): Memory pool identifier for this graph. Multiple graphs
| can share the same pool by passing the same identifier, which can reduce memory overhead.
| Defaults to ``None``.
| capture_error_mode (Literal["default", "global", "thread_local", "relaxed"], optional):
| Specifies the behavior of graph capture. The exact semantics are backend-specific.
| ``"default"``: backend-defined default capture behavior.
| ``"global"``: potentially unsafe API calls are prohibited. Errors may occur if capture
| in the current thread affects other threads.
| ``"thread_local"``: potentially unsafe API calls are prohibited. Errors occur only if
| capture in the current thread affects itself.
| ``"relaxed"``: the current thread is allowed to make potentially unsafe API calls, except
| for calls that inherently conflict with stream capture.
| Default: ``"default"``.
|
| Example::
|
| >>> # xdoctest: +SKIP
| >>> x = torch.zeros([2000], device=0)
|
| >>> stream = torch.Stream()
| >>> graph = torch.accelerator.Graph()
| >>> with stream, graph:
| ... x += 1
|
| >>> graph.replay()
|
| Method resolution order:
| Graph
| torch._C._acceleratorGraph
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, *exc_info: object) -> None
|
| __init__(self, keep_graph: bool = False, *, pool: tuple[int, int] | None = None, capture_error_mode: Literal['default', 'global', 'thread_local', 'relaxed'] = 'default') -> None
| __init__(self: torch._C._acceleratorGraph, keep_graph: bool = False) -> None
|
| capture_begin(self) -> None
| Begin graph capture on the current stream.
|
| All operations on the current stream after this call will be recorded into the graph until
| ``capture_end`` is called, using the memory pool and capture error mode provided at construction time.
|
| capture_end(self) -> None
| End graph capture on the current stream of the current device.
|
| After this call, the graph can be replayed via ``replay``.
|
| debug_dump(self, path: str) -> None
| Dump the captured graph to a file for debugging purposes if the debugging is
| enabled via ``enable_debug_mode``.
|
| Arguments:
| path (str): Path to dump the graph to.
|
| Example::
| >>> # xdoctest: +SKIP
| >>> s = torch.Stream()
| >>> g = torch.accelerator.Graph()
| >>> g.enable_debug_mode()
|
| >>> with s, g:
| >>> # ... operations ...
|
| >>> # Dump captured graph to a file "graph_dump.dot"
| >>> g.debug_dump("graph_dump.dot")
|
| enable_debug_mode(self) -> None
| Enable debugging mode for ``debug_dump``.
|
| instantiate(self) -> None
| Instantiate the underlying graph. Will be called by ``capture_end``
| if ``keep_graph=False``, or by ``replay`` if ``keep_graph=True`` and
| ``instantiate`` has not already been explicitly called.
|
| pool(self) -> tuple[int, int]
| Return an opaque token representing the id of this graph's memory pool.
|
| This id can optionally be passed to another graph's ``capture_begin``,
| which hints the other graph may share the same memory pool.
|
| Example::
| >>> # xdoctest: +SKIP
| >>> g1 = torch.accelerator.Graph()
| >>> g1.capture_begin()
| >>> # ... operations ...
| >>> g1.capture_end()
|
| >>> # Share g1's memory pool with a new graph
| >>> pool_id = g1.pool()
| >>> g2 = torch.accelerator.Graph(pool=pool_id)
|
| replay(self) -> None
| Replay the work captured by this graph.
|
| reset(self) -> None
| Delete the graph currently held by this instance.
|
| After this call, the graph can be recaptured. Set :attr:`graph_pool` or
| :attr:`capture_error_mode` beforehand to use different settings on the next capture.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, keep_graph: bool = False, *, pool: tuple[int, int] | None = None, capture_error_mode: Literal['default', 'global', 'thread_local', 'relaxed'] = 'default') -> Self
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
class device_index(builtins.object)
| device_index(device: int | None, /) -> None
|
| Context manager to set the current device index for the current :ref:`accelerator<accelerators>`.
| Temporarily changes the current device index to the specified value for the duration
| of the context, and automatically restores the previous device index when exiting
| the context.
|
| Args:
| device (Optional[int]): a given device index to temporarily set. If None,
| no device index switching occurs.
|
| Examples:
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> # Set device 0 as the current device temporarily
| >>> with torch.accelerator.device_index(0):
| ... # Code here runs with device 0 as the current device
| ... pass
| >>> # Original device is now restored
| >>> # No-op when None is passed
| >>> with torch.accelerator.device_index(None):
| ... # No device switching occurs
| ... pass
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, *exc_info: object) -> None
|
| __init__(self, device: int | None, /) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
current_accelerator(check_available: bool = False) -> torch.device | None
Return the device of the accelerator available at compilation time.
If no accelerator were available at compilation time, returns None.
See :ref:`accelerator<accelerators>` for details.
Args:
check_available (bool, optional): if True, will also do a runtime check to see
if the device :func:`torch.accelerator.is_available` on top of the compile-time
check.
Default: ``False``
Returns:
torch.device: return the current accelerator as :class:`torch.device`.
.. note:: The index of the returned :class:`torch.device` will be ``None``, please use
:func:`torch.accelerator.current_device_index` to know the current index being used.
This API does NOT poison fork. For more details, see :ref:`multiprocessing-poison-fork-note`.
Example::
>>> # xdoctest:
>>> # If an accelerator is available, sent the model to it
>>> model = torch.nn.Linear(2, 2)
>>> if (current_device := current_accelerator(check_available=True)) is not None:
>>> model.to(current_device)
current_device_idx = current_device_index() -> int
(Deprecated) Return the index of a currently selected device for the current :ref:`accelerator<accelerators>`.
Returns:
int: the index of a currently selected device.
.. warning::
:func:`torch.accelerator.current_device_idx` is deprecated in favor of :func:`torch.accelerator.current_device_index`
and will be removed in a future PyTorch release.
current_device_index() -> int
Return the index of a currently selected device for the current :ref:`accelerator<accelerators>`.
Returns:
int: the index of a currently selected device.
current_stream(device: torch.device | str | int | None = None, /) -> torch.Stream
Return the currently selected stream for a given device.
Args:
device (:class:`torch.device`, str, int, optional): a given device that must match the current
:ref:`accelerator<accelerators>` device type. If not given,
use :func:`torch.accelerator.current_device_index` by default.
Returns:
torch.Stream: the currently selected stream for a given device.
device_count() -> int
Return the number of current :ref:`accelerator<accelerators>` available.
Returns:
int: the number of the current :ref:`accelerator<accelerators>` available.
If there is no available accelerators, return 0.
.. note:: This API delegates to the device-specific version of `device_count`.
On CUDA, this API will NOT poison fork if NVML discovery succeeds.
Otherwise, it will. For more details, see :ref:`multiprocessing-poison-fork-note`.
empty_cache() -> None
Release all unoccupied cached memory currently held by the caching
allocator so that those can be used in other application.
.. note:: This function is a no-op if the memory allocator for the current
:ref:`accelerator <accelerators>` has not been initialized.
empty_host_cache() -> None
Release all unoccupied cached host (pinned) memory currently held by the host caching
allocator so that it can be used by other applications.
.. note:: This function is a no-op if the memory allocator for the current
:ref:`accelerator <accelerators>` has not been initialized.
get_device_capability(device: torch.device | str | int | None = None, /) -> dict[str, typing.Any]
Return the capability of the currently selected device.
Args:
device (:class:`torch.device`, str, int, optional): The device to query capabilities for
:ref:`accelerator<accelerators>` device type. If not given,
use :func:`torch.accelerator.current_device_index` by default.
Returns:
dict[str, Any]: A dictionary containing device capability information. The dictionary includes:
- ``supported_dtypes`` (set(torch.dtype)): Set of PyTorch data types for which
tensors can be allocated on the accelerator and type conversion across
supported dtypes are supported. Any operator support outside of that
is not guaranteed
Examples:
>>> # xdoctest: +SKIP("requires cuda")
>>> # Query capabilities for current device
>>> capabilities = torch.accelerator.get_device_capability("cuda:0")
>>> print("Supported dtypes:", capabilities["supported_dtypes"])
get_memory_info(device_index: torch.device | str | int | None = None, /) -> tuple[int, int]
Return the current device memory information for a given device index.
Args:
device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
If not given, use :func:`torch.accelerator.current_device_index` by default.
If a :class:`torch.device` or str is provided, its type must match the current
:ref:`accelerator<accelerators>` device type.
Returns:
tuple[int, int]: a tuple of two integers (free_memory, total_memory) in bytes.
The first value is the free memory on the device (available across all processes and applications),
The second value is the device's total hardware memory capacity.
is_available() -> bool
Check if the current accelerator is available at runtime: it was built, all the
required drivers are available and at least one device is visible.
See :ref:`accelerator<accelerators>` for details.
Returns:
bool: A boolean indicating if there is an available :ref:`accelerator<accelerators>`.
.. note:: This API delegates to the device-specific version of `is_available`.
On CUDA, when the environment variable ``PYTORCH_NVML_BASED_CUDA_CHECK=1`` is set,
this function will NOT poison fork. Otherwise, it will. For more details, see
:ref:`multiprocessing-poison-fork-note`.
Example::
>>> assert torch.accelerator.is_available() "No available accelerators detected."
max_memory_allocated(device_index: torch.device | str | int | None = None, /) -> int
Return the current :ref:`accelerator<accelerators>` maximum device memory occupied by tensors
in bytes for a given device index.
By default, this returns the peak allocated memory since the beginning of
this program. :func:`~torch.accelerator.reset_peak_memory_stats` can be used to
reset the starting point in tracking this metric.
Args:
device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
If not given, use :func:`torch.accelerator.current_device_index` by default.
If a :class:`torch.device` or str is provided, its type must match the current
:ref:`accelerator<accelerators>` device type.
Returns:
int: the peak memory occupied by live tensors (in bytes) within the current process.
max_memory_reserved(device_index: torch.device | str | int | None = None, /) -> int
Return the current :ref:`accelerator<accelerators>` maximum device memory managed by the caching allocator
in bytes for a given device index.
By default, this returns the peak cached memory since the beginning of this
program. :func:`~torch.accelerator.reset_peak_memory_stats` can be used to reset
the starting point in tracking this metric.
Args:
device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
If not given, use :func:`torch.accelerator.current_device_index` by default.
If a :class:`torch.device` or str is provided, its type must match the current
:ref:`accelerator<accelerators>` device type.
Returns:
int: the peak memory reserved by PyTorch (in bytes) within the current process.
memory_allocated(device_index: torch.device | str | int | None = None, /) -> int
Return the current :ref:`accelerator<accelerators>` device memory occupied by tensors
in bytes for a given device index.
Args:
device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
If not given, use :func:`torch.accelerator.current_device_index` by default.
If a :class:`torch.device` or str is provided, its type must match the current
:ref:`accelerator<accelerators>` device type.
Returns:
int: the current memory occupied by live tensors (in bytes) within the current process.
memory_reserved(device_index: torch.device | str | int | None = None, /) -> int
Return the current :ref:`accelerator<accelerators>` device memory managed by the caching allocator
in bytes for a given device index.
Args:
device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
If not given, use :func:`torch.accelerator.current_device_index` by default.
If a :class:`torch.device` or str is provided, its type must match the current
:ref:`accelerator<accelerators>` device type.
Returns:
int: the current memory reserved by PyTorch (in bytes) within the current process.
memory_stats(device_index: torch.device | str | int | None = None, /) -> collections.OrderedDict[str, typing.Any]
Return a dictionary of accelerator device memory allocator statistics for a given device index.
The return value of this function is a dictionary of statistics, each of
which is a non-negative integer.
Core statistics:
- ``"allocated.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
number of allocation requests received by the memory allocator.
- ``"allocated_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
amount of allocated memory.
- ``"segment.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
number of reserved segments from device memory allocation.
- ``"reserved_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
amount of reserved memory.
- ``"active.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
number of active memory blocks.
- ``"active_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
amount of active memory.
- ``"inactive_split.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
number of inactive, non-releasable memory blocks.
- ``"inactive_split_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
amount of inactive, non-releasable memory.
For these core statistics, values are broken down as follows.
Pool type:
- ``all``: combined statistics across all memory pools.
- ``large_pool``: statistics for the large allocation pool
(as of June 2025, for size >= 1MB allocations).
- ``small_pool``: statistics for the small allocation pool
(as of June 2025, for size < 1MB allocations).
Metric type:
- ``current``: current value of this metric.
- ``peak``: maximum value of this metric.
- ``allocated``: historical total increase in this metric.
- ``freed``: historical total decrease in this metric.
In addition to the core statistics, we also provide some simple event
counters:
- ``"num_alloc_retries"``: number of failed device memory allocation calls that
result in a cache flush and retry.
- ``"num_ooms"``: number of out-of-memory errors thrown.
- ``"num_sync_all_streams"``: number of ``synchronize_and_free_events`` calls.
- ``"num_device_alloc"``: number of device memory allocation calls.
- ``"num_device_free"``: number of device memory free calls.
Args:
device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
If not given, use :func:`torch.accelerator.current_device_index` by default.
If a :class:`torch.device` or str is provided, its type must match the current
:ref:`accelerator<accelerators>` device type.
Returns:
OrderedDict[str, Any]: an ordered dictionary mapping statistic names to their values.
reset_accumulated_memory_stats(device_index: torch.device | str | int | None = None, /) -> None
Reset the "accumulated" (historical) stats tracked by the current :ref:`accelerator<accelerators>`
memory allocator for a given device index.
Args:
device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
If not given, use :func:`torch.accelerator.current_device_index` by default.
If a :class:`torch.device` or str is provided, its type must match the current
:ref:`accelerator<accelerators>` device type.
.. note:: This function is a no-op if the memory allocator for the current
:ref:`accelerator <accelerators>` has not been initialized.
reset_peak_memory_stats(device_index: torch.device | str | int | None = None, /) -> None
Reset the "peak" stats tracked by the current :ref:`accelerator<accelerators>`
memory allocator for a given device index.
Args:
device_index (:class:`torch.device`, str, int, optional): the index of the device to target.
If not given, use :func:`torch.accelerator.current_device_index` by default.
If a :class:`torch.device` or str is provided, its type must match the current
:ref:`accelerator<accelerators>` device type.
.. note:: This function is a no-op if the memory allocator for the current
:ref:`accelerator <accelerators>` has not been initialized.
set_device_idx = set_device_index(device: torch.device | str | int | None, /) -> None
(Deprecated) Set the current device index to a given device.
Args:
device (:class:`torch.device`, str, int): a given device that must match the current
:ref:`accelerator<accelerators>` device type.
.. warning::
:func:`torch.accelerator.set_device_idx` is deprecated in favor of :func:`torch.accelerator.set_device_index`
and will be removed in a future PyTorch release.
set_device_index(device: torch.device | str | int | None, /) -> None
Set the current device index to a given device.
Args:
device (:class:`torch.device`, str, int): a given device that must match the current
:ref:`accelerator<accelerators>` device type.
.. note:: This function is a no-op if this device index is negative.
set_stream(stream: torch.Stream) -> None
Set the current stream to a given stream.
Args:
stream (torch.Stream): a given stream that must match the current :ref:`accelerator<accelerators>` device type.
.. note:: This function will set the current device index to the device index of the given stream.
synchronize(device: torch.device | str | int | None = None, /) -> None
Wait for all kernels in all streams on the given device to complete.
Args:
device (:class:`torch.device`, str, int, optional): device for which to synchronize. It must match
the current :ref:`accelerator<accelerators>` device type. If not given,
use :func:`torch.accelerator.current_device_index` by default.
.. note:: This function is a no-op if the current :ref:`accelerator<accelerators>` is not initialized.
Example::
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
>>> assert torch.accelerator.is_available() "No available accelerators detected."
>>> start_event = torch.Event(enable_timing=True)
>>> end_event = torch.Event(enable_timing=True)
>>> start_event.record()
>>> tensor = torch.randn(100, device=torch.accelerator.current_accelerator())
>>> sum = torch.sum(tensor)
>>> end_event.record()
>>> torch.accelerator.synchronize()
>>> elapsed_time_ms = start_event.elapsed_time(end_event)
DATA
__all__ = ['Graph', 'current_accelerator', 'current_device_idx', 'curr...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\accelerator\__init__.py
torch.acos
Python Library Documentation: built-in function acos in module torch
acos(...)
acos(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the arccosine (in radians) of each element in :attr:`input`.
.. math::
\text{out}_{i} = \cos^{-1}(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.3348, -0.5889, 0.2005, -0.1584])
>>> torch.acos(a)
tensor([ 1.2294, 2.2004, 1.3690, 1.7298])
torch.acos_
Python Library Documentation: built-in function acos_ in module torch acos_(...)
torch.acosh
Python Library Documentation: built-in function acosh in module torch
acosh(...)
acosh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the inverse hyperbolic cosine of the elements of :attr:`input`.
.. math::
\text{out}_{i} = \cosh^{-1}(\text{input}_{i})
Note:
The domain of the inverse hyperbolic cosine is `[1, inf)` and values outside this range
will be mapped to ``NaN``, except for `+ INF` for which the output is mapped to `+ INF`.
Args:
input (Tensor): the input tensor.
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4).uniform_(1, 2)
>>> a
tensor([ 1.3192, 1.9915, 1.9674, 1.7151 ])
>>> torch.acosh(a)
tensor([ 0.7791, 1.3120, 1.2979, 1.1341 ])
torch.acosh_
Python Library Documentation: built-in function acosh_ in module torch acosh_(...)
torch.adaptive_avg_pool1d
Python Library Documentation: built-in function adaptive_avg_pool1d in module torch
adaptive_avg_pool1d(...)
adaptive_avg_pool1d(input, output_size) -> Tensor
Applies a 1D adaptive average pooling over an input signal composed of
several input planes.
See :class:`~torch.nn.AdaptiveAvgPool1d` for details and output shape.
Args:
output_size: the target output size (single integer)
torch.adaptive_max_pool1d
Python Library Documentation: built-in function adaptive_max_pool1d in module torch adaptive_max_pool1d(...)
torch.add
Python Library Documentation: built-in function add in module torch
add(...)
add(input, other, *, alpha=1, out=None) -> Tensor
Adds :attr:`other`, scaled by :attr:`alpha`, to :attr:`input`.
.. math::
\text{{out}}_i = \text{{input}}_i + \text{{alpha}} \times \text{{other}}_i
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
Args:
input (Tensor): the input tensor.
other (Tensor or Number): the tensor or number to add to :attr:`input`.
Keyword arguments:
alpha (Number): the multiplier for :attr:`other`.
out (Tensor, optional): the output tensor.
Examples::
>>> a = torch.randn(4)
>>> a
tensor([ 0.0202, 1.0985, 1.3506, -0.6056])
>>> torch.add(a, 20)
tensor([ 20.0202, 21.0985, 21.3506, 19.3944])
>>> b = torch.randn(4)
>>> b
tensor([-0.9732, -0.3497, 0.6245, 0.4022])
>>> c = torch.randn(4, 1)
>>> c
tensor([[ 0.3743],
[-1.7724],
[-0.5811],
[-0.8017]])
>>> torch.add(b, c, alpha=10)
tensor([[ 2.7695, 3.3930, 4.3672, 4.1450],
[-18.6971, -18.0736, -17.0994, -17.3216],
[ -6.7845, -6.1610, -5.1868, -5.4090],
[ -8.9902, -8.3667, -7.3925, -7.6147]])
torch.addbmm
Python Library Documentation: built-in function addbmm in module torch
addbmm(...)
addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
Performs a batch matrix-matrix product of matrices stored
in :attr:`batch1` and :attr:`batch2`,
with a reduced add step (all matrix multiplications get accumulated
along the first dimension).
:attr:`input` is added to the final result.
:attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
same number of matrices.
If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
:math:`(b \times m \times p)` tensor, :attr:`input` must be
:ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
and :attr:`out` will be a :math:`(n \times p)` tensor.
.. math::
out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
it will not be propagated.
For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
must be real numbers, otherwise they should be integers.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
Args:
input (Tensor): matrix to be added
batch1 (Tensor): the first batch of matrices to be multiplied
batch2 (Tensor): the second batch of matrices to be multiplied
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
Example::
>>> M = torch.randn(3, 5)
>>> batch1 = torch.randn(10, 3, 4)
>>> batch2 = torch.randn(10, 4, 5)
>>> torch.addbmm(M, batch1, batch2)
tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
[ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
[ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
torch.addcdiv
Python Library Documentation: built-in function addcdiv in module torch
addcdiv(...)
addcdiv(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
Performs the element-wise division of :attr:`tensor1` by :attr:`tensor2`,
multiplies the result by the scalar :attr:`value` and adds it to :attr:`input`.
.. warning::
Integer division with addcdiv is no longer supported, and in a future
release addcdiv will perform a true division of tensor1 and tensor2.
The historic addcdiv behavior can be implemented as
(input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype)
for integer inputs and as (input + value * tensor1 / tensor2) for float inputs.
The future addcdiv behavior is just the latter implementation:
(input + value * tensor1 / tensor2), for all dtypes.
.. math::
\text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}
The shapes of :attr:`input`, :attr:`tensor1`, and :attr:`tensor2` must be
:ref:`broadcastable <broadcasting-semantics>`.
For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
a real number, otherwise an integer.
Args:
input (Tensor): the tensor to be added
tensor1 (Tensor): the numerator tensor
tensor2 (Tensor): the denominator tensor
Keyword args:
value (Number, optional): multiplier for :math:`\text{tensor1} / \text{tensor2}`
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.randn(1, 3)
>>> t1 = torch.randn(3, 1)
>>> t2 = torch.randn(1, 3)
>>> torch.addcdiv(t, t1, t2, value=0.1)
tensor([[-0.2312, -3.6496, 0.1312],
[-1.0428, 3.4292, -0.1030],
[-0.5369, -0.9829, 0.0430]])
torch.addcmul
Python Library Documentation: built-in function addcmul in module torch
addcmul(...)
addcmul(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
Performs the element-wise multiplication of :attr:`tensor1`
by :attr:`tensor2`, multiplies the result by the scalar :attr:`value`
and adds it to :attr:`input`.
.. math::
\text{out}_i = \text{input}_i + \text{value} \times \text{tensor1}_i \times \text{tensor2}_i
The shapes of :attr:`tensor`, :attr:`tensor1`, and :attr:`tensor2` must be
:ref:`broadcastable <broadcasting-semantics>`.
For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
a real number, otherwise an integer.
Args:
input (Tensor): the tensor to be added
tensor1 (Tensor): the tensor to be multiplied
tensor2 (Tensor): the tensor to be multiplied
Keyword args:
value (Number, optional): multiplier for :math:`tensor1 .* tensor2`
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.randn(1, 3)
>>> t1 = torch.randn(3, 1)
>>> t2 = torch.randn(1, 3)
>>> torch.addcmul(t, t1, t2, value=0.1)
tensor([[-0.8635, -0.6391, 1.6174],
[-0.7617, -0.5879, 1.7388],
[-0.8353, -0.6249, 1.6511]])
torch.addmm
Python Library Documentation: built-in function addmm in module torch
addmm(...)
addmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
The matrix :attr:`input` is added to the final result.
If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
:math:`(m \times p)` tensor, then :attr:`input` must be
:ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
and :attr:`out` will be a :math:`(n \times p)` tensor.
:attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
:attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
.. math::
\text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
it will not be propagated.
For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
:attr:`alpha` must be real numbers, otherwise they should be integers.
This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
:attr:`input` is sparse the result will have the same layout and if :attr:`out`
is provided it must have the same layout as :attr:`input`.
.. warning::
Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
or may not have autograd support. If you notice missing functionality please
open a feature request.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
Args:
input (Tensor): matrix to be added
mat1 (Tensor): the first matrix to be matrix multiplied
mat2 (Tensor): the second matrix to be matrix multiplied
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
Example::
>>> M = torch.randn(2, 3)
>>> mat1 = torch.randn(2, 3)
>>> mat2 = torch.randn(3, 3)
>>> torch.addmm(M, mat1, mat2)
tensor([[-4.8716, 1.4671, -1.3746],
[ 0.7573, -3.9555, -2.8681]])
.. function:: addmm(input, mat1, mat2, out_dtype, *, beta=1, alpha=1, out=None) -> Tensor
:noindex:
Args:
input (Tensor): matrix to be added
mat1 (Tensor): the first matrix to be matrix multiplied
mat2 (Tensor): the second matrix to be matrix multiplied
out_dtype (dtype): the dtype of the output tensor.
Supported only on CUDA and for torch.float32 given
torch.float16/torch.bfloat16 input dtypes.
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
torch.addmv
Python Library Documentation: built-in function addmv in module torch
addmv(...)
addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
Performs a matrix-vector product of the matrix :attr:`mat` and
the vector :attr:`vec`.
The vector :attr:`input` is added to the final result.
If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
size `m`, then :attr:`input` must be
:ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
:attr:`out` will be 1-D tensor of size `n`.
:attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
:attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
.. math::
\text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
it will not be propagated.
For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
:attr:`alpha` must be real numbers, otherwise they should be integers.
Args:
input (Tensor): vector to be added
mat (Tensor): matrix to be matrix multiplied
vec (Tensor): vector to be matrix multiplied
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
Example::
>>> M = torch.randn(2)
>>> mat = torch.randn(2, 3)
>>> vec = torch.randn(3)
>>> torch.addmv(M, mat, vec)
tensor([-0.3768, -5.5565])
torch.addmv_
Python Library Documentation: built-in function addmv_ in module torch addmv_(...)
torch.addr
Python Library Documentation: built-in function addr in module torch
addr(...)
addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
and adds it to the matrix :attr:`input`.
Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
:attr:`input` respectively.
.. math::
\text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
it will not be propagated.
If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
of size `m`, then :attr:`input` must be
:ref:`broadcastable <broadcasting-semantics>` with a matrix of size
:math:`(n \times m)` and :attr:`out` will be a matrix of size
:math:`(n \times m)`.
Args:
input (Tensor): matrix to be added
vec1 (Tensor): the first vector of the outer product
vec2 (Tensor): the second vector of the outer product
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
Example::
>>> vec1 = torch.arange(1., 4.)
>>> vec2 = torch.arange(1., 3.)
>>> M = torch.zeros(3, 2)
>>> torch.addr(M, vec1, vec2)
tensor([[ 1., 2.],
[ 2., 4.],
[ 3., 6.]])
torch.adjoint
Python Library Documentation: built-in function adjoint in module torch
adjoint(...)
adjoint(input: Tensor) -> Tensor
Returns a view of the tensor conjugated and with the last two dimensions transposed.
``x.adjoint()`` is equivalent to ``x.transpose(-2, -1).conj()`` for complex tensors and
to ``x.transpose(-2, -1)`` for real tensors.
Args:
{input}
Example::
>>> x = torch.arange(4, dtype=torch.float)
>>> A = torch.complex(x, x).reshape(2, 2)
>>> A
tensor([[0.+0.j, 1.+1.j],
[2.+2.j, 3.+3.j]])
>>> A.adjoint()
tensor([[0.-0.j, 2.-2.j],
[1.-1.j, 3.-3.j]])
>>> (A.adjoint() == A.mH).all()
tensor(True)
torch.affine_grid_generator
Python Library Documentation: built-in function affine_grid_generator in module torch affine_grid_generator(...)
torch.alias_copy
Python Library Documentation: built-in function alias_copy in module torch
alias_copy(...)
Performs the same operation as :func:`torch.alias`, but all output tensors
are freshly created instead of aliasing the input.
torch.all
Python Library Documentation: built-in function all in module torch
all(...)
all(input: Tensor, *, out=None) -> Tensor
Tests if all elements in :attr:`input` evaluate to `True`.
.. note:: This function matches the behaviour of NumPy in returning
output of dtype `bool` for all supported dtypes except `uint8`.
For `uint8` the dtype of output is `uint8` itself.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(1, 2).bool()
>>> a
tensor([[False, True]], dtype=torch.bool)
>>> torch.all(a)
tensor(False, dtype=torch.bool)
>>> a = torch.arange(0, 3)
>>> a
tensor([0, 1, 2])
>>> torch.all(a)
tensor(False)
.. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
:noindex:
For each row of :attr:`input` in the given dimension :attr:`dim`,
returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(4, 2).bool()
>>> a
tensor([[True, True],
[True, False],
[True, True],
[True, True]], dtype=torch.bool)
>>> torch.all(a, dim=1)
tensor([ True, False, True, True], dtype=torch.bool)
>>> torch.all(a, dim=0)
tensor([ True, False], dtype=torch.bool)
torch.allclose
Python Library Documentation: built-in function allclose in module torch
allclose(...)
allclose(input: Tensor, other: Tensor, rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False) -> bool
This function checks if :attr:`input` and :attr:`other` satisfy the condition:
.. math::
\lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other}_i \rvert
elementwise, for all elements of :attr:`input` and :attr:`other`. The behaviour of this function is analogous to
`numpy.allclose <https://numpy.org/doc/stable/reference/generated/numpy.allclose.html>`_
Args:
input (Tensor): first tensor to compare
other (Tensor): second tensor to compare
atol (float, optional): absolute tolerance. Default: 1e-08
rtol (float, optional): relative tolerance. Default: 1e-05
equal_nan (bool, optional): if ``True``, then two ``NaN`` s will be considered equal. Default: ``False``
Example::
>>> torch.allclose(torch.tensor([10000., 1e-07]), torch.tensor([10000.1, 1e-08]))
False
>>> torch.allclose(torch.tensor([10000., 1e-08]), torch.tensor([10000.1, 1e-09]))
True
>>> torch.allclose(torch.tensor([1.0, float('nan')]), torch.tensor([1.0, float('nan')]))
False
>>> torch.allclose(torch.tensor([1.0, float('nan')]), torch.tensor([1.0, float('nan')]), equal_nan=True)
True
torch.alpha_dropout
Python Library Documentation: built-in function alpha_dropout in module torch alpha_dropout(...)
torch.alpha_dropout_
Python Library Documentation: built-in function alpha_dropout_ in module torch alpha_dropout_(...)
torch.amax
Python Library Documentation: built-in function amax in module torch
amax(...)
amax(input, dim=None, keepdim=False, *, out=None) -> Tensor
Returns the maximum value of each slice of the :attr:`input` tensor in the given
dimension(s) :attr:`dim`.
.. note::
The difference between ``max``/``min`` and ``amax``/``amin`` is:
- ``amax``/``amin`` supports reducing on multiple dimensions,
- ``amax``/``amin`` does not return indices.
Both ``amax``/``amin`` evenly distribute gradients between equal values
when there are multiple input elements with the same minimum or maximum value.
For ``max``/``min``:
- If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
- If reduce over one specified axis, only propagate to the indexed element.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.8177, 1.4878, -0.2491, 0.9130],
[-0.7158, 1.1775, 2.0992, 0.4817],
[-0.0053, 0.0164, -1.3738, -0.0507],
[ 1.9700, 1.1106, -1.0318, -1.0816]])
>>> torch.amax(a, 1)
tensor([1.4878, 2.0992, 0.0164, 1.9700])
torch.amin
Python Library Documentation: built-in function amin in module torch
amin(...)
amin(input, dim=None, keepdim=False, *, out=None) -> Tensor
Returns the minimum value of each slice of the :attr:`input` tensor in the given
dimension(s) :attr:`dim`.
.. note::
The difference between ``max``/``min`` and ``amax``/``amin`` is:
- ``amax``/``amin`` supports reducing on multiple dimensions,
- ``amax``/``amin`` does not return indices.
Both ``amax``/``amin`` evenly distribute gradients between equal values
when there are multiple input elements with the same minimum or maximum value.
For ``max``/``min``:
- If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
- If reduce over one specified axis, only propagate to the indexed element.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.6451, -0.4866, 0.2987, -1.3312],
[-0.5744, 1.2980, 1.8397, -0.2713],
[ 0.9128, 0.9214, -1.7268, -0.2995],
[ 0.9023, 0.4853, 0.9075, -1.6165]])
>>> torch.amin(a, 1)
tensor([-1.3312, -0.5744, -1.7268, -1.6165])
torch.aminmax
Python Library Documentation: built-in function aminmax in module torch
aminmax(...)
aminmax(input, *, dim=None, keepdim=False, out=None) -> (Tensor min, Tensor max)
Computes the minimum and maximum values of the :attr:`input` tensor.
Args:
input (Tensor):
The input tensor
Keyword Args:
dim (Optional[int]):
The dimension along which to compute the values. If `None`,
computes the values over the entire :attr:`input` tensor.
Default is `None`.
keepdim (bool):
If `True`, the reduced dimensions will be kept in the output
tensor as dimensions with size 1 for broadcasting, otherwise
they will be removed, as if calling (:func:`torch.squeeze`).
Default is `False`.
out (Optional[Tuple[Tensor, Tensor]]):
Optional tensors on which to write the result. Must have the same
shape and dtype as the expected output.
Default is `None`.
Returns:
A named tuple `(min, max)` containing the minimum and maximum values.
Raises:
RuntimeError
If any of the dimensions to compute the values over has size 0.
.. note::
NaN values are propagated to the output if at least one value is NaN.
.. seealso::
:func:`torch.amin` computes just the minimum value
:func:`torch.amax` computes just the maximum value
Example::
>>> torch.aminmax(torch.tensor([1, -3, 5]))
torch.return_types.aminmax(
min=tensor(-3),
max=tensor(5))
>>> # aminmax propagates NaNs
>>> torch.aminmax(torch.tensor([1, -3, 5, torch.nan]))
torch.return_types.aminmax(
min=tensor(nan),
max=tensor(nan))
>>> t = torch.arange(10).view(2, 5)
>>> t
tensor([[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9]])
>>> t.aminmax(dim=0, keepdim=True)
torch.return_types.aminmax(
min=tensor([[0, 1, 2, 3, 4]]),
max=tensor([[5, 6, 7, 8, 9]]))
torch.amp
Python Library Documentation: package torch.amp in torch
NAME
torch.amp
PACKAGE CONTENTS
autocast_mode
grad_scaler
CLASSES
builtins.object
torch.amp.autocast_mode.autocast
torch.amp.grad_scaler.GradScaler
class GradScaler(builtins.object)
| GradScaler(device: 'str' = 'cuda', init_scale: 'float' = 65536.0, growth_factor: 'float' = 2.0, backoff_factor: 'float' = 0.5, growth_interval: 'int' = 2000, enabled: 'bool' = True) -> 'None'
|
| An instance ``scaler`` of :class:`GradScaler`.
|
| Helps perform the steps of gradient scaling
| conveniently.
|
| * ``scaler.scale(loss)`` multiplies a given loss by ``scaler``'s current scale factor.
| * ``scaler.step(optimizer)`` safely unscales gradients and calls ``optimizer.step()``.
| * ``scaler.update()`` updates ``scaler``'s scale factor.
|
| Example::
|
| # Creates a GradScaler once at the beginning of training.
| scaler = GradScaler()
|
| for epoch in epochs:
| for input, target in data:
| optimizer.zero_grad()
| output = model(input)
| loss = loss_fn(output, target)
|
| # Scales loss. Calls backward() on scaled loss to create scaled gradients.
| scaler.scale(loss).backward()
|
| # scaler.step() first unscales gradients of the optimizer's params.
| # If gradients don't contain infs/NaNs, optimizer.step() is then called,
| # otherwise, optimizer.step() is skipped.
| scaler.step(optimizer)
|
| # Updates the scale for next iteration.
| scaler.update()
|
| See the :ref:`Automatic Mixed Precision examples<amp-examples>` for usage
| (along with autocasting) in more complex cases like gradient clipping, gradient accumulation, gradient penalty,
| and multiple losses/optimizers.
|
| ``scaler`` dynamically estimates the scale factor each iteration. To minimize gradient underflow,
| a large scale factor should be used. However, ``float16`` values can "overflow" (become inf or NaN) if
| the scale factor is too large. Therefore, the optimal scale factor is the largest factor that can be used
| without incurring inf or NaN gradient values.
| ``scaler`` approximates the optimal scale factor over time by checking the gradients for infs and NaNs during every
| ``scaler.step(optimizer)`` (or optional separate ``scaler.unscale_(optimizer)``, see :meth:`unscale_`).
|
| * If infs/NaNs are found, ``scaler.step(optimizer)`` skips the underlying ``optimizer.step()`` (so the params
| themselves remain uncorrupted) and ``update()`` multiplies the scale by ``backoff_factor``.
|
| * If no infs/NaNs are found, ``scaler.step(optimizer)`` runs the underlying ``optimizer.step()`` as usual.
| If ``growth_interval`` unskipped iterations occur consecutively, ``update()`` multiplies the scale by
| ``growth_factor``.
|
| The scale factor often causes infs/NaNs to appear in gradients for the first few iterations as its
| value calibrates. ``scaler.step`` will skip the underlying ``optimizer.step()`` for these
| iterations. After that, step skipping should occur rarely (once every few hundred or thousand iterations).
|
| Args:
| device (str, optional, default="cuda"): Device type to use. Possible values are: 'cuda' and 'cpu'.
| The type is the same as the `type` attribute of a :class:`torch.device`.
| Thus, you may obtain the device type of a tensor using `Tensor.device.type`.
| init_scale (float, optional, default=2.**16): Initial scale factor.
| growth_factor (float, optional, default=2.0): Factor by which the scale is multiplied during
| :meth:`update` if no inf/NaN gradients occur for ``growth_interval`` consecutive iterations.
| backoff_factor (float, optional, default=0.5): Factor by which the scale is multiplied during
| :meth:`update` if inf/NaN gradients occur in an iteration.
| growth_interval (int, optional, default=2000): Number of consecutive iterations without inf/NaN gradients
| that must occur for the scale to be multiplied by ``growth_factor``.
| enabled (bool, optional): If ``False``, disables gradient scaling. :meth:`step` simply
| invokes the underlying ``optimizer.step()``, and other methods become no-ops.
| Default: ``True``
|
| Methods defined here:
|
| __getstate__(self) -> 'dict[str, Any]'
| Helper for pickle.
|
| __init__(self, device: 'str' = 'cuda', init_scale: 'float' = 65536.0, growth_factor: 'float' = 2.0, backoff_factor: 'float' = 0.5, growth_interval: 'int' = 2000, enabled: 'bool' = True) -> 'None'
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state: 'dict[str, Any]') -> 'None'
|
| get_backoff_factor(self) -> 'float'
| Return a Python float containing the scale backoff factor.
|
| get_growth_factor(self) -> 'float'
| Return a Python float containing the scale growth factor.
|
| get_growth_interval(self) -> 'int'
| Return a Python int containing the growth interval.
|
| get_scale(self) -> 'float'
| Return a Python float containing the current scale, or 1.0 if scaling is disabled.
|
| .. warning::
| :meth:`get_scale` incurs a CPU-GPU sync.
|
| is_enabled(self) -> 'bool'
| Return a bool indicating whether this instance is enabled.
|
| load_state_dict(self, state_dict: 'dict[str, Any]') -> 'None'
| Load the scaler state.
|
| If this instance is disabled, :meth:`load_state_dict` is a no-op.
|
| Args:
| state_dict(dict): scaler state. Should be an object returned from a call to :meth:`state_dict`.
|
| scale(self, outputs: 'torch.Tensor | Iterable[torch.Tensor]') -> 'torch.Tensor | Iterable[torch.Tensor]'
| Multiplies ('scales') a tensor or list of tensors by the scale factor.
|
| Returns scaled outputs. If this instance of :class:`GradScaler` is not enabled, outputs are returned
| unmodified.
|
| Args:
| outputs (Tensor or iterable of Tensors): Outputs to scale.
|
| set_backoff_factor(self, new_factor: 'float') -> 'None'
| Set a new scale backoff factor.
|
| Args:
| new_scale (float): Value to use as the new scale backoff factor.
|
| set_growth_factor(self, new_factor: 'float') -> 'None'
| Set a new scale growth factor.
|
| Args:
| new_scale (float): Value to use as the new scale growth factor.
|
| set_growth_interval(self, new_interval: 'int') -> 'None'
| Set a new growth interval.
|
| Args:
| new_interval (int): Value to use as the new growth interval.
|
| state_dict(self) -> 'dict[str, Any]'
| Return the state of the scaler as a :class:`dict`.
|
| It contains five entries:
|
| * ``"scale"`` - a Python float containing the current scale
| * ``"growth_factor"`` - a Python float containing the current growth factor
| * ``"backoff_factor"`` - a Python float containing the current backoff factor
| * ``"growth_interval"`` - a Python int containing the current growth interval
| * ``"_growth_tracker"`` - a Python int containing the number of recent consecutive unskipped steps.
|
| If this instance is not enabled, returns an empty dict.
|
| .. note::
| If you wish to checkpoint the scaler's state after a particular iteration, :meth:`state_dict`
| should be called after :meth:`update`.
|
| step(self, optimizer: 'torch.optim.Optimizer', *args: 'Any', **kwargs: 'Any') -> 'float | None'
| Invoke ``unscale_(optimizer)`` followed by parameter update, if gradients are not infs/NaN.
|
| :meth:`step` carries out the following two operations:
|
| 1. Internally invokes ``unscale_(optimizer)`` (unless :meth:`unscale_` was explicitly called for ``optimizer``
| earlier in the iteration). As part of the :meth:`unscale_`, gradients are checked for infs/NaNs.
| 2. If no inf/NaN gradients are found, invokes ``optimizer.step()`` using the unscaled
| gradients. Otherwise, ``optimizer.step()`` is skipped to avoid corrupting the params.
|
| ``*args`` and ``**kwargs`` are forwarded to ``optimizer.step()``.
|
| Returns the return value of ``optimizer.step(*args, **kwargs)``.
|
| Args:
| optimizer (torch.optim.Optimizer): Optimizer that applies the gradients.
| args: Any arguments.
| kwargs: Any keyword arguments.
|
| .. warning::
| Closure use is not currently supported.
|
| unscale_(self, optimizer: 'torch.optim.Optimizer') -> 'None'
| Divides ("unscales") the optimizer's gradient tensors by the scale factor.
|
| :meth:`unscale_` is optional, serving cases where you need to
| :ref:`modify or inspect gradients<working-with-unscaled-gradients>`
| between the backward pass(es) and :meth:`step`.
| If :meth:`unscale_` is not called explicitly, gradients will be unscaled automatically during :meth:`step`.
|
| Simple example, using :meth:`unscale_` to enable clipping of unscaled gradients::
|
| ...
| scaler.scale(loss).backward()
| scaler.unscale_(optimizer)
| torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm)
| scaler.step(optimizer)
| scaler.update()
|
| Args:
| optimizer (torch.optim.Optimizer): Optimizer that owns the gradients to be unscaled.
|
| .. note::
| :meth:`unscale_` does not incur a CPU-GPU sync.
|
| .. warning::
| :meth:`unscale_` should only be called once per optimizer per :meth:`step` call,
| and only after all gradients for that optimizer's assigned parameters have been accumulated.
| Calling :meth:`unscale_` twice for a given optimizer between each :meth:`step` triggers a RuntimeError.
|
| .. warning::
| :meth:`unscale_` may unscale sparse gradients out of place, replacing the ``.grad`` attribute.
|
| update(self, new_scale: 'float | torch.Tensor | None' = None) -> 'None'
| Update the scale factor.
|
| If any optimizer steps were skipped the scale is multiplied by ``backoff_factor``
| to reduce it. If ``growth_interval`` unskipped iterations occurred consecutively,
| the scale is multiplied by ``growth_factor`` to increase it.
|
| Passing ``new_scale`` sets the new scale value manually. (``new_scale`` is not
| used directly, it's used to fill GradScaler's internal scale tensor. So if
| ``new_scale`` was a tensor, later in-place changes to that tensor will not further
| affect the scale GradScaler uses internally.)
|
| Args:
| new_scale (float or :class:`torch.Tensor`, optional, default=None): New scale factor.
|
| .. warning::
| :meth:`update` should only be called at the end of the iteration, after ``scaler.step(optimizer)`` has
| been invoked for all optimizers used this iteration.
|
| .. warning::
| For performance reasons, we do not check the scale factor value to avoid synchronizations,
| so the scale factor is not guaranteed to be above 1. If the scale falls below 1 and/or
| you are seeing NaNs in your gradients or loss, something is likely wrong. For example,
| bf16-pretrained models are often incompatible with AMP/fp16 due to differing dynamic ranges.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class autocast(builtins.object)
| autocast(device_type: str, dtype: torch.dtype | None = None, enabled: bool = True, cache_enabled: bool | None = None)
|
| Instances of :class:`autocast` serve as context managers or decorators that
| allow regions of your script to run in mixed precision.
|
| In these regions, ops run in an op-specific dtype chosen by autocast
| to improve performance while maintaining accuracy.
| See the :ref:`Autocast Op Reference<autocast-op-reference>` for details.
|
| When entering an autocast-enabled region, Tensors may be any type.
| You should not call ``half()`` or ``bfloat16()`` on your model(s) or inputs when using autocasting.
|
| :class:`autocast` should wrap only the forward pass(es) of your network, including the loss
| computation(s). Backward passes under autocast are not recommended.
| Backward ops run in the same type that autocast used for corresponding forward ops.
|
| Example for CUDA Devices::
|
| # Creates model and optimizer in default precision
| model = Net().cuda()
| optimizer = optim.SGD(model.parameters(), ...)
|
| for input, target in data:
| optimizer.zero_grad()
|
| # Enables autocasting for the forward pass (model + loss)
| with torch.autocast(device_type="cuda"):
| output = model(input)
| loss = loss_fn(output, target)
|
| # Exits the context manager before backward()
| loss.backward()
| optimizer.step()
|
| See the :ref:`Automatic Mixed Precision examples<amp-examples>` for usage (along with gradient scaling)
| in more complex scenarios (e.g., gradient penalty, multiple models/losses, custom autograd functions).
|
| :class:`autocast` can also be used as a decorator, e.g., on the ``forward`` method of your model::
|
| class AutocastModel(nn.Module):
| ...
|
| @torch.autocast(device_type="cuda")
| def forward(self, input): ...
|
| Floating-point Tensors produced in an autocast-enabled region may be ``float16``.
| After returning to an autocast-disabled region, using them with floating-point
| Tensors of different dtypes may cause type mismatch errors. If so, cast the Tensor(s)
| produced in the autocast region back to ``float32`` (or other dtype if desired).
| If a Tensor from the autocast region is already ``float32``, the cast is a no-op,
| and incurs no additional overhead.
| CUDA Example::
|
| # Creates some tensors in default dtype (here assumed to be float32)
| a_float32 = torch.rand((8, 8), device="cuda")
| b_float32 = torch.rand((8, 8), device="cuda")
| c_float32 = torch.rand((8, 8), device="cuda")
| d_float32 = torch.rand((8, 8), device="cuda")
|
| with torch.autocast(device_type="cuda"):
| # torch.mm is on autocast's list of ops that should run in float16.
| # Inputs are float32, but the op runs in float16 and produces float16 output.
| # No manual casts are required.
| e_float16 = torch.mm(a_float32, b_float32)
| # Also handles mixed input types
| f_float16 = torch.mm(d_float32, e_float16)
|
| # After exiting autocast, calls f_float16.float() to use with d_float32
| g_float32 = torch.mm(d_float32, f_float16.float())
|
| CPU Training Example::
|
| # Creates model and optimizer in default precision
| model = Net()
| optimizer = optim.SGD(model.parameters(), ...)
|
| for epoch in epochs:
| for input, target in data:
| optimizer.zero_grad()
|
| # Runs the forward pass with autocasting.
| with torch.autocast(device_type="cpu", dtype=torch.bfloat16):
| output = model(input)
| loss = loss_fn(output, target)
|
| loss.backward()
| optimizer.step()
|
|
| CPU Inference Example::
|
| # Creates model in default precision
| model = Net().eval()
|
| with torch.autocast(device_type="cpu", dtype=torch.bfloat16):
| for input in data:
| # Runs the forward pass with autocasting.
| output = model(input)
|
| CPU Inference Example with Jit Trace::
|
| class TestModel(nn.Module):
| def __init__(self, input_size, num_classes):
| super().__init__()
| self.fc1 = nn.Linear(input_size, num_classes)
|
| def forward(self, x):
| return self.fc1(x)
|
|
| input_size = 2
| num_classes = 2
| model = TestModel(input_size, num_classes).eval()
|
| # For now, we suggest to disable the Jit Autocast Pass,
| # As the issue: https://github.com/pytorch/pytorch/issues/75956
| torch._C._jit_set_autocast_mode(False)
|
| with torch.cpu.amp.autocast(cache_enabled=False):
| model = torch.jit.trace(model, torch.randn(1, input_size))
| model = torch.jit.freeze(model)
| # Models Run
| for _ in range(3):
| model(torch.randn(1, input_size))
|
| Type mismatch errors *in* an autocast-enabled region are a bug; if this is what you observe,
| please file an issue.
|
| ``autocast(enabled=False)`` subregions can be nested in autocast-enabled regions.
| Locally disabling autocast can be useful, for example, if you want to force a subregion
| to run in a particular ``dtype``. Disabling autocast gives you explicit control over
| the execution type. In the subregion, inputs from the surrounding region
| should be cast to ``dtype`` before use::
|
| # Creates some tensors in default dtype (here assumed to be float32)
| a_float32 = torch.rand((8, 8), device="cuda")
| b_float32 = torch.rand((8, 8), device="cuda")
| c_float32 = torch.rand((8, 8), device="cuda")
| d_float32 = torch.rand((8, 8), device="cuda")
|
| with torch.autocast(device_type="cuda"):
| e_float16 = torch.mm(a_float32, b_float32)
| with torch.autocast(device_type="cuda", enabled=False):
| # Calls e_float16.float() to ensure float32 execution
| # (necessary because e_float16 was created in an autocasted region)
| f_float32 = torch.mm(c_float32, e_float16.float())
|
| # No manual casts are required when re-entering the autocast-enabled region.
| # torch.mm again runs in float16 and produces float16 output, regardless of input types.
| g_float16 = torch.mm(d_float32, f_float32)
|
| The autocast state is thread-local. If you want it enabled in a new thread, the context manager or decorator
| must be invoked in that thread. This affects :class:`torch.nn.DataParallel` and
| :class:`torch.nn.parallel.DistributedDataParallel` when used with more than one GPU per process
| (see :ref:`Working with Multiple GPUs<amp-multigpu>`).
|
| Args:
| device_type(str, required): Device type to use. Possible values are: 'cuda', 'cpu', 'mtia', 'maia', 'xpu', and 'hpu'.
| The type is the same as the `type` attribute of a :class:`torch.device`.
| Thus, you may obtain the device type of a tensor using `Tensor.device.type`.
| enabled(bool, optional): Whether autocasting should be enabled in the region.
| Default: ``True``
| dtype(torch_dtype, optional): Data type for ops run in autocast. It uses the default value
| (``torch.float16`` for CUDA and ``torch.bfloat16`` for CPU), given by
| :func:`~torch.get_autocast_dtype`, if :attr:`dtype` is ``None``.
| Default: ``None``
| cache_enabled(bool, optional): Whether the weight cache inside autocast should be enabled.
| Default: ``True``
|
| Methods defined here:
|
| __call__(self, func)
| Call self as a function.
|
| __enter__(self)
|
| __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any)
|
| __init__(self, device_type: str, dtype: torch.dtype | None = None, enabled: bool = True, cache_enabled: bool | None = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
custom_bwd(bwd=None, *, device_type: str)
Create a helper decorator for backward methods of custom autograd functions.
Autograd functions are subclasses of :class:`torch.autograd.Function`.
Ensures that ``backward`` executes with the same autocast state as ``forward``.
See the :ref:`example page<amp-custom-examples>` for more detail.
Args:
device_type(str): Device type to use. 'cuda', 'cpu', 'mtia', 'maia', 'xpu' and so on.
The type is the same as the `type` attribute of a :class:`torch.device`.
Thus, you may obtain the device type of a tensor using `Tensor.device.type`.
custom_fwd(fwd=None, *, device_type: str, cast_inputs: torch.dtype | None = None)
Create a helper decorator for ``forward`` methods of custom autograd functions.
Autograd functions are subclasses of :class:`torch.autograd.Function`.
See the :ref:`example page<amp-custom-examples>` for more detail.
Args:
device_type(str): Device type to use. 'cuda', 'cpu', 'mtia', 'maia', 'xpu' and so on.
The type is the same as the `type` attribute of a :class:`torch.device`.
Thus, you may obtain the device type of a tensor using `Tensor.device.type`.
cast_inputs (:class:`torch.dtype` or None, optional, default=None): If not ``None``,
when ``forward`` runs in an autocast-enabled region, casts incoming
floating-point Tensors to the target dtype (non-floating-point Tensors are not affected),
then executes ``forward`` with autocast disabled.
If ``None``, ``forward``'s internal ops execute with the current autocast state.
.. note::
If the decorated ``forward`` is called outside an autocast-enabled region,
:func:`custom_fwd<custom_fwd>` is a no-op and ``cast_inputs`` has no effect.
is_autocast_available(device_type: str) -> bool
Return a bool indicating if autocast is available on :attr:`device_type`.
Args:
device_type(str): Device type to use. Possible values are: 'cuda', 'cpu', 'mtia', 'maia', 'xpu', and so on.
The type is the same as the `type` attribute of a :class:`torch.device`.
Thus, you may obtain the device type of a tensor using `Tensor.device.type`.
DATA
__all__ = ['autocast', 'custom_bwd', 'custom_fwd', 'is_autocast_availa...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\amp\__init__.py
torch.angle
Python Library Documentation: built-in function angle in module torch
angle(...)
angle(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Computes the element-wise angle (in radians) of the given :attr:`input` tensor.
.. math::
\text{out}_{i} = angle(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
.. note:: Starting in PyTorch 1.8, angle returns pi for negative real numbers,
zero for non-negative real numbers, and propagates NaNs. Previously
the function would return zero for all real numbers and not propagate
floating-point NaNs.
Example::
>>> torch.angle(torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))*180/3.14159
tensor([ 135., 135, -45])
torch.any
Python Library Documentation: built-in function any in module torch
any(...)
any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Tests if any element in :attr:`input` evaluates to `True`.
.. note:: This function matches the behaviour of NumPy in returning
output of dtype `bool` for all supported dtypes except `uint8`.
For `uint8` the dtype of output is `uint8` itself.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(1, 2).bool()
>>> a
tensor([[False, True]], dtype=torch.bool)
>>> torch.any(a)
tensor(True, dtype=torch.bool)
>>> a = torch.arange(0, 3)
>>> a
tensor([0, 1, 2])
>>> torch.any(a)
tensor(True)
.. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
:noindex:
For each row of :attr:`input` in the given dimension :attr:`dim`,
returns `True` if any element in the row evaluate to `True` and `False` otherwise.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4, 2) < 0
>>> a
tensor([[ True, True],
[False, True],
[ True, True],
[False, False]])
>>> torch.any(a, 1)
tensor([ True, True, True, False])
>>> torch.any(a, 0)
tensor([True, True])
torch.ao
Python Library Documentation: package torch.ao in torch
NAME
torch.ao
DESCRIPTION
# torch.ao is a package with a lot of interdependencies.
# We will use lazy import to avoid cyclic dependencies here.
PACKAGE CONTENTS
nn (package)
ns (package)
pruning (package)
quantization (package)
FUNCTIONS
__getattr__(name: str) -> 'ModuleType'
DATA
__all__ = ['nn', 'ns', 'pruning', 'quantization']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\ao\__init__.py
torch.arange
Python Library Documentation: built-in function arange in module torch
arange(...)
arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
with values from the interval ``[start, end)`` taken with common difference
:attr:`step` beginning from `start`.
Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
the results may be affected by floating-point rounding behavior. Some values in the sequence
might not be exactly representable in certain floating-point formats, which can lead to
repeated values or unexpected rounding. For precise sequences, it is recommended to use
integer dtypes instead of floating-point dtypes.
Note that non-integer :attr:`step` is subject to floating point rounding errors when
comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
in such cases.
.. math::
\text{out}_{{i+1}} = \text{out}_{i} + \text{step}
Args:
start (Number, optional): the starting value for the set of points. Default: ``0``.
end (Number): the ending value for the set of points
step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
Keyword args:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). If `dtype` is not given, infer the data type from the other input
arguments. If any of `start`, `end`, or `stop` are floating-point, the
`dtype` is inferred to be the default dtype, see
:meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
be `torch.int64`.
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.arange(5)
tensor([ 0, 1, 2, 3, 4])
>>> torch.arange(1, 4)
tensor([ 1, 2, 3])
>>> torch.arange(1, 2.5, 0.5)
tensor([ 1.0000, 1.5000, 2.0000])
torch.arccos
Python Library Documentation: built-in function arccos in module torch
arccos(...)
arccos(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.acos`.
torch.arccos_
Python Library Documentation: built-in function arccos_ in module torch arccos_(...)
torch.arccosh
Python Library Documentation: built-in function arccosh in module torch
arccosh(...)
arccosh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.acosh`.
torch.arccosh_
Python Library Documentation: built-in function arccosh_ in module torch arccosh_(...)
torch.arcsin
Python Library Documentation: built-in function arcsin in module torch
arcsin(...)
arcsin(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.asin`.
torch.arcsin_
Python Library Documentation: built-in function arcsin_ in module torch arcsin_(...)
torch.arcsinh
Python Library Documentation: built-in function arcsinh in module torch
arcsinh(...)
arcsinh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.asinh`.
torch.arcsinh_
Python Library Documentation: built-in function arcsinh_ in module torch arcsinh_(...)
torch.arctan
Python Library Documentation: built-in function arctan in module torch
arctan(...)
arctan(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.atan`.
torch.arctan2
Python Library Documentation: built-in function arctan2 in module torch
arctan2(...)
arctan2(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.atan2`.
torch.arctan_
Python Library Documentation: built-in function arctan_ in module torch arctan_(...)
torch.arctanh
Python Library Documentation: built-in function arctanh in module torch
arctanh(...)
arctanh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.atanh`.
torch.arctanh_
Python Library Documentation: built-in function arctanh_ in module torch arctanh_(...)
torch.are_deterministic_algorithms_enabled
Python Library Documentation: function are_deterministic_algorithms_enabled in module torch
are_deterministic_algorithms_enabled() -> bool
Returns True if the global deterministic flag is turned on. Refer to
:func:`torch.use_deterministic_algorithms` documentation for more details.
torch.argmax
Python Library Documentation: built-in function argmax in module torch
argmax(...)
argmax(input) -> LongTensor
Returns the indices of the maximum value of all elements in the :attr:`input` tensor.
This is the second value returned by :meth:`torch.max`. See its
documentation for the exact semantics of this method.
.. note:: If there are multiple maximal values then the indices of the first maximal value are returned.
Args:
input (Tensor): the input tensor.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 1.3398, 0.2663, -0.2686, 0.2450],
[-0.7401, -0.8805, -0.3402, -1.1936],
[ 0.4907, -1.3948, -1.0691, -0.3132],
[-1.6092, 0.5419, -0.2993, 0.3195]])
>>> torch.argmax(a)
tensor(0)
.. function:: argmax(input, dim, keepdim=False) -> LongTensor
:noindex:
Returns the indices of the maximum values of a tensor across a dimension.
This is the second value returned by :meth:`torch.max`. See its
documentation for the exact semantics of this method.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce.
If ``None``, the argmax of the flattened input is returned.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 1.3398, 0.2663, -0.2686, 0.2450],
[-0.7401, -0.8805, -0.3402, -1.1936],
[ 0.4907, -1.3948, -1.0691, -0.3132],
[-1.6092, 0.5419, -0.2993, 0.3195]])
>>> torch.argmax(a, dim=1)
tensor([ 0, 2, 0, 1])
torch.argmin
Python Library Documentation: built-in function argmin in module torch
argmin(...)
argmin(input, dim=None, keepdim=False) -> LongTensor
Returns the indices of the minimum value(s) of the flattened tensor or along a dimension
This is the second value returned by :meth:`torch.min`. See its
documentation for the exact semantics of this method.
.. note:: If there are multiple minimal values then the indices of the first minimal value are returned.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce.
If ``None``, the argmin of the flattened input is returned.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.1139, 0.2254, -0.1381, 0.3687],
[ 1.0100, -1.1975, -0.0102, -0.4732],
[-0.9240, 0.1207, -0.7506, -1.0213],
[ 1.7809, -1.2960, 0.9384, 0.1438]])
>>> torch.argmin(a)
tensor(13)
>>> torch.argmin(a, dim=1)
tensor([ 2, 1, 3, 1])
>>> torch.argmin(a, dim=1, keepdim=True)
tensor([[2],
[1],
[3],
[1]])
torch.argsort
Python Library Documentation: built-in function argsort in module torch
argsort(...)
argsort(input, dim=-1, descending=False, *, stable=False) -> Tensor
Returns the indices that sort a tensor along a given dimension in ascending
order by value.
This is the second value returned by :meth:`torch.sort`. See its documentation
for the exact semantics of this method.
If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
the order of equivalent elements. If ``False``, the relative order of values
which compare equal is not guaranteed. ``True`` is slower.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to sort along
descending (bool, optional): controls the sorting order (ascending or descending)
Keyword args:
stable (bool, optional): controls the relative order of equivalent elements
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.0785, 1.5267, -0.8521, 0.4065],
[ 0.1598, 0.0788, -0.0745, -1.2700],
[ 1.2208, 1.0722, -0.7064, 1.2564],
[ 0.0669, -0.2318, -0.8229, -0.9280]])
>>> torch.argsort(a, dim=1)
tensor([[2, 0, 3, 1],
[3, 2, 1, 0],
[2, 1, 0, 3],
[3, 2, 1, 0]])
torch.argwhere
Python Library Documentation: built-in function argwhere in module torch
argwhere(...)
argwhere(input) -> Tensor
Returns a tensor containing the indices of all non-zero elements of
:attr:`input`. Each row in the result contains the indices of a non-zero
element in :attr:`input`. The result is sorted lexicographically, with
the last index changing the fastest (C-style).
If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
:attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
non-zero elements in the :attr:`input` tensor.
.. note::
This function is similar to NumPy's `argwhere`.
When :attr:`input` is on CUDA, this function causes host-device synchronization.
Args:
{input}
Example::
>>> t = torch.tensor([1, 0, 1])
>>> torch.argwhere(t)
tensor([[0],
[2]])
>>> t = torch.tensor([[1, 0, 1], [0, 1, 1]])
>>> torch.argwhere(t)
tensor([[0, 0],
[0, 2],
[1, 1],
[1, 2]])
torch.as_strided
Python Library Documentation: built-in function as_strided in module torch
as_strided(...)
as_strided(input, size, stride, storage_offset=None) -> Tensor
Create a view of an existing `torch.Tensor` :attr:`input` with specified
:attr:`size`, :attr:`stride` and :attr:`storage_offset`.
.. warning::
Prefer using other view functions, like :meth:`torch.Tensor.view` or
:meth:`torch.Tensor.expand`, to setting a view's strides manually with
`as_strided`, as this function will throw an error on non-standard Pytorch
backends (that do not have a concept of stride) and the result will depend
on the current layout in memory. The constructed view must only refer to
elements within the Tensor's storage or a runtime error will be thrown.
If the generated view is "overlapped" (with multiple indices referring to
the same element in memory), the behavior of inplace operations on this view
is undefined (and might not throw runtime errors).
Args:
input (Tensor): the input tensor.
size (tuple or ints): the shape of the output tensor
stride (tuple or ints): the stride of the output tensor
storage_offset (int, optional): the offset in the underlying storage of the output tensor.
If ``None``, the storage_offset of the output tensor will match the input tensor.
Example::
>>> x = torch.randn(3, 3)
>>> x
tensor([[ 0.9039, 0.6291, 1.0795],
[ 0.1586, 2.1939, -0.4900],
[-0.1909, -0.7503, 1.9355]])
>>> t = torch.as_strided(x, (2, 2), (1, 2))
>>> t
tensor([[0.9039, 1.0795],
[0.6291, 0.1586]])
>>> t = torch.as_strided(x, (2, 2), (1, 2), 1)
tensor([[0.6291, 0.1586],
[1.0795, 2.1939]])
torch.as_strided_
Python Library Documentation: built-in function as_strided_ in module torch as_strided_(...)
torch.as_strided_copy
Python Library Documentation: built-in function as_strided_copy in module torch
as_strided_copy(...)
Performs the same operation as :func:`torch.as_strided`, but all output tensors
are freshly created instead of aliasing the input.
torch.as_strided_scatter
Python Library Documentation: built-in function as_strided_scatter in module torch
as_strided_scatter(...)
as_strided_scatter(input, src, size, stride, storage_offset=None) -> Tensor
Embeds the values of the :attr:`src` tensor into :attr:`input` along
the elements corresponding to the result of calling
input.as_strided(size, stride, storage_offset).
This function returns a tensor with fresh storage; it does not
return a view.
Args:
input (Tensor): the input tensor.
size (tuple or ints): the shape of the output tensor
stride (tuple or ints): the stride of the output tensor
storage_offset (int, optional): the offset in the underlying storage of the output tensor
.. note::
:attr:`src` must be of the proper size in order to be embedded
into :attr:`input`. Specifically, it should have the same shape as
`torch.as_strided(input, size, stride, storage_offset)`
Example::
>>> a = torch.arange(4).reshape(2, 2) + 1
>>> a
tensor([[1, 2],
[3, 4]])
>>> b = torch.zeros(3, 3)
>>> b
tensor([[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]])
>>> torch.as_strided_scatter(b, a, (2, 2), (1, 2))
tensor([[1., 3., 2.],
[4., 0., 0.],
[0., 0., 0.]])
torch.as_tensor
Python Library Documentation: built-in function as_tensor in module torch
as_tensor(...)
as_tensor(data: Any, *, dtype: Optional[dtype] = None, device: Optional[DeviceLikeType]) -> Tensor
Converts :attr:`data` into a tensor, sharing data and preserving autograd
history if possible.
If :attr:`data` is already a tensor with the requested dtype and device
then :attr:`data` itself is returned, but if :attr:`data` is a
tensor with a different dtype or device then it's copied as if using
`data.to(dtype=dtype, device=device)`.
If :attr:`data` is a NumPy array (an ndarray) with the same dtype and device then a
tensor is constructed using :func:`torch.from_numpy`.
If :attr:`data` is a CuPy array, the returned tensor will be located on the same device as the CuPy array unless
specifically overwritten by :attr:`device` or a default device. The device of the CuPy array is inferred from the
pointer of the array using `cudaPointerGetAttributes` unless :attr:`device` is provided with an explicit device index.
.. seealso::
:func:`torch.tensor` never shares its data and creates a new "leaf tensor" (see :doc:`/notes/autograd`).
Args:
data (array_like): Initial data for the tensor. Can be a list, tuple,
NumPy ``ndarray``, scalar, and other types.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, infers data type from :attr:`data`.
device (:class:`torch.device`, optional): the device of the constructed tensor. If None and data is a tensor
then the device of data is used. If None and data is not a tensor then
the result tensor is constructed on the current device.
Example::
>>> a = numpy.array([1, 2, 3])
>>> t = torch.as_tensor(a)
>>> t
tensor([ 1, 2, 3])
>>> t[0] = -1
>>> a
array([-1, 2, 3])
>>> a = numpy.array([1, 2, 3])
>>> t = torch.as_tensor(a, device=torch.device('cuda'))
>>> t
tensor([ 1, 2, 3])
>>> t[0] = -1
>>> a
array([1, 2, 3])
torch.asarray
Python Library Documentation: built-in function asarray in module torch
asarray(...)
asarray(obj: Any, *, dtype: Optional[dtype], device: Optional[DeviceLikeType], copy: Optional[bool] = None, requires_grad: Optional[bool] = None) -> Tensor # noqa: B950
Converts :attr:`obj` to a tensor.
:attr:`obj` can be one of:
1. a tensor
2. a NumPy array or a NumPy scalar
3. a DLPack capsule
4. an object that implements Python's buffer protocol
5. a scalar
6. a sequence of scalars
When :attr:`obj` is a tensor, NumPy array, or DLPack capsule the returned tensor will,
by default, have the same requires_grad as :attr:`obj` (defaulting to False), have the
same datatype, be on the same device, and share memory with it. These properties can be
controlled with the :attr:`dtype`, :attr:`device`, :attr:`copy`, and
:attr:`requires_grad` keyword arguments. If the returned tensor is of a different
datatype, on a different device, or a copy is requested then it will not share its
memory with :attr:`obj`. If :attr:`requires_grad` is ``True`` (or ``None``, and
:attr:`obj` was a tensor with requires_grad set), then the returned tensor will require
a gradient, and if :attr:`obj` is also a tensor with an autograd history then the
returned tensor will have the same history.
When :attr:`obj` is not a tensor, NumPy array, or DLPack capsule but implements Python's
buffer protocol then the buffer is interpreted as an array of bytes grouped according to
the size of the datatype passed to the :attr:`dtype` keyword argument. (If no datatype is
passed then the default floating point datatype is used, instead.) The returned tensor
will have the specified datatype (or default floating point datatype if none is specified)
and, by default, be on the CPU device and share memory with the buffer.
When :attr:`obj` is a NumPy scalar, the returned tensor will be a 0-dimensional tensor on
the CPU and that doesn't share its memory (i.e. ``copy=True``). By default datatype will
be the PyTorch datatype corresponding to the NumPy's scalar's datatype.
When :attr:`obj` is none of the above but a scalar, or a sequence of scalars then the
returned tensor will, by default, infer its datatype from the scalar values, be on the
current default device, and not share its memory.
.. seealso::
:func:`torch.tensor` creates a tensor that always copies the data from the input object.
:func:`torch.from_numpy` creates a tensor that always shares memory from NumPy arrays.
:func:`torch.frombuffer` creates a tensor that always shares memory from objects that
implement the buffer protocol.
:func:`torch.from_dlpack` creates a tensor that always shares memory from
DLPack capsules.
Args:
obj (object): a tensor, NumPy array, DLPack Capsule, object that implements Python's
buffer protocol, scalar, or sequence of scalars.
Keyword args:
dtype (:class:`torch.dtype`, optional): the datatype of the returned tensor.
Default: ``None``, which causes the datatype of the returned tensor to be
inferred from :attr:`obj`.
copy (bool, optional): controls whether the returned tensor shares memory with :attr:`obj`.
Default: ``None``, which causes the returned tensor to share memory with :attr:`obj`
whenever possible. If ``True`` then the returned tensor does not share its memory.
If ``False`` then the returned tensor shares its memory with :attr:`obj` and an
error is thrown if it cannot.
device (:class:`torch.device`, optional): the device of the returned tensor.
Default: ``None``, which causes the device of :attr:`obj` to be used. Or, if
:attr:`obj` is a Python sequence, the current default device will be used.
requires_grad (bool, optional): whether the returned tensor requires grad.
Default: ``None``, which causes requires_grad for the returned tensor to be
inferred from :attr:`obj`. If ``True``, then the returned tensor will require
a gradient, and if :attr:`obj` is also a tensor with an autograd history then
the returned tensor will have the same history.
Example::
>>> a = torch.tensor([1, 2, 3])
>>> # Shares memory with tensor 'a'
>>> b = torch.asarray(a)
>>> a.data_ptr() == b.data_ptr()
True
>>> # Forces memory copy
>>> c = torch.asarray(a, copy=True)
>>> a.data_ptr() == c.data_ptr()
False
>>> a = torch.tensor([1., 2., 3.], requires_grad=True)
>>> b = a + 2
>>> b
tensor([3., 4., 5.], grad_fn=<AddBackward0>)
>>> # Shares memory with tensor 'b', with no grad
>>> c = torch.asarray(b, requires_grad=False)
>>> c
tensor([3., 4., 5.])
>>> # Shares memory with tensor 'b', retaining autograd history
>>> d = torch.asarray(b, requires_grad=True)
>>> d
tensor([3., 4., 5.], grad_fn=<AddBackward0>)
>>> # Shares memory with tensor 'b', retaining autograd history
>>> e = torch.asarray(b)
>>> e
tensor([3., 4., 5.], grad_fn=<AddBackward0>)
>>> array = numpy.array([1, 2, 3])
>>> # Shares memory with array 'array'
>>> t1 = torch.asarray(array)
>>> array.__array_interface__['data'][0] == t1.data_ptr()
True
>>> # Copies memory due to dtype mismatch
>>> t2 = torch.asarray(array, dtype=torch.float32)
>>> array.__array_interface__['data'][0] == t2.data_ptr()
False
>>> scalar = numpy.float64(0.5)
>>> torch.asarray(scalar)
tensor(0.5000, dtype=torch.float64)
torch.asin
Python Library Documentation: built-in function asin in module torch
asin(...)
asin(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the arcsine of the elements (in radians) in the :attr:`input` tensor.
.. math::
\text{out}_{i} = \sin^{-1}(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-0.5962, 1.4985, -0.4396, 1.4525])
>>> torch.asin(a)
tensor([-0.6387, nan, -0.4552, nan])
torch.asin_
Python Library Documentation: built-in function asin_ in module torch asin_(...)
torch.asinh
Python Library Documentation: built-in function asinh in module torch
asinh(...)
asinh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the inverse hyperbolic sine of the elements of :attr:`input`.
.. math::
\text{out}_{i} = \sinh^{-1}(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.1606, -1.4267, -1.0899, -1.0250 ])
>>> torch.asinh(a)
tensor([ 0.1599, -1.1534, -0.9435, -0.8990 ])
torch.asinh_
Python Library Documentation: built-in function asinh_ in module torch asinh_(...)
torch.atan
Python Library Documentation: built-in function atan in module torch
atan(...)
atan(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the arctangent of the elements (in radians) in the :attr:`input` tensor.
.. math::
\text{out}_{i} = \tan^{-1}(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.2341, 0.2539, -0.6256, -0.6448])
>>> torch.atan(a)
tensor([ 0.2299, 0.2487, -0.5591, -0.5727])
torch.atan2
Python Library Documentation: built-in function atan2 in module torch
atan2(...)
atan2(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
Element-wise arctangent of :math:`\text{input}_{i} / \text{other}_{i}`
with consideration of the quadrant. Returns a new tensor with the signed angles
in radians between vector :math:`(\text{other}_{i}, \text{input}_{i})`
and vector :math:`(1, 0)`. (Note that :math:`\text{other}_{i}`, the second
parameter, is the x-coordinate, while :math:`\text{input}_{i}`, the first
parameter, is the y-coordinate.)
The shapes of ``input`` and ``other`` must be
:ref:`broadcastable <broadcasting-semantics>`.
Args:
input (Tensor): the first input tensor
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.9041, 0.0196, -0.3108, -2.4423])
>>> torch.atan2(a, torch.randn(4))
tensor([ 0.9833, 0.0811, -1.9743, -1.4151])
torch.atan_
Python Library Documentation: built-in function atan_ in module torch atan_(...)
torch.atanh
Python Library Documentation: built-in function atanh in module torch
atanh(...)
atanh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the inverse hyperbolic tangent of the elements of :attr:`input`.
Note:
The domain of the inverse hyperbolic tangent is `(-1, 1)` and values outside this range
will be mapped to ``NaN``, except for the values `1` and `-1` for which the output is
mapped to `+/-INF` respectively.
.. math::
\text{out}_{i} = \tanh^{-1}(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4).uniform_(-1, 1)
>>> a
tensor([ -0.9385, 0.2968, -0.8591, -0.1871 ])
>>> torch.atanh(a)
tensor([ -1.7253, 0.3060, -1.2899, -0.1893 ])
torch.atanh_
Python Library Documentation: built-in function atanh_ in module torch atanh_(...)
torch.atleast_1d
Python Library Documentation: function atleast_1d in module torch.functional
atleast_1d(*tensors)
Returns a 1-dimensional view of each input tensor with zero dimensions.
Input tensors with one or more dimensions are returned as-is.
Args:
input (Tensor or sequence of Tensors): tensor(s) to be converted to at least 1-dimensional.
Returns:
output (Tensor or tuple of Tensors)
Example::
>>> x = torch.arange(2)
>>> x
tensor([0, 1])
>>> torch.atleast_1d(x)
tensor([0, 1])
>>> x = torch.tensor(1.)
>>> x
tensor(1.)
>>> torch.atleast_1d(x)
tensor([1.])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.)
>>> torch.atleast_1d((x, y))
(tensor([0.5000]), tensor([1.]))
>>> torch.atleast_1d()
()
torch.atleast_2d
Python Library Documentation: function atleast_2d in module torch.functional
atleast_2d(*tensors)
Returns a 2-dimensional view of each input tensor with zero dimensions.
Input tensors with two or more dimensions are returned as-is.
Args:
input (Tensor or sequence of Tensors): tensor(s) to be converted to at least 2-dimensional.
Returns:
output (Tensor or tuple of Tensors)
Example::
>>> x = torch.tensor(1.)
>>> x
tensor(1.)
>>> torch.atleast_2d(x)
tensor([[1.]])
>>> x = torch.arange(4).view(2, 2)
>>> x
tensor([[0, 1],
[2, 3]])
>>> torch.atleast_2d(x)
tensor([[0, 1],
[2, 3]])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.)
>>> torch.atleast_2d((x, y))
(tensor([[0.5000]]), tensor([[1.]]))
>>> torch.atleast_2d()
()
torch.atleast_3d
Python Library Documentation: function atleast_3d in module torch.functional
atleast_3d(*tensors)
Returns a 3-dimensional view of each input tensor with zero dimensions.
Input tensors with three or more dimensions are returned as-is.
Args:
input (Tensor or sequence of Tensors): tensor(s) to be converted to at least 3-dimensional.
Returns:
output (Tensor or tuple of Tensors)
Example:
>>> x = torch.tensor(0.5)
>>> x
tensor(0.5000)
>>> torch.atleast_3d(x)
tensor([[[0.5000]]])
>>> y = torch.arange(4).view(2, 2)
>>> y
tensor([[0, 1],
[2, 3]])
>>> torch.atleast_3d(y)
tensor([[[0],
[1]],
<BLANKLINE>
[[2],
[3]]])
>>> x = torch.tensor(1).view(1, 1, 1)
>>> x
tensor([[[1]]])
>>> torch.atleast_3d(x)
tensor([[[1]]])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.0)
>>> torch.atleast_3d((x, y))
(tensor([[[0.5000]]]), tensor([[[1.]]]))
>>> torch.atleast_3d()
()
torch.autocast
Python Library Documentation: class autocast in module torch.amp.autocast_mode class autocast(builtins.object) | autocast(device_type: str, dtype: torch.dtype | None = None, enabled: bool = True, cache_enabled: bool | None = None) | | Instances of :class:`autocast` serve as context managers or decorators that | allow regions of your script to run in mixed precision. | | In these regions, ops run in an op-specific dtype chosen by autocast | to improve performance while maintaining accuracy. | See the :ref:`Autocast Op Reference<autocast-op-reference>` for details. | | When entering an autocast-enabled region, Tensors may be any type. | You should not call ``half()`` or ``bfloat16()`` on your model(s) or inputs when using autocasting. | | :class:`autocast` should wrap only the forward pass(es) of your network, including the loss | computation(s). Backward passes under autocast are not recommended. | Backward ops run in the same type that autocast used for corresponding forward ops. | | Example for CUDA Devices:: | | # Creates model and optimizer in default precision | model = Net().cuda() | optimizer = optim.SGD(model.parameters(), ...) | | for input, target in data: | optimizer.zero_grad() | | # Enables autocasting for the forward pass (model + loss) | with torch.autocast(device_type="cuda"): | output = model(input) | loss = loss_fn(output, target) | | # Exits the context manager before backward() | loss.backward() | optimizer.step() | | See the :ref:`Automatic Mixed Precision examples<amp-examples>` for usage (along with gradient scaling) | in more complex scenarios (e.g., gradient penalty, multiple models/losses, custom autograd functions). | | :class:`autocast` can also be used as a decorator, e.g., on the ``forward`` method of your model:: | | class AutocastModel(nn.Module): | ... | | @torch.autocast(device_type="cuda") | def forward(self, input): ... | | Floating-point Tensors produced in an autocast-enabled region may be ``float16``. | After returning to an autocast-disabled region, using them with floating-point | Tensors of different dtypes may cause type mismatch errors. If so, cast the Tensor(s) | produced in the autocast region back to ``float32`` (or other dtype if desired). | If a Tensor from the autocast region is already ``float32``, the cast is a no-op, | and incurs no additional overhead. | CUDA Example:: | | # Creates some tensors in default dtype (here assumed to be float32) | a_float32 = torch.rand((8, 8), device="cuda") | b_float32 = torch.rand((8, 8), device="cuda") | c_float32 = torch.rand((8, 8), device="cuda") | d_float32 = torch.rand((8, 8), device="cuda") | | with torch.autocast(device_type="cuda"): | # torch.mm is on autocast's list of ops that should run in float16. | # Inputs are float32, but the op runs in float16 and produces float16 output. | # No manual casts are required. | e_float16 = torch.mm(a_float32, b_float32) | # Also handles mixed input types | f_float16 = torch.mm(d_float32, e_float16) | | # After exiting autocast, calls f_float16.float() to use with d_float32 | g_float32 = torch.mm(d_float32, f_float16.float()) | | CPU Training Example:: | | # Creates model and optimizer in default precision | model = Net() | optimizer = optim.SGD(model.parameters(), ...) | | for epoch in epochs: | for input, target in data: | optimizer.zero_grad() | | # Runs the forward pass with autocasting. | with torch.autocast(device_type="cpu", dtype=torch.bfloat16): | output = model(input) | loss = loss_fn(output, target) | | loss.backward() | optimizer.step() | | | CPU Inference Example:: | | # Creates model in default precision | model = Net().eval() | | with torch.autocast(device_type="cpu", dtype=torch.bfloat16): | for input in data: | # Runs the forward pass with autocasting. | output = model(input) | | CPU Inference Example with Jit Trace:: | | class TestModel(nn.Module): | def __init__(self, input_size, num_classes): | super().__init__() | self.fc1 = nn.Linear(input_size, num_classes) | | def forward(self, x): | return self.fc1(x) | | | input_size = 2 | num_classes = 2 | model = TestModel(input_size, num_classes).eval() | | # For now, we suggest to disable the Jit Autocast Pass, | # As the issue: https://github.com/pytorch/pytorch/issues/75956 | torch._C._jit_set_autocast_mode(False) | | with torch.cpu.amp.autocast(cache_enabled=False): | model = torch.jit.trace(model, torch.randn(1, input_size)) | model = torch.jit.freeze(model) | # Models Run | for _ in range(3): | model(torch.randn(1, input_size)) | | Type mismatch errors *in* an autocast-enabled region are a bug; if this is what you observe, | please file an issue. | | ``autocast(enabled=False)`` subregions can be nested in autocast-enabled regions. | Locally disabling autocast can be useful, for example, if you want to force a subregion | to run in a particular ``dtype``. Disabling autocast gives you explicit control over | the execution type. In the subregion, inputs from the surrounding region | should be cast to ``dtype`` before use:: | | # Creates some tensors in default dtype (here assumed to be float32) | a_float32 = torch.rand((8, 8), device="cuda") | b_float32 = torch.rand((8, 8), device="cuda") | c_float32 = torch.rand((8, 8), device="cuda") | d_float32 = torch.rand((8, 8), device="cuda") | | with torch.autocast(device_type="cuda"): | e_float16 = torch.mm(a_float32, b_float32) | with torch.autocast(device_type="cuda", enabled=False): | # Calls e_float16.float() to ensure float32 execution | # (necessary because e_float16 was created in an autocasted region) | f_float32 = torch.mm(c_float32, e_float16.float()) | | # No manual casts are required when re-entering the autocast-enabled region. | # torch.mm again runs in float16 and produces float16 output, regardless of input types. | g_float16 = torch.mm(d_float32, f_float32) | | The autocast state is thread-local. If you want it enabled in a new thread, the context manager or decorator | must be invoked in that thread. This affects :class:`torch.nn.DataParallel` and | :class:`torch.nn.parallel.DistributedDataParallel` when used with more than one GPU per process | (see :ref:`Working with Multiple GPUs<amp-multigpu>`). | | Args: | device_type(str, required): Device type to use. Possible values are: 'cuda', 'cpu', 'mtia', 'maia', 'xpu', and 'hpu'. | The type is the same as the `type` attribute of a :class:`torch.device`. | Thus, you may obtain the device type of a tensor using `Tensor.device.type`. | enabled(bool, optional): Whether autocasting should be enabled in the region. | Default: ``True`` | dtype(torch_dtype, optional): Data type for ops run in autocast. It uses the default value | (``torch.float16`` for CUDA and ``torch.bfloat16`` for CPU), given by | :func:`~torch.get_autocast_dtype`, if :attr:`dtype` is ``None``. | Default: ``None`` | cache_enabled(bool, optional): Whether the weight cache inside autocast should be enabled. | Default: ``True`` | | Methods defined here: | | __call__(self, func) | Call self as a function. | | __enter__(self) | | __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) | | __init__(self, device_type: str, dtype: torch.dtype | None = None, enabled: bool = True, cache_enabled: bool | None = None) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
torch.autocast_decrement_nesting
Python Library Documentation: built-in function autocast_decrement_nesting in module torch autocast_decrement_nesting(...)
torch.autocast_increment_nesting
Python Library Documentation: built-in function autocast_increment_nesting in module torch autocast_increment_nesting(...)
torch.autograd
Python Library Documentation: package torch.autograd in torch
NAME
torch.autograd - ``torch.autograd`` provides classes and functions implementing automatic differentiation of arbitrary scalar valued functions.
DESCRIPTION
It requires minimal changes to the existing code - you only need to declare :class:`Tensor` s
for which gradients should be computed with the ``requires_grad=True`` keyword.
As of now, we only support autograd for floating point :class:`Tensor` types (
half, float, double and bfloat16) and complex :class:`Tensor` types (cfloat, cdouble).
PACKAGE CONTENTS
_functions (package)
anomaly_mode
forward_ad
function
functional
grad_mode
gradcheck
graph
profiler
profiler_legacy
profiler_util
variable
CLASSES
builtins.object
torch.autograd.anomaly_mode.detect_anomaly
torch.autograd.anomaly_mode.set_detect_anomaly
torch._C._LegacyVariableBase(builtins.object)
torch.autograd.variable.Variable
torch.autograd.function._SingleLevelFunction(torch._C._FunctionBase, torch.autograd.function.FunctionCtx, torch.autograd.function._HookMixin)
torch.autograd.function.Function
torch.autograd.function.NestedIOFunction
torch.utils._contextlib._DecoratorContextManager(builtins.object)
torch.autograd.grad_mode.enforce_grad_layout_policy
torch.autograd.grad_mode.inference_mode
torch.autograd.grad_mode.set_grad_enabled
torch.autograd.grad_mode.set_multithreading_enabled
torch.utils._contextlib._NoParamDecoratorContextManager(torch.utils._contextlib._DecoratorContextManager)
torch.autograd.grad_mode.enable_grad
torch.autograd.grad_mode.no_grad
class Function(_SingleLevelFunction)
| Function(*args, **kwargs)
|
| Base class to create custom `autograd.Function`.
|
| To create a custom `autograd.Function`, subclass this class and implement
| the :meth:`forward` and :meth:`backward` static methods. Then, to use your custom
| op in the forward pass, call the class method ``apply``. Do not call
| :meth:`forward` directly.
|
| To ensure correctness and best performance, make sure you are calling the
| correct methods on ``ctx`` and validating your backward function using
| :func:`torch.autograd.gradcheck`.
|
| See :ref:`extending-autograd` for more details on how to use this class.
|
| Examples::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_AUTOGRAD)
| >>> class Exp(Function):
| >>> @staticmethod
| >>> def forward(ctx, i):
| >>> result = i.exp()
| >>> ctx.save_for_backward(result)
| >>> return result
| >>>
| >>> @staticmethod
| >>> def backward(ctx, grad_output):
| >>> result, = ctx.saved_tensors
| >>> return grad_output * result
| >>>
| >>> # Use it by calling the apply method:
| >>> # xdoctest: +SKIP
| >>> output = Exp.apply(input)
|
| Method resolution order:
| Function
| _SingleLevelFunction
| torch._C._FunctionBase
| FunctionCtx
| _HookMixin
| builtins.object
|
| Methods defined here:
|
| __call__(self, *args, **kwargs)
| Call self as a function.
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| apply(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| vmap(info, in_dims, *args)
| Define the behavior for this autograd.Function underneath :func:`torch.vmap`.
|
| For a :func:`torch.autograd.Function` to support
| :func:`torch.vmap`, you must either override this static method, or set
| ``generate_vmap_rule`` to ``True`` (you may not do both).
|
| If you choose to override this staticmethod: it must accept
|
| - an ``info`` object as the first argument. ``info.batch_size``
| specifies the size of the dimension being vmapped over,
| while ``info.randomness`` is the randomness option passed to
| :func:`torch.vmap`.
| - an ``in_dims`` tuple as the second argument.
| For each arg in ``args``, ``in_dims`` has a corresponding
| ``Optional[int]``. It is ``None`` if the arg is not a Tensor or if
| the arg is not being vmapped over, otherwise, it is an integer
| specifying what dimension of the Tensor is being vmapped over.
| - ``*args``, which is the same as the args to :meth:`~Function.forward`.
|
| The return of the vmap staticmethod is a tuple of ``(output, out_dims)``.
| Similar to ``in_dims``, ``out_dims`` should be of the same structure as
| ``output`` and contain one ``out_dim`` per output that specifies if the
| output has the vmapped dimension and what index it is in.
|
| Please see :ref:`func-autograd-function` for more details.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| generate_vmap_rule = False
|
| ----------------------------------------------------------------------
| Static methods inherited from _SingleLevelFunction:
|
| backward(ctx: Any, *grad_outputs: Any) -> Any
| Define a formula for differentiating the operation with backward mode automatic differentiation.
|
| This function is to be overridden by all subclasses.
| (Defining this function is equivalent to defining the ``vjp`` function.)
|
| It must accept a context :attr:`ctx` as the first argument, followed by
| as many outputs as the :func:`forward` returned (None will be passed in
| for non tensor outputs of the forward function),
| and it should return as many tensors, as there were inputs to
| :func:`forward`. Each argument is the gradient w.r.t the given output,
| and each returned value should be the gradient w.r.t. the
| corresponding input. If an input is not a Tensor or is a Tensor not
| requiring grads, you can just pass None as a gradient for that input.
|
| The context can be used to retrieve tensors saved during the forward
| pass. It also has an attribute :attr:`ctx.needs_input_grad` as a tuple
| of booleans representing whether each input needs gradient. E.g.,
| :func:`backward` will have ``ctx.needs_input_grad[0] = True`` if the
| first input to :func:`forward` needs gradient computed w.r.t. the
| output.
|
| forward(*args: Any, **kwargs: Any) -> Any
| Define the forward of the custom autograd Function.
|
| This function is to be overridden by all subclasses.
| There are two ways to define forward:
|
| Usage 1 (Combined forward and ctx)::
|
| @staticmethod
| def forward(ctx: Any, *args: Any, **kwargs: Any) -> Any:
| pass
|
| - It must accept a context ctx as the first argument, followed by any
| number of arguments (tensors or other types).
| - See :ref:`combining-forward-context` for more details
|
| Usage 2 (Separate forward and ctx)::
|
| @staticmethod
| def forward(*args: Any, **kwargs: Any) -> Any:
| pass
|
|
| @staticmethod
| def setup_context(ctx: Any, inputs: Tuple[Any, ...], output: Any) -> None:
| pass
|
| - The forward no longer accepts a ctx argument.
| - Instead, you must also override the :meth:`torch.autograd.Function.setup_context`
| staticmethod to handle setting up the ``ctx`` object.
| ``output`` is the output of the forward, ``inputs`` are a Tuple of inputs
| to the forward.
| - See :ref:`extending-autograd` for more details
|
| The context can be used to store arbitrary data that can be then
| retrieved during the backward pass. Tensors should not be stored
| directly on `ctx` (though this is not currently enforced for
| backward compatibility). Instead, tensors should be saved either with
| :func:`ctx.save_for_backward` if they are intended to be used in
| ``backward`` (equivalently, ``vjp``) or :func:`ctx.save_for_forward`
| if they are intended to be used for in ``jvp``.
|
| jvp(ctx: Any, *grad_inputs: Any) -> Any
| Define a formula for differentiating the operation with forward mode automatic differentiation.
|
| This function is to be overridden by all subclasses.
| It must accept a context :attr:`ctx` as the first argument, followed by
| as many inputs as the :func:`forward` got (None will be passed in
| for non tensor inputs of the forward function),
| and it should return as many tensors as there were outputs to
| :func:`forward`. Each argument is the gradient w.r.t the given input,
| and each returned value should be the gradient w.r.t. the
| corresponding output. If an output is not a Tensor or the function is not
| differentiable with respect to that output, you can just pass None as a
| gradient for that input.
|
| You can use the :attr:`ctx` object to pass any value from the forward to this
| functions.
|
| setup_context(ctx: Any, inputs: tuple[typing.Any, ...], output: Any) -> Any
| There are two ways to define the forward pass of an autograd.Function.
|
| Either:
|
| 1. Override forward with the signature ``forward(ctx, *args, **kwargs)``.
| ``setup_context`` is not overridden. Setting up the ctx for backward
| happens inside the ``forward``.
| 2. Override forward with the signature ``forward(*args, **kwargs)`` and
| override ``setup_context``. Setting up the ctx for backward happens
| inside ``setup_context`` (as opposed to inside the ``forward``)
|
| See :meth:`torch.autograd.Function.forward` and :ref:`extending-autograd` for more details.
|
| vjp = backward(ctx: Any, *grad_outputs: Any) -> Any
| Define a formula for differentiating the operation with backward mode automatic differentiation.
|
| This function is to be overridden by all subclasses.
| (Defining this function is equivalent to defining the ``vjp`` function.)
|
| It must accept a context :attr:`ctx` as the first argument, followed by
| as many outputs as the :func:`forward` returned (None will be passed in
| for non tensor outputs of the forward function),
| and it should return as many tensors, as there were inputs to
| :func:`forward`. Each argument is the gradient w.r.t the given output,
| and each returned value should be the gradient w.r.t. the
| corresponding input. If an input is not a Tensor or is a Tensor not
| requiring grads, you can just pass None as a gradient for that input.
|
| The context can be used to retrieve tensors saved during the forward
| pass. It also has an attribute :attr:`ctx.needs_input_grad` as a tuple
| of booleans representing whether each input needs gradient. E.g.,
| :func:`backward` will have ``ctx.needs_input_grad[0] = True`` if the
| first input to :func:`forward` needs gradient computed w.r.t. the
| output.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _SingleLevelFunction:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from _SingleLevelFunction:
|
| boxed_grads_call = False
|
| clear_saved_tensors_on_access = False
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C._FunctionBase:
|
| maybe_clear_saved_tensors(...)
|
| name(...)
|
| register_hook(...)
|
| register_prehook(...)
|
| ----------------------------------------------------------------------
| Static methods inherited from torch._C._FunctionBase:
|
| __new__(*args, **kwargs) class method of torch._C._FunctionBase
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C._FunctionBase:
|
| dirty_tensors
|
| materialize_grads
|
| metadata
|
| needs_input_grad
|
| next_functions
|
| non_differentiable
|
| requires_grad
|
| saved_for_forward
|
| saved_tensors
|
| saved_variables
|
| to_save
|
| ----------------------------------------------------------------------
| Methods inherited from FunctionCtx:
|
| mark_dirty(self, *args: torch.Tensor)
| Mark given tensors as modified in an in-place operation.
|
| This should be called at most once, in either the :func:`setup_context`
| or :func:`forward` methods, and all arguments should be inputs.
|
| Every tensor that's been modified in-place in a call to :func:`forward`
| should be given to this function, to ensure correctness of our checks.
| It doesn't matter whether the function is called before or after
| modification.
|
| Examples::
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_AUTOGRAD)
| >>> class Inplace(Function):
| >>> @staticmethod
| >>> def forward(ctx, x):
| >>> x_npy = x.numpy() # x_npy shares storage with x
| >>> x_npy += 1
| >>> ctx.mark_dirty(x)
| >>> return x
| >>>
| >>> @staticmethod
| >>> @once_differentiable
| >>> def backward(ctx, grad_output):
| >>> return grad_output
| >>>
| >>> a = torch.tensor(1., requires_grad=True, dtype=torch.double).clone()
| >>> b = a * a
| >>> Inplace.apply(a) # This would lead to wrong gradients!
| >>> # but the engine would not know unless we mark_dirty
| >>> # xdoctest: +SKIP
| >>> b.backward() # RuntimeError: one of the variables needed for gradient
| >>> # computation has been modified by an inplace operation
|
| mark_non_differentiable(self, *args: torch.Tensor)
| Mark outputs as non-differentiable.
|
| This should be called at most once, in either the :func:`setup_context`
| or :func:`forward` methods, and all arguments should be tensor outputs.
|
| This will mark outputs as not requiring gradients, increasing the
| efficiency of backward computation. You still need to accept a gradient
| for each output in :meth:`~Function.backward`, but it's always going to
| be a zero tensor with the same shape as the shape of a corresponding
| output.
|
| This is used e.g. for indices returned from a sort. See example::
| >>> class Func(Function):
| >>> @staticmethod
| >>> def forward(ctx, x):
| >>> sorted, idx = x.sort()
| >>> ctx.mark_non_differentiable(idx)
| >>> ctx.save_for_backward(x, idx)
| >>> return sorted, idx
| >>>
| >>> @staticmethod
| >>> @once_differentiable
| >>> def backward(ctx, g1, g2): # still need to accept g2
| >>> x, idx = ctx.saved_tensors
| >>> grad_input = torch.zeros_like(x)
| >>> grad_input.index_add_(0, idx, g1)
| >>> return grad_input
|
| mark_shared_storage(self, *pairs)
|
| save_for_backward(self, *tensors: torch.Tensor)
| Save given tensors for a future call to :func:`~Function.backward`.
|
| ``save_for_backward`` should be called at most once, in either the
| :func:`setup_context` or :func:`forward` methods, and only with tensors.
|
| All tensors intended to be used in the backward pass should be saved
| with ``save_for_backward`` (as opposed to directly on ``ctx``) to prevent
| incorrect gradients and memory leaks, and enable the application of saved
| tensor hooks. See :class:`torch.autograd.graph.saved_tensors_hooks`.
| See :ref:`extending-autograd` for more details.
|
| Note that if intermediary tensors, tensors that are neither inputs
| nor outputs of :func:`forward`, are saved for backward, your custom Function
| may not support double backward.
| Custom Functions that do not support double backward should decorate their
| :func:`backward` method with ``@once_differentiable`` so that performing
| double backward raises an error. If you'd like to support double backward,
| you can either recompute intermediaries based on the inputs during backward
| or return the intermediaries as the outputs of the custom Function. See the
| `double backward tutorial <https://pytorch.org/tutorials/intermediate/custom_function_double_backward_tutorial.html>`_
| for more details.
|
| In :func:`backward`, saved tensors can be accessed through the :attr:`saved_tensors`
| attribute. Before returning them to the user, a check is made to ensure
| they weren't used in any in-place operation that modified their content.
|
| Arguments can also be ``None``. This is a no-op.
|
| See :ref:`extending-autograd` for more details on how to use this method.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_AUTOGRAD)
| >>> class Func(Function):
| >>> @staticmethod
| >>> def forward(ctx, x: torch.Tensor, y: torch.Tensor, z: int):
| >>> w = x * z
| >>> out = x * y + y * z + w * y
| >>> ctx.save_for_backward(x, y, w, out)
| >>> ctx.z = z # z is not a tensor
| >>> return out
| >>>
| >>> @staticmethod
| >>> @once_differentiable
| >>> def backward(ctx, grad_out):
| >>> x, y, w, out = ctx.saved_tensors
| >>> z = ctx.z
| >>> gx = grad_out * (y + y * z)
| >>> gy = grad_out * (x + z + w)
| >>> gz = None
| >>> return gx, gy, gz
| >>>
| >>> a = torch.tensor(1., requires_grad=True, dtype=torch.double)
| >>> b = torch.tensor(2., requires_grad=True, dtype=torch.double)
| >>> c = 4
| >>> d = Func.apply(a, b, c)
|
| save_for_forward(self, *tensors: torch.Tensor)
| Save given tensors for a future call to :func:`~Function.jvp`.
|
| ``save_for_forward`` should be called at most once, in either the
| :func:`setup_context` or :func:`forward` methods, and all arguments
| should be tensors.
|
| In :func:`jvp`, saved objects can be accessed through the :attr:`saved_tensors`
| attribute.
|
| Arguments can also be ``None``. This is a no-op.
|
| See :ref:`extending-autograd` for more details on how to use this method.
|
| Example::
|
| >>> # xdoctest: +SKIP
| >>> class Func(torch.autograd.Function):
| >>> @staticmethod
| >>> def forward(ctx, x: torch.Tensor, y: torch.Tensor, z: int):
| >>> ctx.save_for_backward(x, y)
| >>> ctx.save_for_forward(x, y)
| >>> ctx.z = z
| >>> return x * y * z
| >>>
| >>> @staticmethod
| >>> def jvp(ctx, x_t, y_t, _):
| >>> x, y = ctx.saved_tensors
| >>> z = ctx.z
| >>> return z * (y * x_t + x * y_t)
| >>>
| >>> @staticmethod
| >>> def vjp(ctx, grad_out):
| >>> x, y = ctx.saved_tensors
| >>> z = ctx.z
| >>> return z * grad_out * y, z * grad_out * x, None
| >>>
| >>> a = torch.tensor(1., requires_grad=True, dtype=torch.double)
| >>> t = torch.tensor(1., dtype=torch.double)
| >>> b = torch.tensor(2., requires_grad=True, dtype=torch.double)
| >>> c = 4
| >>>
| >>> with fwAD.dual_level():
| >>> a_dual = fwAD.make_dual(a, t)
| >>> d = Func.apply(a_dual, b, c)
|
| set_materialize_grads(self, value: bool)
| Set whether to materialize grad tensors. Default is ``True``.
|
| This should be called only from either the :func:`setup_context` or
| :func:`forward` methods.
|
| If ``True``, undefined grad tensors will be expanded to tensors full of zeros
| prior to calling the :func:`backward` and :func:`jvp` methods.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_AUTOGRAD)
| >>> class SimpleFunc(Function):
| >>> @staticmethod
| >>> def forward(ctx, x):
| >>> return x.clone(), x.clone()
| >>>
| >>> @staticmethod
| >>> @once_differentiable
| >>> def backward(ctx, g1, g2):
| >>> return g1 + g2 # No check for None necessary
| >>>
| >>> # We modify SimpleFunc to handle non-materialized grad outputs
| >>> class Func(Function):
| >>> @staticmethod
| >>> def forward(ctx, x):
| >>> ctx.set_materialize_grads(False)
| >>> ctx.save_for_backward(x)
| >>> return x.clone(), x.clone()
| >>>
| >>> @staticmethod
| >>> @once_differentiable
| >>> def backward(ctx, g1, g2):
| >>> x, = ctx.saved_tensors
| >>> grad_input = torch.zeros_like(x)
| >>> if g1 is not None: # We must check for None now
| >>> grad_input += g1
| >>> if g2 is not None:
| >>> grad_input += g2
| >>> return grad_input
| >>>
| >>> a = torch.tensor(1., requires_grad=True)
| >>> b, _ = Func.apply(a) # induces g2 to be undefined
class NestedIOFunction(Function)
| NestedIOFunction(*args, **kwargs)
|
| This class is here only for backward compatibility reasons.
| Use :class:`Function` instead of this for any new use case.
|
| Method resolution order:
| NestedIOFunction
| Function
| _SingleLevelFunction
| torch._C._FunctionBase
| FunctionCtx
| _HookMixin
| builtins.object
|
| Methods defined here:
|
| __call__ = _do_forward(self, *input)
|
| backward(self, *gradients: Any) -> Any
| Shared backward utility.
|
| backward_extended(self, *grad_output: Any) -> None
| User defined backward.
|
| forward(self, *args: Any) -> Any
| Shared forward utility.
|
| forward_extended(self, *input: Any) -> None
| User defined forward.
|
| mark_dirty(self, *args: Any, **kwargs: Any) -> None
| See :meth:`Function.mark_dirty`.
|
| mark_non_differentiable(self, *args: Any, **kwargs: Any) -> None
| See :meth:`Function.mark_non_differentiable`.
|
| save_for_backward(self, *args: Any) -> None
| See :meth:`Function.save_for_backward`.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| saved_tensors
| See :meth:`Function.saved_tensors`.
|
| ----------------------------------------------------------------------
| Methods inherited from Function:
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Class methods inherited from Function:
|
| apply(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Static methods inherited from Function:
|
| vmap(info, in_dims, *args)
| Define the behavior for this autograd.Function underneath :func:`torch.vmap`.
|
| For a :func:`torch.autograd.Function` to support
| :func:`torch.vmap`, you must either override this static method, or set
| ``generate_vmap_rule`` to ``True`` (you may not do both).
|
| If you choose to override this staticmethod: it must accept
|
| - an ``info`` object as the first argument. ``info.batch_size``
| specifies the size of the dimension being vmapped over,
| while ``info.randomness`` is the randomness option passed to
| :func:`torch.vmap`.
| - an ``in_dims`` tuple as the second argument.
| For each arg in ``args``, ``in_dims`` has a corresponding
| ``Optional[int]``. It is ``None`` if the arg is not a Tensor or if
| the arg is not being vmapped over, otherwise, it is an integer
| specifying what dimension of the Tensor is being vmapped over.
| - ``*args``, which is the same as the args to :meth:`~Function.forward`.
|
| The return of the vmap staticmethod is a tuple of ``(output, out_dims)``.
| Similar to ``in_dims``, ``out_dims`` should be of the same structure as
| ``output`` and contain one ``out_dim`` per output that specifies if the
| output has the vmapped dimension and what index it is in.
|
| Please see :ref:`func-autograd-function` for more details.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Function:
|
| generate_vmap_rule = False
|
| ----------------------------------------------------------------------
| Static methods inherited from _SingleLevelFunction:
|
| jvp(ctx: Any, *grad_inputs: Any) -> Any
| Define a formula for differentiating the operation with forward mode automatic differentiation.
|
| This function is to be overridden by all subclasses.
| It must accept a context :attr:`ctx` as the first argument, followed by
| as many inputs as the :func:`forward` got (None will be passed in
| for non tensor inputs of the forward function),
| and it should return as many tensors as there were outputs to
| :func:`forward`. Each argument is the gradient w.r.t the given input,
| and each returned value should be the gradient w.r.t. the
| corresponding output. If an output is not a Tensor or the function is not
| differentiable with respect to that output, you can just pass None as a
| gradient for that input.
|
| You can use the :attr:`ctx` object to pass any value from the forward to this
| functions.
|
| setup_context(ctx: Any, inputs: tuple[typing.Any, ...], output: Any) -> Any
| There are two ways to define the forward pass of an autograd.Function.
|
| Either:
|
| 1. Override forward with the signature ``forward(ctx, *args, **kwargs)``.
| ``setup_context`` is not overridden. Setting up the ctx for backward
| happens inside the ``forward``.
| 2. Override forward with the signature ``forward(*args, **kwargs)`` and
| override ``setup_context``. Setting up the ctx for backward happens
| inside ``setup_context`` (as opposed to inside the ``forward``)
|
| See :meth:`torch.autograd.Function.forward` and :ref:`extending-autograd` for more details.
|
| vjp = backward(ctx: Any, *grad_outputs: Any) -> Any
| Define a formula for differentiating the operation with backward mode automatic differentiation.
|
| This function is to be overridden by all subclasses.
| (Defining this function is equivalent to defining the ``vjp`` function.)
|
| It must accept a context :attr:`ctx` as the first argument, followed by
| as many outputs as the :func:`forward` returned (None will be passed in
| for non tensor outputs of the forward function),
| and it should return as many tensors, as there were inputs to
| :func:`forward`. Each argument is the gradient w.r.t the given output,
| and each returned value should be the gradient w.r.t. the
| corresponding input. If an input is not a Tensor or is a Tensor not
| requiring grads, you can just pass None as a gradient for that input.
|
| The context can be used to retrieve tensors saved during the forward
| pass. It also has an attribute :attr:`ctx.needs_input_grad` as a tuple
| of booleans representing whether each input needs gradient. E.g.,
| :func:`backward` will have ``ctx.needs_input_grad[0] = True`` if the
| first input to :func:`forward` needs gradient computed w.r.t. the
| output.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _SingleLevelFunction:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from _SingleLevelFunction:
|
| boxed_grads_call = False
|
| clear_saved_tensors_on_access = False
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C._FunctionBase:
|
| maybe_clear_saved_tensors(...)
|
| name(...)
|
| register_hook(...)
|
| register_prehook(...)
|
| ----------------------------------------------------------------------
| Static methods inherited from torch._C._FunctionBase:
|
| __new__(*args, **kwargs) class method of torch._C._FunctionBase
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C._FunctionBase:
|
| dirty_tensors
|
| materialize_grads
|
| metadata
|
| needs_input_grad
|
| next_functions
|
| non_differentiable
|
| requires_grad
|
| saved_for_forward
|
| saved_variables
|
| to_save
|
| ----------------------------------------------------------------------
| Methods inherited from FunctionCtx:
|
| mark_shared_storage(self, *pairs)
|
| save_for_forward(self, *tensors: torch.Tensor)
| Save given tensors for a future call to :func:`~Function.jvp`.
|
| ``save_for_forward`` should be called at most once, in either the
| :func:`setup_context` or :func:`forward` methods, and all arguments
| should be tensors.
|
| In :func:`jvp`, saved objects can be accessed through the :attr:`saved_tensors`
| attribute.
|
| Arguments can also be ``None``. This is a no-op.
|
| See :ref:`extending-autograd` for more details on how to use this method.
|
| Example::
|
| >>> # xdoctest: +SKIP
| >>> class Func(torch.autograd.Function):
| >>> @staticmethod
| >>> def forward(ctx, x: torch.Tensor, y: torch.Tensor, z: int):
| >>> ctx.save_for_backward(x, y)
| >>> ctx.save_for_forward(x, y)
| >>> ctx.z = z
| >>> return x * y * z
| >>>
| >>> @staticmethod
| >>> def jvp(ctx, x_t, y_t, _):
| >>> x, y = ctx.saved_tensors
| >>> z = ctx.z
| >>> return z * (y * x_t + x * y_t)
| >>>
| >>> @staticmethod
| >>> def vjp(ctx, grad_out):
| >>> x, y = ctx.saved_tensors
| >>> z = ctx.z
| >>> return z * grad_out * y, z * grad_out * x, None
| >>>
| >>> a = torch.tensor(1., requires_grad=True, dtype=torch.double)
| >>> t = torch.tensor(1., dtype=torch.double)
| >>> b = torch.tensor(2., requires_grad=True, dtype=torch.double)
| >>> c = 4
| >>>
| >>> with fwAD.dual_level():
| >>> a_dual = fwAD.make_dual(a, t)
| >>> d = Func.apply(a_dual, b, c)
|
| set_materialize_grads(self, value: bool)
| Set whether to materialize grad tensors. Default is ``True``.
|
| This should be called only from either the :func:`setup_context` or
| :func:`forward` methods.
|
| If ``True``, undefined grad tensors will be expanded to tensors full of zeros
| prior to calling the :func:`backward` and :func:`jvp` methods.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_AUTOGRAD)
| >>> class SimpleFunc(Function):
| >>> @staticmethod
| >>> def forward(ctx, x):
| >>> return x.clone(), x.clone()
| >>>
| >>> @staticmethod
| >>> @once_differentiable
| >>> def backward(ctx, g1, g2):
| >>> return g1 + g2 # No check for None necessary
| >>>
| >>> # We modify SimpleFunc to handle non-materialized grad outputs
| >>> class Func(Function):
| >>> @staticmethod
| >>> def forward(ctx, x):
| >>> ctx.set_materialize_grads(False)
| >>> ctx.save_for_backward(x)
| >>> return x.clone(), x.clone()
| >>>
| >>> @staticmethod
| >>> @once_differentiable
| >>> def backward(ctx, g1, g2):
| >>> x, = ctx.saved_tensors
| >>> grad_input = torch.zeros_like(x)
| >>> if g1 is not None: # We must check for None now
| >>> grad_input += g1
| >>> if g2 is not None:
| >>> grad_input += g2
| >>> return grad_input
| >>>
| >>> a = torch.tensor(1., requires_grad=True)
| >>> b, _ = Func.apply(a) # induces g2 to be undefined
class Variable(torch._C._LegacyVariableBase)
| Method resolution order:
| Variable
| torch._C._LegacyVariableBase
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from torch._C._LegacyVariableBase:
|
| __new__(*args, **kwargs) class method of torch._C._LegacyVariableBase
| Create and return a new object. See help(type) for accurate signature.
class detect_anomaly(builtins.object)
| detect_anomaly(check_nan=True) -> None
|
| Context-manager that enable anomaly detection for the autograd engine.
|
| This does two things:
|
| - Running the forward pass with detection enabled will allow the backward
| pass to print the traceback of the forward operation that created the failing
| backward function.
| - If ``check_nan`` is ``True``, any backward computation that generate "nan"
| value will raise an error. Default ``True``.
|
| .. warning::
| This mode should be enabled only for debugging as the different tests
| will slow down your program execution.
|
| Example:
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_ANOMALY)
| >>> import torch
| >>> from torch import autograd
| >>> class MyFunc(autograd.Function):
| ... @staticmethod
| ... def forward(ctx, inp):
| ... return inp.clone()
| ...
| ... @staticmethod
| ... def backward(ctx, gO):
| ... # Error during the backward pass
| ... raise RuntimeError("Some error in backward")
| ... return gO.clone()
| >>> def run_fn(a):
| ... out = MyFunc.apply(a)
| ... return out.sum()
| >>> inp = torch.rand(10, 10, requires_grad=True)
| >>> out = run_fn(inp)
| >>> out.backward()
| Traceback (most recent call last):
| File "<stdin>", line 1, in <module>
| File "/your/pytorch/install/torch/_tensor.py", line 93, in backward
| torch.autograd.backward(self, gradient, retain_graph, create_graph)
| File "/your/pytorch/install/torch/autograd/__init__.py", line 90, in backward
| allow_unreachable=True) # allow_unreachable flag
| File "/your/pytorch/install/torch/autograd/function.py", line 76, in apply
| return self._forward_cls.backward(self, *args)
| File "<stdin>", line 8, in backward
| RuntimeError: Some error in backward
| >>> with autograd.detect_anomaly():
| ... inp = torch.rand(10, 10, requires_grad=True)
| ... out = run_fn(inp)
| ... out.backward()
| Traceback of forward call that caused the error:
| File "tmp.py", line 53, in <module>
| out = run_fn(inp)
| File "tmp.py", line 44, in run_fn
| out = MyFunc.apply(a)
| Traceback (most recent call last):
| File "<stdin>", line 4, in <module>
| File "/your/pytorch/install/torch/_tensor.py", line 93, in backward
| torch.autograd.backward(self, gradient, retain_graph, create_graph)
| File "/your/pytorch/install/torch/autograd/__init__.py", line 90, in backward
| allow_unreachable=True) # allow_unreachable flag
| File "/your/pytorch/install/torch/autograd/function.py", line 76, in apply
| return self._forward_cls.backward(self, *args)
| File "<stdin>", line 8, in backward
| RuntimeError: Some error in backward
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, *args: object) -> None
|
| __init__(self, check_nan=True) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class enable_grad(torch.utils._contextlib._NoParamDecoratorContextManager)
| enable_grad(orig_func: Optional[~F] = None) -> Union[Self, ~F]
|
| Context-manager that enables gradient calculation.
|
| Enables gradient calculation, if it has been disabled via :class:`~no_grad`
| or :class:`~set_grad_enabled`.
|
| This context manager is thread local; it will not affect computation
| in other threads.
|
| Also functions as a decorator.
|
| .. note::
| enable_grad is one of several mechanisms that can enable or
| disable gradients locally see :ref:`locally-disable-grad-doc` for
| more information on how they compare.
|
| .. note::
| This API does not apply to :ref:`forward-mode AD <forward-mode-ad>`.
|
| Example::
| >>> # xdoctest: +SKIP
| >>> x = torch.tensor([1.], requires_grad=True)
| >>> with torch.no_grad():
| ... with torch.enable_grad():
| ... y = x * 2
| >>> y.requires_grad
| True
| >>> y.backward()
| >>> x.grad
| tensor([2.])
| >>> @torch.enable_grad()
| ... def doubler(x):
| ... return x * 2
| >>> with torch.no_grad():
| ... z = doubler(x)
| >>> z.requires_grad
| True
| >>> @torch.enable_grad()
| ... def tripler(x):
| ... return x * 3
| >>> with torch.no_grad():
| ... z = tripler(x)
| >>> z.requires_grad
| True
|
| Method resolution order:
| enable_grad
| torch.utils._contextlib._NoParamDecoratorContextManager
| torch.utils._contextlib._DecoratorContextManager
| builtins.object
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.utils._contextlib._NoParamDecoratorContextManager:
|
| __new__(cls, orig_func: Optional[~F] = None) -> Union[Self, ~F]
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __call__(self, orig_func: ~F) -> ~F
| Call self as a function.
|
| clone(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class enforce_grad_layout_policy(torch.utils._contextlib._DecoratorContextManager)
| enforce_grad_layout_policy(enable: bool = True) -> None
|
| Context-manager that controls the gradient layout policy enforcement.
|
| The gradient layout contract ensures that accumulated gradients have
| strides matching their corresponding parameters (for non-overlapping
| dense parameters) or are row-major contiguous (otherwise). This aids
| performance in optimizers and distributed reducers.
|
| When ``enable=False``, the autograd engine relaxes this enforcement:
|
| - Stealable gradients whose layout does *not* match the parameter can
| still be stolen directly (avoiding an extra copy).
| - The "grad and param do not obey the gradient layout contract" warning
| is suppressed.
|
| The logic that *creates* a brand-new gradient (e.g., cloning into the
| correct layout when the gradient is not stealable) is **not** affected
| by this flag.
|
| This can be used as a context-manager or as a function. It is
| thread-local and will not affect computation in other threads.
|
| Args:
| enable (bool): Whether to enforce the gradient layout contract
| (``True``, default) or relax enforcement (``False``).
|
| Example::
| >>> # xdoctest: +SKIP
| >>> import torch
| >>> p = torch.empty(2, 3, 4).permute(2, 0, 1).requires_grad_()
| >>> with torch.autograd.enforce_grad_layout_policy(False):
| ... (p * 2).sum().backward()
| ... # p.grad may now have the same strides as the incoming
| ... # gradient rather than being forced to match p's strides.
|
| Method resolution order:
| enforce_grad_layout_policy
| torch.utils._contextlib._DecoratorContextManager
| builtins.object
|
| Methods defined here:
|
| __call__(self, orig_func: ~F) -> ~F
| Call self as a function.
|
| __enter__(self) -> None
|
| __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None
|
| __init__(self, enable: bool = True) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| clone(self) -> 'enforce_grad_layout_policy'
| Create a copy of this class
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class inference_mode(torch.utils._contextlib._DecoratorContextManager)
| inference_mode(mode=True)
|
| Context manager that enables or disables inference mode.
|
| InferenceMode is analogous to :class:`~no_grad` and should be used
| when you are certain your operations will not interact with autograd
| (e.g., during data loading or model evaluation). Compared to
| :class:`~no_grad`, it removes additional overhead by disabling view
| tracking and version counter bumps. It is also more restrictive, in
| that tensors created in this mode cannot be used in computations
| recorded by autograd.
|
| This context manager is thread-local; it does not affect computation
| in other threads.
|
| Also functions as a decorator.
|
| .. note::
| Inference mode is one of several mechanisms that can locally enable
| or disable gradients. See :ref:`locally-disable-grad-doc` for a
| comparison. If avoiding the use of tensors created in inference mode
| in autograd-tracked regions is difficult, consider benchmarking your
| code with and without inference mode to weigh the performance benefits
| against the trade-offs. You can always use :class:`~no_grad` instead.
|
| .. note::
| Unlike some other mechanisms that locally enable or disable grad,
| entering inference_mode also disables :ref:`forward-mode AD <forward-mode-ad>`.
|
| .. warning::
| `inference_mode` does NOT automatically set the model to evaluation mode.
| For proper inference behavior (e.g., disabling dropout, using running statistics
| in batch normalization), you must explicitly set your model to evaluation mode using
| `model.eval()` in addition to using this context manager.
|
| Args:
| mode (bool or function): Either a boolean flag to enable or disable
| inference mode, or a Python function to decorate with inference
| mode enabled.
|
| Example::
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_AUTOGRAD)
| >>> import torch
| >>> x = torch.ones(1, 2, 3, requires_grad=True)
| >>> with torch.inference_mode():
| ... y = x * x
| >>> y.requires_grad
| False
| >>> # xdoctest: +SKIP("want string isn't quite right")
| >>> y._version
| Traceback (most recent call last):
| File "<stdin>", line 1, in <module>
| RuntimeError: Inference tensors do not track version counter.
| >>> @torch.inference_mode()
| ... def func(x):
| ... return x * x
| >>> out = func(x)
| >>> out.requires_grad
| False
| >>> @torch.inference_mode()
| ... def doubler(x):
| ... return x * 2
| >>> out = doubler(x)
| >>> out.requires_grad
| False
|
| Method resolution order:
| inference_mode
| torch.utils._contextlib._DecoratorContextManager
| builtins.object
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None
|
| __init__(self, mode: bool = True) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| clone(self) -> 'inference_mode'
| Create a copy of this class
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, mode=True)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __call__(self, orig_func: ~F) -> ~F
| Call self as a function.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class no_grad(torch.utils._contextlib._NoParamDecoratorContextManager)
| no_grad() -> None
|
| Context-manager that disables gradient calculation.
|
| Disabling gradient calculation is useful for inference, when you are sure
| that you will not call :meth:`Tensor.backward()`. It will reduce memory
| consumption for computations that would otherwise have `requires_grad=True`.
|
| In this mode, the result of every computation will have
| `requires_grad=False`, even when the inputs have `requires_grad=True`.
| There is an exception! All factory functions, or functions that create
| a new Tensor and take a requires_grad kwarg, will NOT be affected by
| this mode.
|
| This context manager is thread local; it will not affect computation
| in other threads.
|
| Also functions as a decorator.
|
| .. note::
| No-grad is one of several mechanisms that can enable or
| disable gradients locally see :ref:`locally-disable-grad-doc` for
| more information on how they compare.
|
| .. note::
| This API does not apply to :ref:`forward-mode AD <forward-mode-ad>`.
| If you want to disable forward AD for a computation, you can unpack
| your dual tensors.
|
| Example::
| >>> # xdoctest: +SKIP
| >>> x = torch.tensor([1.], requires_grad=True)
| >>> with torch.no_grad():
| ... y = x * 2
| >>> y.requires_grad
| False
| >>> @torch.no_grad()
| ... def doubler(x):
| ... return x * 2
| >>> z = doubler(x)
| >>> z.requires_grad
| False
| >>> @torch.no_grad()
| ... def tripler(x):
| ... return x * 3
| >>> z = tripler(x)
| >>> z.requires_grad
| False
| >>> # factory function exception
| >>> with torch.no_grad():
| ... a = torch.nn.Parameter(torch.rand(10))
| >>> a.requires_grad
| True
|
| Method resolution order:
| no_grad
| torch.utils._contextlib._NoParamDecoratorContextManager
| torch.utils._contextlib._DecoratorContextManager
| builtins.object
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None
|
| __init__(self) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.utils._contextlib._NoParamDecoratorContextManager:
|
| __new__(cls, orig_func: Optional[~F] = None) -> Union[Self, ~F]
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __call__(self, orig_func: ~F) -> ~F
| Call self as a function.
|
| clone(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class set_detect_anomaly(builtins.object)
| set_detect_anomaly(mode: bool, check_nan: bool = True) -> None
|
| Context-manager that sets the anomaly detection for the autograd engine on or off.
|
| ``set_detect_anomaly`` will enable or disable the autograd anomaly detection
| based on its argument :attr:`mode`.
| It can be used as a context-manager or as a function.
|
| See ``detect_anomaly`` above for details of the anomaly detection behaviour.
|
| Args:
| mode (bool): Flag whether to enable anomaly detection (``True``),
| or disable (``False``).
| check_nan (bool): Flag whether to raise an error when the backward
| generate "nan"
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, *args: object) -> None
|
| __init__(self, mode: bool, check_nan: bool = True) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class set_grad_enabled(torch.utils._contextlib._DecoratorContextManager)
| set_grad_enabled(mode: bool) -> None
|
| Context-manager that sets gradient calculation on or off.
|
| ``set_grad_enabled`` will enable or disable grads based on its argument :attr:`mode`.
| It can be used as a context-manager or as a function.
|
| This context manager is thread local; it will not affect computation
| in other threads.
|
| Args:
| mode (bool): Flag whether to enable grad (``True``), or disable
| (``False``). This can be used to conditionally enable
| gradients.
|
| .. note::
| set_grad_enabled is one of several mechanisms that can enable or
| disable gradients locally see :ref:`locally-disable-grad-doc` for
| more information on how they compare.
|
| .. note::
| This API does not apply to :ref:`forward-mode AD <forward-mode-ad>`.
|
| Example::
| >>> # xdoctest: +SKIP
| >>> x = torch.tensor([1.], requires_grad=True)
| >>> is_train = False
| >>> with torch.set_grad_enabled(is_train):
| ... y = x * 2
| >>> y.requires_grad
| False
| >>> _ = torch.set_grad_enabled(True)
| >>> y = x * 2
| >>> y.requires_grad
| True
| >>> _ = torch.set_grad_enabled(False)
| >>> y = x * 2
| >>> y.requires_grad
| False
|
| Method resolution order:
| set_grad_enabled
| torch.utils._contextlib._DecoratorContextManager
| builtins.object
|
| Methods defined here:
|
| __call__(self, orig_func: ~F) -> ~F
| Call self as a function.
|
| __enter__(self) -> None
|
| __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None
|
| __init__(self, mode: bool) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self) -> str
| Return repr(self).
|
| __str__(self) -> str
| Return str(self).
|
| clone(self) -> 'set_grad_enabled'
| Create a copy of this class
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class set_multithreading_enabled(torch.utils._contextlib._DecoratorContextManager)
| set_multithreading_enabled(mode: bool) -> None
|
| Context-manager that enables or disables multithreaded backward.
|
| Ordinarily, when :ref:`accelerator<accelerators>` devices are in use,
| the backward pass runs on device-specific worker threads. The engine
| creates these threads based on the number of available devices and
| reuses them across iterations.
|
| When ``mode=False``, the backward pass runs on the calling thread
| instead. ``mode=True`` restores the default behavior.
|
| This can be used as a context-manager or as a function. It is
| thread-local and will not affect computation in other threads.
|
| Args:
| mode (bool): Whether to enable multithreaded backward (``True``,
| default) or disable (``False``).
|
| .. note::
| This API does not apply to :ref:`forward-mode AD <forward-mode-ad>`,
| which never uses multithreading.
|
| Method resolution order:
| set_multithreading_enabled
| torch.utils._contextlib._DecoratorContextManager
| builtins.object
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None
|
| __init__(self, mode: bool) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| clone(self) -> 'set_multithreading_enabled'
| Create a copy of this class
|
| ----------------------------------------------------------------------
| Methods inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __call__(self, orig_func: ~F) -> ~F
| Call self as a function.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
backward(tensors: Union[torch.Tensor, collections.abc.Sequence[torch.Tensor], ForwardRef('GradientEdge'), collections.abc.Sequence['GradientEdge']], grad_tensors: torch.Tensor | collections.abc.Sequence[torch.Tensor | None] | None = None, retain_graph: bool | None = None, create_graph: bool = False, grad_variables: torch.Tensor | collections.abc.Sequence[torch.Tensor | None] | None = None, inputs: Union[torch.Tensor, collections.abc.Sequence[torch.Tensor], ForwardRef('GradientEdge'), collections.abc.Sequence['GradientEdge'], dict[str, torch.Tensor], NoneType] = None) -> None
Compute the sum of gradients of given tensors with respect to graph leaves.
The graph is differentiated using the chain rule. If any of ``tensors``
are non-scalar (i.e. their data has more than one element) and require
gradient, then the Jacobian-vector product would be computed, in this
case the function additionally requires specifying ``grad_tensors``.
It should be a sequence of matching length, that contains the "vector"
in the Jacobian-vector product, usually the gradient of the differentiated
function w.r.t. corresponding tensors (``None`` is an acceptable value for
all tensors that don't need gradient tensors).
This function accumulates gradients in the leaves - you might need to zero
``.grad`` attributes or set them to ``None`` before calling it.
See :ref:`Default gradient layouts<default-grad-layouts>`
for details on the memory layout of accumulated gradients.
.. note::
Using this method with ``create_graph=True`` will create a reference cycle
between the parameter and its gradient which can cause a memory leak.
We recommend using ``autograd.grad`` when creating the graph to avoid this.
If you have to use this function, make sure to reset the ``.grad`` fields of your
parameters to ``None`` after use to break the cycle and avoid the leak.
.. note::
If you run any forward ops, create ``grad_tensors``, and/or call ``backward``
in a user-specified CUDA stream context, see
:ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
.. note::
When ``inputs`` are provided and a given input is not a leaf,
the current implementation will call its grad_fn (even though it is not strictly needed to get these gradients).
It is an implementation detail on which the user should not rely.
See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
Args:
tensors (Sequence[Tensor] or Tensor or Sequence[GradientEdge] or GradientEdge): Tensors of which
the derivative will be computed.
grad_tensors (Sequence[Tensor or None] or Tensor, optional): The "vector" in
the Jacobian-vector product, usually gradients w.r.t. each element of
corresponding tensors. None values can be specified for scalar Tensors or
ones that don't require grad. If a None value would be acceptable for all
grad_tensors, then this argument is optional.
retain_graph (bool, optional): If ``False``, the graph used to compute the grad
will be freed. Note that in nearly all cases setting this option to ``True``
is not needed and often can be worked around in a much more efficient
way. Defaults to the value of ``create_graph``.
create_graph (bool, optional): If ``True``, graph of the derivative will
be constructed, allowing to compute higher order derivative products.
Defaults to ``False``.
inputs (Sequence[Tensor] or Tensor or Sequence[GradientEdge] or dict[str, Tensor], optional):
Inputs w.r.t. which the gradient will be accumulated into ``.grad``.
All other Tensors will be ignored. If not provided, the gradient is
accumulated into all the leaf Tensors that were used to compute the
:attr:`tensors`. A dict of tensors (e.g.
``dict(model.named_parameters())``) is also accepted, in which case
the values are used as the input tensors.
grad(outputs: Union[torch.Tensor, collections.abc.Sequence[torch.Tensor], ForwardRef('GradientEdge'), collections.abc.Sequence['GradientEdge']], inputs: Union[torch.Tensor, collections.abc.Sequence[torch.Tensor], ForwardRef('GradientEdge'), collections.abc.Sequence['GradientEdge'], dict[str, torch.Tensor]], grad_outputs: torch.Tensor | collections.abc.Sequence[torch.Tensor | None] | None = None, retain_graph: bool | None = None, create_graph: bool = False, only_inputs: bool = True, allow_unused: bool | None = None, is_grads_batched: bool = False, materialize_grads: bool = False) -> tuple[torch.Tensor, ...] | dict[str, torch.Tensor]
Compute and return the sum of gradients of outputs with respect to the inputs.
``grad_outputs`` should be a sequence of length matching ``output``
containing the "vector" in vector-Jacobian product, usually the pre-computed
gradients w.r.t. each of the outputs. If an output doesn't require_grad,
then the gradient can be ``None``).
.. note::
If you run any forward ops, create ``grad_outputs``, and/or call ``grad``
in a user-specified CUDA stream context, see
:ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
.. note::
``only_inputs`` argument is deprecated and is ignored now (defaults to ``True``).
To accumulate gradient for other parts of the graph, please use
``torch.autograd.backward``.
Args:
outputs (sequence of Tensor or GradientEdge): outputs of the differentiated function.
inputs (sequence of Tensor or GradientEdge or dict[str, Tensor]): Inputs w.r.t. which
the gradient will be returned (and not accumulated into ``.grad``).
When a dict is provided (e.g. ``dict(model.named_parameters())``),
the result is returned as a dict with matching keys.
grad_outputs (sequence of [Tensor or None] or Tensor, optional): The "vector" in the
vector-Jacobian product. Usually gradients w.r.t. each output. None values can be
specified for scalar Tensors or ones that don't require grad. If a None value would be
acceptable for all grad_tensors, then this argument is optional. Default: None.
retain_graph (bool, optional): If ``False``, the graph used to compute the grad
will be freed. Note that in nearly all cases setting this option to ``True``
is not needed and often can be worked around in a much more efficient
way. Defaults to the value of ``create_graph``.
create_graph (bool, optional): If ``True``, graph of the derivative will
be constructed, allowing to compute higher order derivative products.
Default: ``False``.
allow_unused (Optional[bool], optional): If ``False``, specifying inputs
that were not used when computing outputs (and therefore their grad is
always zero) is an error. Defaults to the value of ``materialize_grads``.
is_grads_batched (bool, optional): If ``True``, the first dimension of each
tensor in ``grad_outputs`` will be interpreted as the batch dimension.
Instead of computing a single vector-Jacobian product, we compute a
batch of vector-Jacobian products for each "vector" in the batch.
We use the vmap prototype feature as the backend to vectorize calls
to the autograd engine so that this computation can be performed in a
single call. This should lead to performance improvements when compared
to manually looping and performing backward multiple times. Note that
due to this feature being experimental, there may be performance
cliffs. Please use ``torch._C._debug_only_display_vmap_fallback_warnings(True)``
to show any performance warnings and file an issue on github if warnings exist
for your use case. Defaults to ``False``.
materialize_grads (bool, optional): If ``True``, set the gradient for unused inputs
to zero instead of None. This is useful when computing higher-order derivatives.
If ``materialize_grads`` is ``True`` and ``allow_unused`` is ``False``, an error
will be raised. Defaults to ``False``.
gradcheck(func: collections.abc.Callable[..., torch.Tensor | collections.abc.Sequence[torch.Tensor]], inputs: torch.Tensor | collections.abc.Sequence[torch.Tensor], *, eps: float = 1e-06, atol: float = 1e-05, rtol: float = 0.001, raise_exception: bool = True, nondet_tol: float = 0.0, check_undefined_grad: bool = True, check_grad_dtypes: bool = False, check_batched_grad: bool = False, check_batched_forward_grad: bool = False, check_forward_ad: bool = False, check_backward_ad: bool = True, fast_mode: bool = False, masked: bool | None = None) -> bool
Check gradients computed via small finite differences against analytical
gradients wrt tensors in :attr:`inputs` that are of floating point or complex type
and with ``requires_grad=True``.
The check between numerical and analytical gradients uses :func:`~torch.allclose`.
For most of the complex functions we consider for optimization purposes, no notion of
Jacobian exists. Instead, gradcheck verifies if the numerical and analytical values of
the Wirtinger and Conjugate Wirtinger derivatives are consistent. Because the gradient
computation is done under the assumption that the overall function has a real-valued
output, we treat functions with complex output in a special way. For these functions,
gradcheck is applied to two real-valued functions corresponding to taking the real
components of the complex outputs for the first, and taking the imaginary components
of the complex outputs for the second. For more details, check out
:ref:`complex_autograd-doc`.
.. note::
The default values are designed for :attr:`input` of double precision.
This check will likely fail if :attr:`input` is of less precision, e.g.,
``FloatTensor``.
.. note::
Gradcheck may fail when evaluated on non-differentiable points
because the numerically computed gradients via finite differencing may differ
those computed analytically (not necessarily because either is incorrect).
For more context, see :ref:`non-differentiable-func-grad`.
.. warning::
If any checked tensor in :attr:`input` has overlapping memory, i.e.,
different indices pointing to the same memory address (e.g., from
:func:`torch.Tensor.expand`), this check will likely fail because the numerical
gradients computed by point perturbation at such indices will change
values at all other indices that share the same memory address.
Args:
func (function): a Python function that takes Tensor inputs and returns
a Tensor or a tuple of Tensors
inputs (tuple of Tensor or Tensor): inputs to the function
eps (float, optional): perturbation for finite differences
atol (float, optional): absolute tolerance
rtol (float, optional): relative tolerance
raise_exception (bool, optional): indicating whether to raise an exception if
the check fails. The exception gives more information about the
exact nature of the failure. This is helpful when debugging gradchecks.
nondet_tol (float, optional): tolerance for non-determinism. When running
identical inputs through the differentiation, the results must either match
exactly (default, 0.0) or be within this tolerance.
check_undefined_grad (bool, optional): if ``True``, check if undefined output grads
are supported and treated as zeros, for ``Tensor`` outputs.
check_batched_grad (bool, optional): if ``True``, check if we can compute
batched gradients using prototype vmap support. Defaults to False.
check_batched_forward_grad (bool, optional): if ``True``, checks if we can compute
batched forward gradients using forward ad and prototype vmap support. Defaults to ``False``.
check_forward_ad (bool, optional): if ``True``, check that the gradients computed with forward
mode AD match the numerical ones. Defaults to ``False``.
check_backward_ad (bool, optional): if ``False``, do not perform any checks that rely on
backward mode AD to be implemented. Defaults to ``True``.
fast_mode (bool, optional): Fast mode for gradcheck and gradgradcheck is currently only
implemented for R to R functions. If none of the inputs and outputs are complex
a faster implementation of gradcheck that no longer computes the entire jacobian
is run; otherwise, we fall back to the slow implementation.
masked (bool, optional): if ``True``, the gradients of unspecified elements of
sparse tensors are ignored. Defaults to ``False``.
Returns:
``True`` if all differences satisfy allclose condition
gradgradcheck(func: collections.abc.Callable[..., torch.Tensor | collections.abc.Sequence[torch.Tensor]], inputs: torch.Tensor | collections.abc.Sequence[torch.Tensor], grad_outputs: torch.Tensor | collections.abc.Sequence[torch.Tensor | None] | None = None, *, eps: float = 1e-06, atol: float = 1e-05, rtol: float = 0.001, gen_non_contig_grad_outputs: bool = False, raise_exception: bool = True, nondet_tol: float = 0.0, check_undefined_grad: bool = True, check_grad_dtypes: bool = False, check_batched_grad: bool = False, check_fwd_over_rev: bool = False, check_rev_over_rev: bool = True, fast_mode: bool = False, masked: bool = False) -> bool
Check gradients of gradients computed via small finite differences
against analytical gradients wrt tensors in :attr:`inputs` and
:attr:`grad_outputs` that are of floating point or complex type and with
``requires_grad=True``.
This function checks that backpropagating through the gradients computed
to the given :attr:`grad_outputs` are correct.
The check between numerical and analytical gradients uses :func:`~torch.allclose`.
.. note::
The default values are designed for :attr:`input` and
:attr:`grad_outputs` of double precision. This check will likely fail if
they are of less precision, e.g., ``FloatTensor``.
.. warning::
If any checked tensor in :attr:`input` and :attr:`grad_outputs` has
overlapping memory, i.e., different indices pointing to the same memory
address (e.g., from :func:`torch.Tensor.expand`), this check will likely fail
because the numerical gradients computed by point perturbation at such
indices will change values at all other indices that share the same
memory address.
Args:
func (function): a Python function that takes Tensor inputs and returns
a Tensor or a tuple of Tensors
inputs (tuple of Tensor or Tensor): inputs to the function
grad_outputs (tuple of [Tensor or None] or Tensor, optional): The gradients with
respect to the function's outputs.
eps (float, optional): perturbation for finite differences
atol (float, optional): absolute tolerance
rtol (float, optional): relative tolerance
gen_non_contig_grad_outputs (bool, optional): if :attr:`grad_outputs` is
``None`` and :attr:`gen_non_contig_grad_outputs` is ``True``, the
randomly generated gradient outputs are made to be noncontiguous
raise_exception (bool, optional): indicating whether to raise an exception if
the check fails. The exception gives more information about the
exact nature of the failure. This is helpful when debugging gradchecks.
nondet_tol (float, optional): tolerance for non-determinism. When running
identical inputs through the differentiation, the results must either match
exactly (default, 0.0) or be within this tolerance. Note that a small amount
of nondeterminism in the gradient will lead to larger inaccuracies in
the second derivative.
check_undefined_grad (bool, optional): if True, check if undefined output grads
are supported and treated as zeros
check_batched_grad (bool, optional): if True, check if we can compute
batched gradients using prototype vmap support. Defaults to False.
fast_mode (bool, optional): if True, run a faster implementation of gradgradcheck that
no longer computes the entire jacobian.
masked (bool, optional): if True, the gradients of unspecified elements of
sparse tensors are ignored (default, False).
Returns:
True if all differences satisfy allclose condition
variable(*args, **kwargs)
DATA
__all__ = ['Variable', 'Function', 'backward', 'grad_mode', 'NestedIOF...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\autograd\__init__.py
torch.avg_pool1d
Python Library Documentation: built-in function avg_pool1d in module torch
avg_pool1d(...)
avg_pool1d(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True) -> Tensor
Applies a 1D average pooling over an input signal composed of several
input planes.
See :class:`~torch.nn.AvgPool1d` for details and output shape.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iW)`
kernel_size: the size of the window. Can be a single number or a
tuple `(kW,)`
stride: the stride of the window. Can be a single number or a tuple
`(sW,)`. Default: :attr:`kernel_size`
padding: implicit zero paddings on both sides of the input. Can be a single
number or a tuple `(padW,)`. Should be at most half of effective kernel
size, that is :math:`((kernelSize - 1) * dilation + 1) / 2`. Default: 0
ceil_mode: when True, will use `ceil` instead of `floor` to compute the
output shape. Default: ``False``
count_include_pad: when True, will include the zero-padding in the
averaging calculation. Default: ``True``
Examples::
>>> # pool of square window of size=3, stride=2
>>> input = torch.tensor([[[1, 2, 3, 4, 5, 6, 7]]], dtype=torch.float32)
>>> F.avg_pool1d(input, kernel_size=3, stride=2)
tensor([[[ 2., 4., 6.]]])
torch.backends
Python Library Documentation: package torch.backends in torch
NAME
torch.backends - # mypy: allow-untyped-defs
PACKAGE CONTENTS
_coreml (package)
_nnapi (package)
cpu (package)
cuda (package)
cudnn (package)
cusparselt (package)
kleidiai (package)
mha (package)
miopen (package)
mkl (package)
mkldnn (package)
mps (package)
nnpack (package)
openmp (package)
opt_einsum (package)
python_native (package)
quantized (package)
xeon (package)
xnnpack (package)
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\backends\__init__.py
torch.baddbmm
Python Library Documentation: built-in function baddbmm in module torch
baddbmm(...)
baddbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
Performs a batch matrix-matrix product of matrices in :attr:`batch1`
and :attr:`batch2`.
:attr:`input` is added to the final result.
:attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
number of matrices.
If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
:math:`(b \times m \times p)` tensor, then :attr:`input` must be
:ref:`broadcastable <broadcasting-semantics>` with a
:math:`(b \times n \times p)` tensor and :attr:`out` will be a
:math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
same as the scaling factors used in :meth:`torch.addbmm`.
.. math::
\text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
it will not be propagated.
For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
:attr:`alpha` must be real numbers, otherwise they should be integers.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
Args:
input (Tensor): the tensor to be added
batch1 (Tensor): the first batch of matrices to be multiplied
batch2 (Tensor): the second batch of matrices to be multiplied
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
Example::
>>> M = torch.randn(10, 3, 5)
>>> batch1 = torch.randn(10, 3, 4)
>>> batch2 = torch.randn(10, 4, 5)
>>> torch.baddbmm(M, batch1, batch2).size()
torch.Size([10, 3, 5])
.. function:: baddbmm(input, batch1, batch2, out_dtype, *, beta=1, alpha=1, out=None) -> Tensor
:noindex:
Args:
input (Tensor): the tensor to be added
batch1 (Tensor): the first batch of matrices to be multiplied
batch2 (Tensor): the second batch of matrices to be multiplied
out_dtype (dtype): the dtype of the output tensor.
Supported only on CUDA and for torch.float32 given
torch.float16/torch.bfloat16 input dtypes.
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
torch.bartlett_window
Python Library Documentation: built-in function bartlett_window in module torch
bartlett_window(...)
bartlett_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Bartlett window function.
.. math::
w[n] = 1 - \left| \frac{2n}{N-1} - 1 \right| = \begin{cases}
\frac{2n}{N - 1} & \text{if } 0 \leq n \leq \frac{N - 1}{2} \\
2 - \frac{2n}{N - 1} & \text{if } \frac{N - 1}{2} < n < N \\
\end{cases},
where :math:`N` is the full window size.
The input :attr:`window_length` is a positive integer controlling the
returned window size. :attr:`periodic` flag determines whether the returned
window trims off the last duplicate value from the symmetric window and is
ready to be used as a periodic window with functions like
:meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
``torch.bartlett_window(L, periodic=True)`` equal to
``torch.bartlett_window(L + 1, periodic=False)[:-1])``.
.. note::
If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
Arguments:
window_length (int): the size of returned window
periodic (bool, optional): If True, returns a window to be used as periodic
function. If False, return a symmetric window.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
torch.batch_norm
Python Library Documentation: built-in function batch_norm in module torch batch_norm(...)
torch.batch_norm_backward_elemt
Python Library Documentation: built-in function batch_norm_backward_elemt in module torch batch_norm_backward_elemt(...)
torch.batch_norm_backward_reduce
Python Library Documentation: built-in function batch_norm_backward_reduce in module torch batch_norm_backward_reduce(...)
torch.batch_norm_elemt
Python Library Documentation: built-in function batch_norm_elemt in module torch batch_norm_elemt(...)
torch.batch_norm_gather_stats
Python Library Documentation: built-in function batch_norm_gather_stats in module torch batch_norm_gather_stats(...)
torch.batch_norm_gather_stats_with_counts
Python Library Documentation: built-in function batch_norm_gather_stats_with_counts in module torch batch_norm_gather_stats_with_counts(...)
torch.batch_norm_stats
Python Library Documentation: built-in function batch_norm_stats in module torch batch_norm_stats(...)
torch.batch_norm_update_stats
Python Library Documentation: built-in function batch_norm_update_stats in module torch batch_norm_update_stats(...)
torch.bernoulli
Python Library Documentation: built-in function bernoulli in module torch
bernoulli(...)
bernoulli(input: Tensor, *, generator: Optional[Generator], out: Optional[Tensor]) -> Tensor
Draws binary random numbers (0 or 1) from a Bernoulli distribution.
The :attr:`input` tensor should be a tensor containing probabilities
to be used for drawing the binary random number.
Hence, all values in :attr:`input` have to be in the range:
:math:`0 \leq \text{input}_i \leq 1`.
The :math:`\text{i}^{th}` element of the output tensor will draw a
value :math:`1` according to the :math:`\text{i}^{th}` probability value given
in :attr:`input`.
.. math::
\text{out}_{i} \sim \mathrm{Bernoulli}(p = \text{input}_{i})
The returned :attr:`out` tensor only has values 0 or 1 and is of the same
shape as :attr:`input`.
:attr:`out` can have integral ``dtype``, but :attr:`input` must have floating
point ``dtype``.
Args:
input (Tensor): the input tensor of probability values for the Bernoulli distribution
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.empty(3, 3).uniform_(0, 1) # generate a uniform random matrix with range [0, 1]
>>> a
tensor([[ 0.1737, 0.0950, 0.3609],
[ 0.7148, 0.0289, 0.2676],
[ 0.9456, 0.8937, 0.7202]])
>>> torch.bernoulli(a)
tensor([[ 1., 0., 0.],
[ 0., 0., 0.],
[ 1., 1., 1.]])
>>> a = torch.ones(3, 3) # probability of drawing "1" is 1
>>> torch.bernoulli(a)
tensor([[ 1., 1., 1.],
[ 1., 1., 1.],
[ 1., 1., 1.]])
>>> a = torch.zeros(3, 3) # probability of drawing "1" is 0
>>> torch.bernoulli(a)
tensor([[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]])
torch.bfloat16
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.bilinear
Python Library Documentation: built-in function bilinear in module torch
bilinear(...)
bilinear(input1, input2, weight, bias=None) -> Tensor
Applies a bilinear transformation to the incoming data:
:math:`y = x_1^T A x_2 + b`
Shape:
- input1: :math:`(N, *, H_{in1})` where :math:`H_{in1}=\text{in1\_features}`
and :math:`*` means any number of additional dimensions.
All but the last dimension of the inputs should be the same.
- input2: :math:`(N, *, H_{in2})` where :math:`H_{in2}=\text{in2\_features}`
- weight: :math:`(\text{out\_features}, \text{in1\_features},
\text{in2\_features})`
- bias: :math:`(\text{out\_features})`
- output: :math:`(N, *, H_{out})` where :math:`H_{out}=\text{out\_features}`
and all but the last dimension are the same shape as the input.
torch.binary_cross_entropy_with_logits
Python Library Documentation: built-in function binary_cross_entropy_with_logits in module torch binary_cross_entropy_with_logits(...)
torch.bincount
Python Library Documentation: built-in function bincount in module torch
bincount(...)
bincount(input, weights=None, minlength=0) -> Tensor
Count the frequency of each value in an array of non-negative ints.
The number of bins (size 1) is one larger than the largest value in
:attr:`input` unless :attr:`input` is empty, in which case the result is a
tensor of size 0. If :attr:`minlength` is specified, the number of bins is at least
:attr:`minlength` and if :attr:`input` is empty, then the result is tensor of size
:attr:`minlength` filled with zeros. If ``n`` is the value at position ``i``,
``out[n] += weights[i]`` if :attr:`weights` is specified else
``out[n] += 1``.
Note:
This operation may produce nondeterministic gradients when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
Arguments:
input (Tensor): 1-d int tensor
weights (Tensor): optional, weight for each value in the input tensor.
Should be of same size as input tensor.
minlength (int): optional, minimum number of bins. Should be non-negative.
Returns:
output (Tensor): a tensor of shape ``Size([max(input) + 1])`` if
:attr:`input` is non-empty, else ``Size(0)``
Example::
>>> input = torch.randint(0, 8, (5,), dtype=torch.int64)
>>> weights = torch.linspace(0, 1, steps=5)
>>> input, weights
(tensor([4, 3, 6, 3, 4]),
tensor([ 0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
>>> torch.bincount(input)
tensor([0, 0, 0, 2, 2, 0, 1])
>>> input.bincount(weights)
tensor([0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 0.0000, 0.5000])
torch.binomial
Python Library Documentation: built-in function binomial in module torch binomial(...)
torch.bit
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.bits16
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.bits1x8
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.bits2x4
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.bits4x2
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.bits8
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.bitwise_and
Python Library Documentation: built-in function bitwise_and in module torch
bitwise_and(...)
bitwise_and(input, other, *, out=None) -> Tensor
Computes the bitwise AND of :attr:`input` and :attr:`other`. The input tensor must be of
integral or Boolean types. For bool tensors, it computes the logical AND.
Args:
input: the first input tensor
other: the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.bitwise_and(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([1, 0, 3], dtype=torch.int8)
>>> torch.bitwise_and(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
tensor([ False, True, False])
torch.bitwise_left_shift
Python Library Documentation: built-in function bitwise_left_shift in module torch
bitwise_left_shift(...)
bitwise_left_shift(input, other, *, out=None) -> Tensor
Computes the left arithmetic shift of :attr:`input` by :attr:`other` bits.
The input tensor must be of integral type. This operator supports
:ref:`broadcasting to a common shape <broadcasting-semantics>` and
:ref:`type promotion <type-promotion-doc>`.
The operation applied is:
.. math::
\text{out}_i = \text{input}_i << \text{other}_i
Args:
input (Tensor or Scalar): the first input tensor
other (Tensor or Scalar): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.bitwise_left_shift(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([-2, -2, 24], dtype=torch.int8)
torch.bitwise_not
Python Library Documentation: built-in function bitwise_not in module torch
bitwise_not(...)
bitwise_not(input, *, out=None) -> Tensor
Computes the bitwise NOT of the given input tensor. The input tensor must be of
integral or Boolean types. For bool tensors, it computes the logical NOT.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.bitwise_not(torch.tensor([-1, -2, 3], dtype=torch.int8))
tensor([ 0, 1, -4], dtype=torch.int8)
torch.bitwise_or
Python Library Documentation: built-in function bitwise_or in module torch
bitwise_or(...)
bitwise_or(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
Computes the bitwise OR of :attr:`input` and :attr:`other`. The input tensor must be of
integral or Boolean types. For bool tensors, it computes the logical OR.
Args:
input: the first input tensor
other: the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.bitwise_or(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([-1, -2, 3], dtype=torch.int8)
>>> torch.bitwise_or(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
tensor([ True, True, False])
torch.bitwise_right_shift
Python Library Documentation: built-in function bitwise_right_shift in module torch
bitwise_right_shift(...)
bitwise_right_shift(input, other, *, out=None) -> Tensor
Computes the right arithmetic shift of :attr:`input` by :attr:`other` bits.
The input tensor must be of integral type. This operator supports
:ref:`broadcasting to a common shape <broadcasting-semantics>` and
:ref:`type promotion <type-promotion-doc>`.
In any case, if the value of the right operand is negative or is greater
or equal to the number of bits in the promoted left operand, the behavior is undefined.
The operation applied is:
.. math::
\text{out}_i = \text{input}_i >> \text{other}_i
Args:
input (Tensor or Scalar): the first input tensor
other (Tensor or Scalar): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.bitwise_right_shift(torch.tensor([-2, -7, 31], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([-1, -7, 3], dtype=torch.int8)
torch.bitwise_xor
Python Library Documentation: built-in function bitwise_xor in module torch
bitwise_xor(...)
bitwise_xor(input, other, *, out=None) -> Tensor
Computes the bitwise XOR of :attr:`input` and :attr:`other`. The input tensor must be of
integral or Boolean types. For bool tensors, it computes the logical XOR.
Args:
input: the first input tensor
other: the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.bitwise_xor(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([-2, -2, 0], dtype=torch.int8)
>>> torch.bitwise_xor(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
tensor([ True, False, False])
torch.blackman_window
Python Library Documentation: built-in function blackman_window in module torch
blackman_window(...)
blackman_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Blackman window function.
.. math::
w[n] = 0.42 - 0.5 \cos \left( \frac{2 \pi n}{N - 1} \right) + 0.08 \cos \left( \frac{4 \pi n}{N - 1} \right)
where :math:`N` is the full window size.
The input :attr:`window_length` is a positive integer controlling the
returned window size. :attr:`periodic` flag determines whether the returned
window trims off the last duplicate value from the symmetric window and is
ready to be used as a periodic window with functions like
:meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
``torch.blackman_window(L, periodic=True)`` equal to
``torch.blackman_window(L + 1, periodic=False)[:-1]``.
.. note::
If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
Arguments:
window_length (int): the size of returned window
periodic (bool, optional): If True, returns a window to be used as periodic
function. If False, return a symmetric window.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
torch.block_diag
Python Library Documentation: function block_diag in module torch.functional
block_diag(*tensors)
Create a block diagonal matrix from provided tensors.
Args:
*tensors: One or more tensors with 0, 1, or 2 dimensions.
Returns:
Tensor: A 2 dimensional tensor with all the input tensors arranged in
order such that their upper left and lower right corners are
diagonally adjacent. All other elements are set to 0.
Example::
>>> import torch
>>> A = torch.tensor([[0, 1], [1, 0]])
>>> B = torch.tensor([[3, 4, 5], [6, 7, 8]])
>>> C = torch.tensor(7)
>>> D = torch.tensor([1, 2, 3])
>>> E = torch.tensor([[4], [5], [6]])
>>> torch.block_diag(A, B, C, D, E)
tensor([[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 3, 4, 5, 0, 0, 0, 0, 0],
[0, 0, 6, 7, 8, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 7, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 2, 3, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 5],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 6]])
torch.bmm
Python Library Documentation: built-in function bmm in module torch
bmm(...)
bmm(input, mat2, *, out=None) -> Tensor
Performs a batch matrix-matrix product of matrices stored in :attr:`input`
and :attr:`mat2`.
:attr:`input` and :attr:`mat2` must be 3-D tensors each containing
the same number of matrices.
If :attr:`input` is a :math:`(b \times n \times m)` tensor, :attr:`mat2` is a
:math:`(b \times m \times p)` tensor, :attr:`out` will be a
:math:`(b \times n \times p)` tensor.
.. math::
\text{out}_i = \text{input}_i \mathbin{@} \text{mat2}_i
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
.. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
For broadcasting matrix products, see :func:`torch.matmul`.
Args:
input (Tensor): the first batch of matrices to be multiplied
mat2 (Tensor): the second batch of matrices to be multiplied
Keyword Args:
out (Tensor, optional): the output tensor.
Example::
>>> input = torch.randn(10, 3, 4)
>>> mat2 = torch.randn(10, 4, 5)
>>> res = torch.bmm(input, mat2)
>>> res.size()
torch.Size([10, 3, 5])
.. function:: bmm(input, mat2, out_dtype, *, out=None) -> Tensor
:noindex:
Args:
input (Tensor): the first batch of matrices to be multiplied
mat2 (Tensor): the second batch of matrices to be multiplied
out_dtype (dtype): the dtype of the output tensor.
Supported only on CUDA and for torch.float32 given
torch.float16/torch.bfloat16 input dtypes.
Keyword Args:
out (Tensor, optional): the output tensor.
torch.bool
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.broadcast_shapes
Python Library Documentation: function broadcast_shapes in module torch.functional
broadcast_shapes(*shapes)
broadcast_shapes(*shapes) -> Size
Similar to :func:`broadcast_tensors` but for shapes.
This is equivalent to
``torch.broadcast_tensors(*map(torch.empty, shapes))[0].shape``
but avoids the need to create intermediate tensors. This is useful for
broadcasting tensors of common batch shape but different rightmost shape,
e.g. to broadcast mean vectors with covariance matrices.
Example::
>>> torch.broadcast_shapes((2,), (3, 1), (1, 1, 1))
torch.Size([1, 3, 2])
Args:
\*shapes (torch.Size): Shapes of tensors.
Returns:
shape (torch.Size): A shape compatible with all input shapes.
Raises:
RuntimeError: If shapes are incompatible.
torch.broadcast_tensors
Python Library Documentation: function broadcast_tensors in module torch.functional
broadcast_tensors(*tensors)
broadcast_tensors(*tensors) -> List of Tensors
Broadcasts the given tensors according to :ref:`broadcasting-semantics`.
Args:
*tensors: any number of tensors of the same type
.. warning::
More than one element of a broadcasted tensor may refer to a single
memory location. As a result, in-place operations (especially ones that
are vectorized) may result in incorrect behavior. If you need to write
to the tensors, please clone them first.
Example::
>>> x = torch.arange(3).view(1, 3)
>>> y = torch.arange(2).view(2, 1)
>>> a, b = torch.broadcast_tensors(x, y)
>>> a.size()
torch.Size([2, 3])
>>> a
tensor([[0, 1, 2],
[0, 1, 2]])
torch.broadcast_to
Python Library Documentation: built-in function broadcast_to in module torch
broadcast_to(...)
broadcast_to(input, shape) -> Tensor
Broadcasts :attr:`input` to the shape :attr:`\shape`.
Equivalent to calling ``input.expand(shape)``. See :meth:`~Tensor.expand` for details.
Args:
input (Tensor): the input tensor.
shape (list, tuple, or :class:`torch.Size`): the new shape.
Example::
>>> x = torch.tensor([1, 2, 3])
>>> torch.broadcast_to(x, (3, 3))
tensor([[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])
torch.bucketize
Python Library Documentation: built-in function bucketize in module torch
bucketize(...)
bucketize(input, boundaries, *, out_int32=False, right=False, out=None) -> Tensor
Returns the indices of the buckets to which each value in the :attr:`input` belongs, where the
boundaries of the buckets are set by :attr:`boundaries`. Return a new tensor with the same size
as :attr:`input`. If :attr:`right` is False (default), then the left boundary is open. Note that
this behavior is opposite the behavior of
`numpy.digitize <https://numpy.org/doc/stable/reference/generated/numpy.digitize.html>`_.
More formally, the returned index satisfies the following rules:
.. list-table::
:widths: 15 85
:header-rows: 1
* - :attr:`right`
- *returned index satisfies*
* - False
- ``boundaries[i-1] < input[m][n]...[l][x] <= boundaries[i]``
* - True
- ``boundaries[i-1] <= input[m][n]...[l][x] < boundaries[i]``
Args:
input (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
boundaries (Tensor): 1-D tensor, must contain a strictly increasing sequence, or the return value is undefined.
Keyword args:
out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
Default value is False, i.e. default output data type is torch.int64.
right (bool, optional): determines the behavior for values in :attr:`boundaries`. See the table above.
out (Tensor, optional): the output tensor, must be the same size as :attr:`input` if provided.
Example::
>>> boundaries = torch.tensor([1, 3, 5, 7, 9])
>>> boundaries
tensor([1, 3, 5, 7, 9])
>>> v = torch.tensor([[3, 6, 9], [3, 6, 9]])
>>> v
tensor([[3, 6, 9],
[3, 6, 9]])
>>> torch.bucketize(v, boundaries)
tensor([[1, 3, 4],
[1, 3, 4]])
>>> torch.bucketize(v, boundaries, right=True)
tensor([[2, 3, 5],
[2, 3, 5]])
torch.builtins
Python Library Documentation: built-in module builtins
NAME
builtins - Built-in functions, types, exceptions, and other objects.
DESCRIPTION
This module provides direct access to all 'built-in'
identifiers of Python; for example, builtins.len is
the full name for the built-in function len().
This module is not normally accessed explicitly by most
applications, but can be useful in modules that provide
objects with the same name as a built-in value, but in
which the built-in of that name is also needed.
CLASSES
object
BaseException
BaseExceptionGroup
ExceptionGroup(BaseExceptionGroup, Exception)
Exception
ArithmeticError
FloatingPointError
OverflowError
ZeroDivisionError
AssertionError
AttributeError
BufferError
EOFError
ImportError
ModuleNotFoundError
LookupError
IndexError
KeyError
MemoryError
NameError
UnboundLocalError
OSError
BlockingIOError
ChildProcessError
ConnectionError
BrokenPipeError
ConnectionAbortedError
ConnectionRefusedError
ConnectionResetError
FileExistsError
FileNotFoundError
InterruptedError
IsADirectoryError
NotADirectoryError
PermissionError
ProcessLookupError
TimeoutError
ReferenceError
RuntimeError
NotImplementedError
RecursionError
StopAsyncIteration
StopIteration
SyntaxError
IndentationError
TabError
SystemError
TypeError
ValueError
UnicodeError
UnicodeDecodeError
UnicodeEncodeError
UnicodeTranslateError
Warning
BytesWarning
DeprecationWarning
EncodingWarning
FutureWarning
ImportWarning
PendingDeprecationWarning
ResourceWarning
RuntimeWarning
SyntaxWarning
UnicodeWarning
UserWarning
GeneratorExit
KeyboardInterrupt
SystemExit
bytearray
bytes
classmethod
complex
dict
enumerate
filter
float
frozenset
int
bool
list
map
memoryview
property
range
reversed
set
slice
staticmethod
str
super
tuple
type
zip
class ArithmeticError(Exception)
| Base class for arithmetic errors.
|
| Method resolution order:
| ArithmeticError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| FloatingPointError
| OverflowError
| ZeroDivisionError
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class AssertionError(Exception)
| Assertion failed.
|
| Method resolution order:
| AssertionError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class AttributeError(Exception)
| Attribute not found.
|
| Method resolution order:
| AttributeError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __getstate__(...)
| Helper for pickle.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| name
| attribute name
|
| obj
| object
|
| ----------------------------------------------------------------------
| Static methods inherited from Exception:
|
| __new__(*args, **kwargs) class method of Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class BaseException(object)
| Common base class for all exceptions
|
| Built-in subclasses:
| BaseExceptionGroup
| Exception
| GeneratorExit
| KeyboardInterrupt
| ... and 1 other subclasses
|
| Methods defined here:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class BaseExceptionGroup(BaseException)
| A combination of multiple unrelated exceptions.
|
| Method resolution order:
| BaseExceptionGroup
| BaseException
| object
|
| Built-in subclasses:
| ExceptionGroup
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self, /)
| Return str(self).
|
| derive(...)
|
| split(...)
|
| subgroup(...)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__(...)
| See PEP 585
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| exceptions
| nested exceptions
|
| message
| exception message
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class BlockingIOError(OSError)
| I/O operation would block.
|
| Method resolution order:
| BlockingIOError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class BrokenPipeError(ConnectionError)
| Broken pipe.
|
| Method resolution order:
| BrokenPipeError
| ConnectionError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class BufferError(Exception)
| Buffer error.
|
| Method resolution order:
| BufferError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class BytesWarning(Warning)
| Base class for warnings about bytes and buffer related problems, mostly
| related to conversion from str or comparing to str.
|
| Method resolution order:
| BytesWarning
| Warning
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ChildProcessError(OSError)
| Child process error.
|
| Method resolution order:
| ChildProcessError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ConnectionAbortedError(ConnectionError)
| Connection aborted.
|
| Method resolution order:
| ConnectionAbortedError
| ConnectionError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ConnectionError(OSError)
| Connection error.
|
| Method resolution order:
| ConnectionError
| OSError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| BrokenPipeError
| ConnectionAbortedError
| ConnectionRefusedError
| ConnectionResetError
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ConnectionRefusedError(ConnectionError)
| Connection refused.
|
| Method resolution order:
| ConnectionRefusedError
| ConnectionError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ConnectionResetError(ConnectionError)
| Connection reset.
|
| Method resolution order:
| ConnectionResetError
| ConnectionError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class DeprecationWarning(Warning)
| Base class for warnings about deprecated features.
|
| Method resolution order:
| DeprecationWarning
| Warning
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class EOFError(Exception)
| Read beyond end of file.
|
| Method resolution order:
| EOFError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class EncodingWarning(Warning)
| Base class for warnings about encodings.
|
| Method resolution order:
| EncodingWarning
| Warning
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
EnvironmentError = class OSError(Exception)
| Base class for I/O related errors.
|
| Method resolution order:
| OSError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| BlockingIOError
| ChildProcessError
| ConnectionError
| FileExistsError
| ... and 7 other subclasses
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class Exception(BaseException)
| Common base class for all non-exit exceptions.
|
| Method resolution order:
| Exception
| BaseException
| object
|
| Built-in subclasses:
| ArithmeticError
| AssertionError
| AttributeError
| BufferError
| ... and 16 other subclasses
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ExceptionGroup(BaseExceptionGroup, Exception)
| Method resolution order:
| ExceptionGroup
| BaseExceptionGroup
| Exception
| BaseException
| object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from BaseExceptionGroup:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self, /)
| Return str(self).
|
| derive(...)
|
| split(...)
|
| subgroup(...)
|
| ----------------------------------------------------------------------
| Class methods inherited from BaseExceptionGroup:
|
| __class_getitem__(...)
| See PEP 585
|
| ----------------------------------------------------------------------
| Static methods inherited from BaseExceptionGroup:
|
| __new__(*args, **kwargs) class method of BaseExceptionGroup
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseExceptionGroup:
|
| exceptions
| nested exceptions
|
| message
| exception message
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class FileExistsError(OSError)
| File already exists.
|
| Method resolution order:
| FileExistsError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class FileNotFoundError(OSError)
| File not found.
|
| Method resolution order:
| FileNotFoundError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class FloatingPointError(ArithmeticError)
| Floating-point operation failed.
|
| Method resolution order:
| FloatingPointError
| ArithmeticError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class FutureWarning(Warning)
| Base class for warnings about constructs that will change semantically
| in the future.
|
| Method resolution order:
| FutureWarning
| Warning
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class GeneratorExit(BaseException)
| Request that a generator exit.
|
| Method resolution order:
| GeneratorExit
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
IOError = class OSError(Exception)
| Base class for I/O related errors.
|
| Method resolution order:
| OSError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| BlockingIOError
| ChildProcessError
| ConnectionError
| FileExistsError
| ... and 7 other subclasses
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ImportError(Exception)
| Import can't find module, or can't find name in module.
|
| Method resolution order:
| ImportError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| ModuleNotFoundError
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| msg
| exception message
|
| name
| module name
|
| name_from
| name imported from module
|
| path
| module path
|
| ----------------------------------------------------------------------
| Static methods inherited from Exception:
|
| __new__(*args, **kwargs) class method of Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ImportWarning(Warning)
| Base class for warnings about probable mistakes in module imports
|
| Method resolution order:
| ImportWarning
| Warning
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class IndentationError(SyntaxError)
| Improper indentation.
|
| Method resolution order:
| IndentationError
| SyntaxError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| TabError
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from SyntaxError:
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from SyntaxError:
|
| end_lineno
| exception end lineno
|
| end_offset
| exception end offset
|
| filename
| exception filename
|
| lineno
| exception lineno
|
| msg
| exception msg
|
| offset
| exception offset
|
| print_file_and_line
| exception print_file_and_line
|
| text
| exception text
|
| ----------------------------------------------------------------------
| Static methods inherited from Exception:
|
| __new__(*args, **kwargs) class method of Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class IndexError(LookupError)
| Sequence index out of range.
|
| Method resolution order:
| IndexError
| LookupError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class InterruptedError(OSError)
| Interrupted by signal.
|
| Method resolution order:
| InterruptedError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class IsADirectoryError(OSError)
| Operation doesn't work on directories.
|
| Method resolution order:
| IsADirectoryError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class KeyError(LookupError)
| Mapping key not found.
|
| Method resolution order:
| KeyError
| LookupError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from LookupError:
|
| __new__(*args, **kwargs) class method of LookupError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class KeyboardInterrupt(BaseException)
| Program interrupted by user.
|
| Method resolution order:
| KeyboardInterrupt
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class LookupError(Exception)
| Base class for lookup errors.
|
| Method resolution order:
| LookupError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| IndexError
| KeyError
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class MemoryError(Exception)
| Out of memory.
|
| Method resolution order:
| MemoryError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ModuleNotFoundError(ImportError)
| Module not found.
|
| Method resolution order:
| ModuleNotFoundError
| ImportError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from ImportError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from ImportError:
|
| msg
| exception message
|
| name
| module name
|
| name_from
| name imported from module
|
| path
| module path
|
| ----------------------------------------------------------------------
| Static methods inherited from Exception:
|
| __new__(*args, **kwargs) class method of Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class NameError(Exception)
| Name not found globally.
|
| Method resolution order:
| NameError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| UnboundLocalError
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| name
| name
|
| ----------------------------------------------------------------------
| Static methods inherited from Exception:
|
| __new__(*args, **kwargs) class method of Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class NotADirectoryError(OSError)
| Operation only works on directories.
|
| Method resolution order:
| NotADirectoryError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class NotImplementedError(RuntimeError)
| Method or function hasn't been implemented yet.
|
| Method resolution order:
| NotImplementedError
| RuntimeError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class OSError(Exception)
| Base class for I/O related errors.
|
| Method resolution order:
| OSError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| BlockingIOError
| ChildProcessError
| ConnectionError
| FileExistsError
| ... and 7 other subclasses
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class OverflowError(ArithmeticError)
| Result too large to be represented.
|
| Method resolution order:
| OverflowError
| ArithmeticError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class PendingDeprecationWarning(Warning)
| Base class for warnings about features which will be deprecated
| in the future.
|
| Method resolution order:
| PendingDeprecationWarning
| Warning
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class PermissionError(OSError)
| Not enough permissions.
|
| Method resolution order:
| PermissionError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ProcessLookupError(OSError)
| Process not found.
|
| Method resolution order:
| ProcessLookupError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class RecursionError(RuntimeError)
| Recursion limit exceeded.
|
| Method resolution order:
| RecursionError
| RuntimeError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ReferenceError(Exception)
| Weak ref proxy used after referent went away.
|
| Method resolution order:
| ReferenceError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ResourceWarning(Warning)
| Base class for warnings about resource usage.
|
| Method resolution order:
| ResourceWarning
| Warning
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class RuntimeError(Exception)
| Unspecified run-time error.
|
| Method resolution order:
| RuntimeError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| NotImplementedError
| RecursionError
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class RuntimeWarning(Warning)
| Base class for warnings about dubious runtime behavior.
|
| Method resolution order:
| RuntimeWarning
| Warning
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class StopAsyncIteration(Exception)
| Signal the end from iterator.__anext__().
|
| Method resolution order:
| StopAsyncIteration
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class StopIteration(Exception)
| Signal the end from iterator.__next__().
|
| Method resolution order:
| StopIteration
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| value
| generator return value
|
| ----------------------------------------------------------------------
| Static methods inherited from Exception:
|
| __new__(*args, **kwargs) class method of Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class SyntaxError(Exception)
| Invalid syntax.
|
| Method resolution order:
| SyntaxError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| IndentationError
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| end_lineno
| exception end lineno
|
| end_offset
| exception end offset
|
| filename
| exception filename
|
| lineno
| exception lineno
|
| msg
| exception msg
|
| offset
| exception offset
|
| print_file_and_line
| exception print_file_and_line
|
| text
| exception text
|
| ----------------------------------------------------------------------
| Static methods inherited from Exception:
|
| __new__(*args, **kwargs) class method of Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class SyntaxWarning(Warning)
| Base class for warnings about dubious syntax.
|
| Method resolution order:
| SyntaxWarning
| Warning
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class SystemError(Exception)
| Internal error in the Python interpreter.
|
| Please report this to the Python maintainer, along with the traceback,
| the Python version, and the hardware/OS platform and version.
|
| Method resolution order:
| SystemError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class SystemExit(BaseException)
| Request to exit from the interpreter.
|
| Method resolution order:
| SystemExit
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| code
| exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Static methods inherited from BaseException:
|
| __new__(*args, **kwargs) class method of BaseException
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class TabError(IndentationError)
| Improper mixture of spaces and tabs.
|
| Method resolution order:
| TabError
| IndentationError
| SyntaxError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from SyntaxError:
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from SyntaxError:
|
| end_lineno
| exception end lineno
|
| end_offset
| exception end offset
|
| filename
| exception filename
|
| lineno
| exception lineno
|
| msg
| exception msg
|
| offset
| exception offset
|
| print_file_and_line
| exception print_file_and_line
|
| text
| exception text
|
| ----------------------------------------------------------------------
| Static methods inherited from Exception:
|
| __new__(*args, **kwargs) class method of Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class TimeoutError(OSError)
| Timeout expired.
|
| Method resolution order:
| TimeoutError
| OSError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from OSError:
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from OSError:
|
| __new__(*args, **kwargs) class method of OSError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from OSError:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class TypeError(Exception)
| Inappropriate argument type.
|
| Method resolution order:
| TypeError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class UnboundLocalError(NameError)
| Local name referenced but not bound to a value.
|
| Method resolution order:
| UnboundLocalError
| NameError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from NameError:
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from NameError:
|
| name
| name
|
| ----------------------------------------------------------------------
| Static methods inherited from Exception:
|
| __new__(*args, **kwargs) class method of Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class UnicodeDecodeError(UnicodeError)
| Unicode decoding error.
|
| Method resolution order:
| UnicodeDecodeError
| UnicodeError
| ValueError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| encoding
| exception encoding
|
| end
| exception end
|
| object
| exception object
|
| reason
| exception reason
|
| start
| exception start
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class UnicodeEncodeError(UnicodeError)
| Unicode encoding error.
|
| Method resolution order:
| UnicodeEncodeError
| UnicodeError
| ValueError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| encoding
| exception encoding
|
| end
| exception end
|
| object
| exception object
|
| reason
| exception reason
|
| start
| exception start
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class UnicodeError(ValueError)
| Unicode related error.
|
| Method resolution order:
| UnicodeError
| ValueError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| UnicodeDecodeError
| UnicodeEncodeError
| UnicodeTranslateError
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class UnicodeTranslateError(UnicodeError)
| Unicode translation error.
|
| Method resolution order:
| UnicodeTranslateError
| UnicodeError
| ValueError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| encoding
| exception encoding
|
| end
| exception end
|
| object
| exception object
|
| reason
| exception reason
|
| start
| exception start
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class UnicodeWarning(Warning)
| Base class for warnings about Unicode related problems, mostly
| related to conversion problems.
|
| Method resolution order:
| UnicodeWarning
| Warning
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class UserWarning(Warning)
| Base class for warnings generated by user code.
|
| Method resolution order:
| UserWarning
| Warning
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ValueError(Exception)
| Inappropriate argument value (of correct type).
|
| Method resolution order:
| ValueError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| UnicodeError
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class Warning(Exception)
| Base class for warning categories.
|
| Method resolution order:
| Warning
| Exception
| BaseException
| object
|
| Built-in subclasses:
| BytesWarning
| DeprecationWarning
| EncodingWarning
| FutureWarning
| ... and 7 other subclasses
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
WindowsError = class OSError(Exception)
| Base class for I/O related errors.
|
| Method resolution order:
| OSError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| BlockingIOError
| ChildProcessError
| ConnectionError
| FileExistsError
| ... and 7 other subclasses
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ZeroDivisionError(ArithmeticError)
| Second argument to a division or modulo operation was zero.
|
| Method resolution order:
| ZeroDivisionError
| ArithmeticError
| Exception
| BaseException
| object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class bool(int)
| bool(x) -> bool
|
| Returns True when the argument x is true, False otherwise.
| The builtins True and False are the only two instances of the class bool.
| The class bool is a subclass of the class int, and cannot be subclassed.
|
| Method resolution order:
| bool
| int
| object
|
| Methods defined here:
|
| __and__(self, value, /)
| Return self&value.
|
| __invert__(self, /)
| ~self
|
| __or__(self, value, /)
| Return self|value.
|
| __rand__(self, value, /)
| Return value&self.
|
| __repr__(self, /)
| Return repr(self).
|
| __ror__(self, value, /)
| Return value|self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __xor__(self, value, /)
| Return self^value.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from int:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Convert to a string according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods inherited from int:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from int:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
class bytearray(object)
| bytearray(iterable_of_ints) -> bytearray
| bytearray(string, encoding[, errors]) -> bytearray
| bytearray(bytes_or_buffer) -> mutable copy of bytes_or_buffer
| bytearray(int) -> bytes array of size given by the parameter initialized with null bytes
| bytearray() -> empty bytes array
|
| Construct a mutable bytearray object from:
| - an iterable yielding integers in range(256)
| - a text string encoded using the specified encoding
| - a bytes or a buffer object
| - any object implementing the buffer API.
| - an integer
|
| Methods defined here:
|
| __add__(self, value, /)
| Return self+value.
|
| __alloc__(...)
| B.__alloc__() -> int
|
| Return the number of bytes actually allocated.
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __iadd__(self, value, /)
| Implement self+=value.
|
| __imul__(self, value, /)
| Implement self*=value.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __reduce__(self, /)
| Return state information for pickling.
|
| __reduce_ex__(self, proto=0, /)
| Return state information for pickling.
|
| __release_buffer__(self, buffer, /)
| Release the buffer object that exposes the underlying memory of the object.
|
| __repr__(self, /)
| Return repr(self).
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sizeof__(self, /)
| Returns the size of the bytearray object in memory, in bytes.
|
| __str__(self, /)
| Return str(self).
|
| append(self, item, /)
| Append a single item to the end of the bytearray.
|
| item
| The item to be appended.
|
| capitalize(...)
| B.capitalize() -> copy of B
|
| Return a copy of B with only its first character capitalized (ASCII)
| and the rest lower-cased.
|
| center(self, width, fillchar=b' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character.
|
| clear(self, /)
| Remove all items from the bytearray.
|
| copy(self, /)
| Return a copy of B.
|
| count(...)
| B.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of subsection sub in
| bytes B[start:end]. Optional arguments start and end are interpreted
| as in slice notation.
|
| decode(self, /, encoding='utf-8', errors='strict')
| Decode the bytearray using the codec registered for encoding.
|
| encoding
| The encoding with which to decode the bytearray.
| errors
| The error handling scheme to use for the handling of decoding errors.
| The default is 'strict' meaning that decoding errors raise a
| UnicodeDecodeError. Other possible values are 'ignore' and 'replace'
| as well as any other name registered with codecs.register_error that
| can handle UnicodeDecodeErrors.
|
| endswith(...)
| B.endswith(suffix[, start[, end]]) -> bool
|
| Return True if B ends with the specified suffix, False otherwise.
| With optional start, test B beginning at that position.
| With optional end, stop comparing B at that position.
| suffix can also be a tuple of bytes to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| extend(self, iterable_of_ints, /)
| Append all the items from the iterator or sequence to the end of the bytearray.
|
| iterable_of_ints
| The iterable of items to append.
|
| find(...)
| B.find(sub[, start[, end]]) -> int
|
| Return the lowest index in B where subsection sub is found,
| such that sub is contained within B[start,end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| hex(...)
| Create a string of hexadecimal numbers from a bytearray object.
|
| sep
| An optional single character or byte to separate hex bytes.
| bytes_per_sep
| How many bytes between separators. Positive values count from the
| right, negative values count from the left.
|
| Example:
| >>> value = bytearray([0xb9, 0x01, 0xef])
| >>> value.hex()
| 'b901ef'
| >>> value.hex(':')
| 'b9:01:ef'
| >>> value.hex(':', 2)
| 'b9:01ef'
| >>> value.hex(':', -2)
| 'b901:ef'
|
| index(...)
| B.index(sub[, start[, end]]) -> int
|
| Return the lowest index in B where subsection sub is found,
| such that sub is contained within B[start,end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the subsection is not found.
|
| insert(self, index, item, /)
| Insert a single item into the bytearray before the given index.
|
| index
| The index where the value is to be inserted.
| item
| The item to be inserted.
|
| isalnum(...)
| B.isalnum() -> bool
|
| Return True if all characters in B are alphanumeric
| and there is at least one character in B, False otherwise.
|
| isalpha(...)
| B.isalpha() -> bool
|
| Return True if all characters in B are alphabetic
| and there is at least one character in B, False otherwise.
|
| isascii(...)
| B.isascii() -> bool
|
| Return True if B is empty or all characters in B are ASCII,
| False otherwise.
|
| isdigit(...)
| B.isdigit() -> bool
|
| Return True if all characters in B are digits
| and there is at least one character in B, False otherwise.
|
| islower(...)
| B.islower() -> bool
|
| Return True if all cased characters in B are lowercase and there is
| at least one cased character in B, False otherwise.
|
| isspace(...)
| B.isspace() -> bool
|
| Return True if all characters in B are whitespace
| and there is at least one character in B, False otherwise.
|
| istitle(...)
| B.istitle() -> bool
|
| Return True if B is a titlecased string and there is at least one
| character in B, i.e. uppercase characters may only follow uncased
| characters and lowercase characters only cased ones. Return False
| otherwise.
|
| isupper(...)
| B.isupper() -> bool
|
| Return True if all cased characters in B are uppercase and there is
| at least one cased character in B, False otherwise.
|
| join(self, iterable_of_bytes, /)
| Concatenate any number of bytes/bytearray objects.
|
| The bytearray whose method is called is inserted in between each pair.
|
| The result is returned as a new bytearray object.
|
| ljust(self, width, fillchar=b' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character.
|
| lower(...)
| B.lower() -> copy of B
|
| Return a copy of B with all ASCII characters converted to lowercase.
|
| lstrip(self, bytes=None, /)
| Strip leading bytes contained in the argument.
|
| If the argument is omitted or None, strip leading ASCII whitespace.
|
| partition(self, sep, /)
| Partition the bytearray into three parts using the given separator.
|
| This will search for the separator sep in the bytearray. If the separator is
| found, returns a 3-tuple containing the part before the separator, the
| separator itself, and the part after it as new bytearray objects.
|
| If the separator is not found, returns a 3-tuple containing the copy of the
| original bytearray object and two empty bytearray objects.
|
| pop(self, index=-1, /)
| Remove and return a single item from B.
|
| index
| The index from where to remove the item.
| -1 (the default value) means remove the last item.
|
| If no index argument is given, will pop the last item.
|
| remove(self, value, /)
| Remove the first occurrence of a value in the bytearray.
|
| value
| The value to remove.
|
| removeprefix(self, prefix, /)
| Return a bytearray with the given prefix string removed if present.
|
| If the bytearray starts with the prefix string, return
| bytearray[len(prefix):]. Otherwise, return a copy of the original
| bytearray.
|
| removesuffix(self, suffix, /)
| Return a bytearray with the given suffix string removed if present.
|
| If the bytearray ends with the suffix string and that suffix is not
| empty, return bytearray[:-len(suffix)]. Otherwise, return a copy of
| the original bytearray.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| reverse(self, /)
| Reverse the order of the values in B in place.
|
| rfind(...)
| B.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in B where subsection sub is found,
| such that sub is contained within B[start,end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| B.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in B where subsection sub is found,
| such that sub is contained within B[start,end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raise ValueError when the subsection is not found.
|
| rjust(self, width, fillchar=b' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character.
|
| rpartition(self, sep, /)
| Partition the bytearray into three parts using the given separator.
|
| This will search for the separator sep in the bytearray, starting at the end.
| If the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it as new bytearray
| objects.
|
| If the separator is not found, returns a 3-tuple containing two empty bytearray
| objects and the copy of the original bytearray object.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the sections in the bytearray, using sep as the delimiter.
|
| sep
| The delimiter according which to split the bytearray.
| None (the default value) means split on ASCII whitespace characters
| (space, tab, return, newline, formfeed, vertical tab).
| maxsplit
| Maximum number of splits to do.
| -1 (the default value) means no limit.
|
| Splitting is done starting at the end of the bytearray and working to the front.
|
| rstrip(self, bytes=None, /)
| Strip trailing bytes contained in the argument.
|
| If the argument is omitted or None, strip trailing ASCII whitespace.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the sections in the bytearray, using sep as the delimiter.
|
| sep
| The delimiter according which to split the bytearray.
| None (the default value) means split on ASCII whitespace characters
| (space, tab, return, newline, formfeed, vertical tab).
| maxsplit
| Maximum number of splits to do.
| -1 (the default value) means no limit.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the bytearray, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| B.startswith(prefix[, start[, end]]) -> bool
|
| Return True if B starts with the specified prefix, False otherwise.
| With optional start, test B beginning at that position.
| With optional end, stop comparing B at that position.
| prefix can also be a tuple of bytes to try.
|
| strip(self, bytes=None, /)
| Strip leading and trailing bytes contained in the argument.
|
| If the argument is omitted or None, strip leading and trailing ASCII whitespace.
|
| swapcase(...)
| B.swapcase() -> copy of B
|
| Return a copy of B with uppercase ASCII characters converted
| to lowercase ASCII and vice versa.
|
| title(...)
| B.title() -> copy of B
|
| Return a titlecased version of B, i.e. ASCII words start with uppercase
| characters, all remaining cased characters have lowercase.
|
| translate(self, table, /, delete=b'')
| Return a copy with each character mapped by the given translation table.
|
| table
| Translation table, which must be a bytes object of length 256.
|
| All characters occurring in the optional argument delete are removed.
| The remaining characters are mapped through the given translation table.
|
| upper(...)
| B.upper() -> copy of B
|
| Return a copy of B with all ASCII characters converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The original string is never truncated.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| fromhex(string, /)
| Create a bytearray object from a string of hexadecimal numbers.
|
| Spaces between two numbers are accepted.
| Example: bytearray.fromhex('B9 01EF') -> bytearray(b'\\xb9\\x01\\xef')
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| maketrans(frm, to, /)
| Return a translation table useable for the bytes or bytearray translate method.
|
| The returned table will be one where each byte in frm is mapped to the byte at
| the same position in to.
|
| The bytes objects frm and to must be of the same length.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class bytes(object)
| bytes(iterable_of_ints) -> bytes
| bytes(string, encoding[, errors]) -> bytes
| bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
| bytes(int) -> bytes object of size given by the parameter initialized with null bytes
| bytes() -> empty bytes object
|
| Construct an immutable array of bytes from:
| - an iterable yielding integers in range(256)
| - a text string encoded using the specified encoding
| - any object implementing the buffer API.
| - an integer
|
| Methods defined here:
|
| __add__(self, value, /)
| Return self+value.
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __bytes__(self, /)
| Convert this value to exact type bytes.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __str__(self, /)
| Return str(self).
|
| capitalize(...)
| B.capitalize() -> copy of B
|
| Return a copy of B with only its first character capitalized (ASCII)
| and the rest lower-cased.
|
| center(self, width, fillchar=b' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character.
|
| count(...)
| B.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of subsection sub in
| bytes B[start:end]. Optional arguments start and end are interpreted
| as in slice notation.
|
| decode(self, /, encoding='utf-8', errors='strict')
| Decode the bytes using the codec registered for encoding.
|
| encoding
| The encoding with which to decode the bytes.
| errors
| The error handling scheme to use for the handling of decoding errors.
| The default is 'strict' meaning that decoding errors raise a
| UnicodeDecodeError. Other possible values are 'ignore' and 'replace'
| as well as any other name registered with codecs.register_error that
| can handle UnicodeDecodeErrors.
|
| endswith(...)
| B.endswith(suffix[, start[, end]]) -> bool
|
| Return True if B ends with the specified suffix, False otherwise.
| With optional start, test B beginning at that position.
| With optional end, stop comparing B at that position.
| suffix can also be a tuple of bytes to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| B.find(sub[, start[, end]]) -> int
|
| Return the lowest index in B where subsection sub is found,
| such that sub is contained within B[start,end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| hex(...)
| Create a string of hexadecimal numbers from a bytes object.
|
| sep
| An optional single character or byte to separate hex bytes.
| bytes_per_sep
| How many bytes between separators. Positive values count from the
| right, negative values count from the left.
|
| Example:
| >>> value = b'\xb9\x01\xef'
| >>> value.hex()
| 'b901ef'
| >>> value.hex(':')
| 'b9:01:ef'
| >>> value.hex(':', 2)
| 'b9:01ef'
| >>> value.hex(':', -2)
| 'b901:ef'
|
| index(...)
| B.index(sub[, start[, end]]) -> int
|
| Return the lowest index in B where subsection sub is found,
| such that sub is contained within B[start,end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the subsection is not found.
|
| isalnum(...)
| B.isalnum() -> bool
|
| Return True if all characters in B are alphanumeric
| and there is at least one character in B, False otherwise.
|
| isalpha(...)
| B.isalpha() -> bool
|
| Return True if all characters in B are alphabetic
| and there is at least one character in B, False otherwise.
|
| isascii(...)
| B.isascii() -> bool
|
| Return True if B is empty or all characters in B are ASCII,
| False otherwise.
|
| isdigit(...)
| B.isdigit() -> bool
|
| Return True if all characters in B are digits
| and there is at least one character in B, False otherwise.
|
| islower(...)
| B.islower() -> bool
|
| Return True if all cased characters in B are lowercase and there is
| at least one cased character in B, False otherwise.
|
| isspace(...)
| B.isspace() -> bool
|
| Return True if all characters in B are whitespace
| and there is at least one character in B, False otherwise.
|
| istitle(...)
| B.istitle() -> bool
|
| Return True if B is a titlecased string and there is at least one
| character in B, i.e. uppercase characters may only follow uncased
| characters and lowercase characters only cased ones. Return False
| otherwise.
|
| isupper(...)
| B.isupper() -> bool
|
| Return True if all cased characters in B are uppercase and there is
| at least one cased character in B, False otherwise.
|
| join(self, iterable_of_bytes, /)
| Concatenate any number of bytes objects.
|
| The bytes whose method is called is inserted in between each pair.
|
| The result is returned as a new bytes object.
|
| Example: b'.'.join([b'ab', b'pq', b'rs']) -> b'ab.pq.rs'.
|
| ljust(self, width, fillchar=b' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character.
|
| lower(...)
| B.lower() -> copy of B
|
| Return a copy of B with all ASCII characters converted to lowercase.
|
| lstrip(self, bytes=None, /)
| Strip leading bytes contained in the argument.
|
| If the argument is omitted or None, strip leading ASCII whitespace.
|
| partition(self, sep, /)
| Partition the bytes into three parts using the given separator.
|
| This will search for the separator sep in the bytes. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original bytes
| object and two empty bytes objects.
|
| removeprefix(self, prefix, /)
| Return a bytes object with the given prefix string removed if present.
|
| If the bytes starts with the prefix string, return bytes[len(prefix):].
| Otherwise, return a copy of the original bytes.
|
| removesuffix(self, suffix, /)
| Return a bytes object with the given suffix string removed if present.
|
| If the bytes ends with the suffix string and that suffix is not empty,
| return bytes[:-len(prefix)]. Otherwise, return a copy of the original
| bytes.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| B.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in B where subsection sub is found,
| such that sub is contained within B[start,end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| B.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in B where subsection sub is found,
| such that sub is contained within B[start,end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raise ValueError when the subsection is not found.
|
| rjust(self, width, fillchar=b' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character.
|
| rpartition(self, sep, /)
| Partition the bytes into three parts using the given separator.
|
| This will search for the separator sep in the bytes, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty bytes
| objects and the original bytes object.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the sections in the bytes, using sep as the delimiter.
|
| sep
| The delimiter according which to split the bytes.
| None (the default value) means split on ASCII whitespace characters
| (space, tab, return, newline, formfeed, vertical tab).
| maxsplit
| Maximum number of splits to do.
| -1 (the default value) means no limit.
|
| Splitting is done starting at the end of the bytes and working to the front.
|
| rstrip(self, bytes=None, /)
| Strip trailing bytes contained in the argument.
|
| If the argument is omitted or None, strip trailing ASCII whitespace.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the sections in the bytes, using sep as the delimiter.
|
| sep
| The delimiter according which to split the bytes.
| None (the default value) means split on ASCII whitespace characters
| (space, tab, return, newline, formfeed, vertical tab).
| maxsplit
| Maximum number of splits to do.
| -1 (the default value) means no limit.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the bytes, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| B.startswith(prefix[, start[, end]]) -> bool
|
| Return True if B starts with the specified prefix, False otherwise.
| With optional start, test B beginning at that position.
| With optional end, stop comparing B at that position.
| prefix can also be a tuple of bytes to try.
|
| strip(self, bytes=None, /)
| Strip leading and trailing bytes contained in the argument.
|
| If the argument is omitted or None, strip leading and trailing ASCII whitespace.
|
| swapcase(...)
| B.swapcase() -> copy of B
|
| Return a copy of B with uppercase ASCII characters converted
| to lowercase ASCII and vice versa.
|
| title(...)
| B.title() -> copy of B
|
| Return a titlecased version of B, i.e. ASCII words start with uppercase
| characters, all remaining cased characters have lowercase.
|
| translate(self, table, /, delete=b'')
| Return a copy with each character mapped by the given translation table.
|
| table
| Translation table, which must be a bytes object of length 256.
|
| All characters occurring in the optional argument delete are removed.
| The remaining characters are mapped through the given translation table.
|
| upper(...)
| B.upper() -> copy of B
|
| Return a copy of B with all ASCII characters converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The original string is never truncated.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| fromhex(string, /)
| Create a bytes object from a string of hexadecimal numbers.
|
| Spaces between two numbers are accepted.
| Example: bytes.fromhex('B9 01EF') -> b'\\xb9\\x01\\xef'.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| maketrans(frm, to, /)
| Return a translation table useable for the bytes or bytearray translate method.
|
| The returned table will be one where each byte in frm is mapped to the byte at
| the same position in to.
|
| The bytes objects frm and to must be of the same length.
class classmethod(object)
| classmethod(function) -> method
|
| Convert a function to be a class method.
|
| A class method receives the class as implicit first argument,
| just like an instance method receives the instance.
| To declare a class method, use this idiom:
|
| class C:
| @classmethod
| def f(cls, arg1, arg2, argN):
| ...
|
| It can be called either on the class (e.g. C.f()) or on an instance
| (e.g. C().f()). The instance is ignored except for its class.
| If a class method is called for a derived class, the derived class
| object is passed as the implied first argument.
|
| Class methods are different than C++ or Java static methods.
| If you want those, see the staticmethod builtin.
|
| Methods defined here:
|
| __get__(self, instance, owner=None, /)
| Return an attribute of instance, which is of type owner.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
|
| __func__
|
| __isabstractmethod__
|
| __wrapped__
class complex(object)
| complex(real=0, imag=0)
|
| Create a complex number from a string or numbers.
|
| If a string is given, parse it as a complex number.
| If a single number is given, convert it to a complex number.
| If the 'real' or 'imag' arguments are given, create a complex number
| with the specified real and imaginary components.
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __bool__(self, /)
| True if self else False
|
| __complex__(self, /)
| Convert this value to exact type complex.
|
| __eq__(self, value, /)
| Return self==value.
|
| __format__(self, format_spec, /)
| Convert to a string according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __repr__(self, /)
| Return repr(self).
|
| __rmul__(self, value, /)
| Return value*self.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| conjugate(self, /)
| Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| imag
| the imaginary part of a complex number
|
| real
| the real part of a complex number
class dict(object)
| dict() -> new empty dictionary
| dict(mapping) -> new dictionary initialized from a mapping object's
| (key, value) pairs
| dict(iterable) -> new dictionary initialized as if via:
| d = {}
| for k, v in iterable:
| d[k] = v
| dict(**kwargs) -> new dictionary initialized with the name=value pairs
| in the keyword argument list. For example: dict(one=1, two=2)
|
| Built-in subclasses:
| StgDict
|
| Methods defined here:
|
| __contains__(self, key, /)
| True if the dictionary has the specified key, else False.
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __ior__(self, value, /)
| Return self|=value.
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __or__(self, value, /)
| Return self|value.
|
| __repr__(self, /)
| Return repr(self).
|
| __reversed__(self, /)
| Return a reverse iterator over the dict keys.
|
| __ror__(self, value, /)
| Return value|self.
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sizeof__(...)
| D.__sizeof__() -> size of D in memory, in bytes
|
| clear(...)
| D.clear() -> None. Remove all items from D.
|
| copy(...)
| D.copy() -> a shallow copy of D
|
| get(self, key, default=None, /)
| Return the value for key if key is in the dictionary, else default.
|
| items(...)
| D.items() -> a set-like object providing a view on D's items
|
| keys(...)
| D.keys() -> a set-like object providing a view on D's keys
|
| pop(...)
| D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
|
| If the key is not found, return the default if given; otherwise,
| raise a KeyError.
|
| popitem(self, /)
| Remove and return a (key, value) pair as a 2-tuple.
|
| Pairs are returned in LIFO (last-in, first-out) order.
| Raises KeyError if the dict is empty.
|
| setdefault(self, key, default=None, /)
| Insert key with a value of default if key is not in the dictionary.
|
| Return the value for key if key is in the dictionary, else default.
|
| update(...)
| D.update([E, ]**F) -> None. Update D from dict/iterable E and F.
| If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
| If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v
| In either case, this is followed by: for k in F: D[k] = F[k]
|
| values(...)
| D.values() -> an object providing a view on D's values
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__(...)
| See PEP 585
|
| fromkeys(iterable, value=None, /)
| Create a new dictionary with keys from iterable and values set to value.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class enumerate(object)
| enumerate(iterable, start=0)
|
| Return an enumerate object.
|
| iterable
| an object supporting iteration
|
| The enumerate object yields pairs containing a count (from start, which
| defaults to zero) and a value yielded by the iterable argument.
|
| enumerate is useful for obtaining an indexed list:
| (0, seq[0]), (1, seq[1]), (2, seq[2]), ...
|
| Methods defined here:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __iter__(self, /)
| Implement iter(self).
|
| __next__(self, /)
| Implement next(self).
|
| __reduce__(...)
| Return state information for pickling.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__(...)
| See PEP 585
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
class filter(object)
| filter(function or None, iterable) --> filter object
|
| Return an iterator yielding those items of iterable for which function(item)
| is true. If function is None, return the items that are true.
|
| Methods defined here:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __iter__(self, /)
| Implement iter(self).
|
| __next__(self, /)
| Implement next(self).
|
| __reduce__(...)
| Return state information for pickling.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
class float(object)
| float(x=0, /)
|
| Convert a string or number to a floating-point number, if possible.
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(self, /)
| Return the ceiling as an Integral.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(self, /)
| Return the floor as an Integral.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Formats the float according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __int__(self, /)
| int(self)
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __round__(self, ndigits=None, /)
| Return the Integral closest to x, rounding half toward even.
|
| When an argument is passed, work like built-in round(x, ndigits).
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(self, /)
| Return the Integral closest to x between 0 and x.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is exactly equal to the original float.
|
| The ratio is in lowest terms and has a positive denominator. Raise
| OverflowError on infinities and a ValueError on NaNs.
|
| >>> (10.0).as_integer_ratio()
| (10, 1)
| >>> (0.0).as_integer_ratio()
| (0, 1)
| >>> (-.25).as_integer_ratio()
| (-1, 4)
|
| conjugate(self, /)
| Return self, the complex conjugate of any float.
|
| hex(self, /)
| Return a hexadecimal representation of a floating-point number.
|
| >>> (-0.1).hex()
| '-0x1.999999999999ap-4'
| >>> 3.14159.hex()
| '0x1.921f9f01b866ep+1'
|
| is_integer(self, /)
| Return True if the float is an integer.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __getformat__(typestr, /)
| You probably don't want to use this function.
|
| typestr
| Must be 'double' or 'float'.
|
| It exists mainly to be used in Python's test suite.
|
| This function returns whichever of 'unknown', 'IEEE, big-endian' or 'IEEE,
| little-endian' best describes the format of floating-point numbers used by the
| C type named by typestr.
|
| fromhex(string, /)
| Create a floating-point number from a hexadecimal string.
|
| >>> float.fromhex('0x1.ffffp10')
| 2047.984375
| >>> float.fromhex('-0x1p-1074')
| -5e-324
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| imag
| the imaginary part of a complex number
|
| real
| the real part of a complex number
class frozenset(object)
| frozenset() -> empty frozenset object
| frozenset(iterable) -> frozenset object
|
| Build an immutable unordered collection of unique elements.
|
| Methods defined here:
|
| __and__(self, value, /)
| Return self&value.
|
| __contains__(...)
| x.__contains__(y) <==> y in x.
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __or__(self, value, /)
| Return self|value.
|
| __rand__(self, value, /)
| Return value&self.
|
| __reduce__(...)
| Return state information for pickling.
|
| __repr__(self, /)
| Return repr(self).
|
| __ror__(self, value, /)
| Return value|self.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(...)
| S.__sizeof__() -> size of S in memory, in bytes
|
| __sub__(self, value, /)
| Return self-value.
|
| __xor__(self, value, /)
| Return self^value.
|
| copy(...)
| Return a shallow copy of a set.
|
| difference(...)
| Return the difference of two or more sets as a new set.
|
| (i.e. all elements that are in this set but not the others.)
|
| intersection(...)
| Return the intersection of two sets as a new set.
|
| (i.e. all elements that are in both sets.)
|
| isdisjoint(...)
| Return True if two sets have a null intersection.
|
| issubset(self, other, /)
| Test whether every element in the set is in other.
|
| issuperset(self, other, /)
| Test whether every element in other is in the set.
|
| symmetric_difference(...)
| Return the symmetric difference of two sets as a new set.
|
| (i.e. all elements that are in exactly one of the sets.)
|
| union(...)
| Return the union of sets as a new set.
|
| (i.e. all elements that are in either set.)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__(...)
| See PEP 585
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
class int(object)
| int([x]) -> integer
| int(x, base=10) -> integer
|
| Convert a number or string to an integer, or return 0 if no arguments
| are given. If x is a number, return x.__int__(). For floating-point
| numbers, this truncates towards zero.
|
| If x is not a number or if base is given, then x must be a string,
| bytes, or bytearray instance representing an integer literal in the
| given base. The literal can be preceded by '+' or '-' and be surrounded
| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
| Base 0 means to interpret the base from the string as an integer literal.
| >>> int('0b100', base=0)
| 4
|
| Built-in subclasses:
| bool
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Convert to a string according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
class list(object)
| list(iterable=(), /)
|
| Built-in mutable sequence.
|
| If no argument is given, the constructor creates a new empty list.
| The argument must be an iterable if specified.
|
| Methods defined here:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, index, /)
| Return self[index].
|
| __gt__(self, value, /)
| Return self>value.
|
| __iadd__(self, value, /)
| Implement self+=value.
|
| __imul__(self, value, /)
| Implement self*=value.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __reversed__(self, /)
| Return a reverse iterator over the list.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sizeof__(self, /)
| Return the size of the list in memory, in bytes.
|
| append(self, object, /)
| Append object to the end of the list.
|
| clear(self, /)
| Remove all items from list.
|
| copy(self, /)
| Return a shallow copy of the list.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| extend(self, iterable, /)
| Extend list by appending elements from the iterable.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| insert(self, index, object, /)
| Insert object before index.
|
| pop(self, index=-1, /)
| Remove and return item at index (default last).
|
| Raises IndexError if list is empty or index is out of range.
|
| remove(self, value, /)
| Remove first occurrence of value.
|
| Raises ValueError if the value is not present.
|
| reverse(self, /)
| Reverse *IN PLACE*.
|
| sort(self, /, *, key=None, reverse=False)
| Sort the list in ascending order and return None.
|
| The sort is in-place (i.e. the list itself is modified) and stable (i.e. the
| order of two equal elements is maintained).
|
| If a key function is given, apply it once to each list item and sort them,
| ascending or descending, according to their function values.
|
| The reverse flag can be set to sort in descending order.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__(...)
| See PEP 585
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class map(object)
| map(func, *iterables) --> map object
|
| Make an iterator that computes the function using arguments from
| each of the iterables. Stops when the shortest iterable is exhausted.
|
| Methods defined here:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __iter__(self, /)
| Implement iter(self).
|
| __next__(self, /)
| Implement next(self).
|
| __reduce__(...)
| Return state information for pickling.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
class memoryview(object)
| memoryview(object)
|
| Create a new memoryview object which references the given object.
|
| Methods defined here:
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __enter__(...)
|
| __eq__(self, value, /)
| Return self==value.
|
| __exit__(...)
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __release_buffer__(self, buffer, /)
| Release the buffer object that exposes the underlying memory of the object.
|
| __repr__(self, /)
| Return repr(self).
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| cast(...)
| Cast a memoryview to a new format or shape.
|
| hex(...)
| Return the data in the buffer as a str of hexadecimal numbers.
|
| sep
| An optional single character or byte to separate hex bytes.
| bytes_per_sep
| How many bytes between separators. Positive values count from the
| right, negative values count from the left.
|
| Example:
| >>> value = memoryview(b'\xb9\x01\xef')
| >>> value.hex()
| 'b901ef'
| >>> value.hex(':')
| 'b9:01:ef'
| >>> value.hex(':', 2)
| 'b9:01ef'
| >>> value.hex(':', -2)
| 'b901:ef'
|
| release(self, /)
| Release the underlying buffer exposed by the memoryview object.
|
| tobytes(self, /, order='C')
| Return the data in the buffer as a byte string.
|
| Order can be {'C', 'F', 'A'}. When order is 'C' or 'F', the data of the
| original array is converted to C or Fortran order. For contiguous views,
| 'A' returns an exact copy of the physical memory. In particular, in-memory
| Fortran order is preserved. For non-contiguous views, the data is converted
| to C first. order=None is the same as order='C'.
|
| tolist(self, /)
| Return the data in the buffer as a list of elements.
|
| toreadonly(self, /)
| Return a readonly version of the memoryview.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| c_contiguous
| A bool indicating whether the memory is C contiguous.
|
| contiguous
| A bool indicating whether the memory is contiguous.
|
| f_contiguous
| A bool indicating whether the memory is Fortran contiguous.
|
| format
| A string containing the format (in struct module style)
| for each element in the view.
|
| itemsize
| The size in bytes of each element of the memoryview.
|
| nbytes
| The amount of space in bytes that the array would use in
| a contiguous representation.
|
| ndim
| An integer indicating how many dimensions of a multi-dimensional
| array the memory represents.
|
| obj
| The underlying object of the memoryview.
|
| readonly
| A bool indicating whether the memory is read only.
|
| shape
| A tuple of ndim integers giving the shape of the memory
| as an N-dimensional array.
|
| strides
| A tuple of ndim integers giving the size in bytes to access
| each element for each dimension of the array.
|
| suboffsets
| A tuple of integers used internally for PIL-style arrays.
class object
| The base class of the class hierarchy.
|
| When called, it accepts no arguments and returns a new featureless
| instance that has no instance attributes and cannot be given any.
|
| Built-in subclasses:
| AbsBackward0
| AccumulateGrad
| AcosBackward0
| AcoshBackward0
| ... and 749 other subclasses
|
| Methods defined here:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __dir__(self, /)
| Default dir() implementation.
|
| __eq__(self, value, /)
| Return self==value.
|
| __format__(self, format_spec, /)
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getstate__(self, /)
| Helper for pickle.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __reduce__(self, /)
| Helper for pickle.
|
| __reduce_ex__(self, protocol, /)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __sizeof__(self, /)
| Size of object in memory, in bytes.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __init_subclass__(...)
| This method is called when a class is subclassed.
|
| The default implementation does nothing. It may be
| overridden to extend subclasses.
|
| __subclasshook__(...)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __class__ = <class 'type'>
| type(object) -> the object's type
| type(name, bases, dict, **kwds) -> a new type
class property(object)
| property(fget=None, fset=None, fdel=None, doc=None)
|
| Property attribute.
|
| fget
| function to be used for getting an attribute value
| fset
| function to be used for setting an attribute value
| fdel
| function to be used for del'ing an attribute
| doc
| docstring
|
| Typical use is to define a managed attribute x:
|
| class C(object):
| def getx(self): return self._x
| def setx(self, value): self._x = value
| def delx(self): del self._x
| x = property(getx, setx, delx, "I'm the 'x' property.")
|
| Decorators make defining new properties or modifying existing ones easy:
|
| class C(object):
| @property
| def x(self):
| "I am the 'x' property."
| return self._x
| @x.setter
| def x(self, value):
| self._x = value
| @x.deleter
| def x(self):
| del self._x
|
| Methods defined here:
|
| __delete__(self, instance, /)
| Delete an attribute of instance.
|
| __get__(self, instance, owner=None, /)
| Return an attribute of instance, which is of type owner.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __set__(self, instance, value, /)
| Set an attribute of instance to value.
|
| __set_name__(...)
| Method to set name of a property.
|
| deleter(...)
| Descriptor to obtain a copy of the property with a different deleter.
|
| getter(...)
| Descriptor to obtain a copy of the property with a different getter.
|
| setter(...)
| Descriptor to obtain a copy of the property with a different setter.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __isabstractmethod__
|
| fdel
|
| fget
|
| fset
class range(object)
| range(stop) -> range object
| range(start, stop[, step]) -> range object
|
| Return an object that produces a sequence of integers from start (inclusive)
| to stop (exclusive) by step. range(i, j) produces i, i+1, i+2, ..., j-1.
| start defaults to 0, and stop is omitted! range(4) produces 0, 1, 2, 3.
| These are exactly the valid indices for a list of 4 elements.
| When step is given, it specifies the increment (or decrement).
|
| Methods defined here:
|
| __bool__(self, /)
| True if self else False
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __reversed__(...)
| Return a reverse iterator.
|
| count(...)
| rangeobject.count(value) -> integer -- return number of occurrences of value
|
| index(...)
| rangeobject.index(value) -> integer -- return index of value.
| Raise ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| start
|
| step
|
| stop
class reversed(object)
| reversed(sequence, /)
|
| Return a reverse iterator over the values of the given sequence.
|
| Methods defined here:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __iter__(self, /)
| Implement iter(self).
|
| __length_hint__(...)
| Private method returning an estimate of len(list(it)).
|
| __next__(self, /)
| Implement next(self).
|
| __reduce__(...)
| Return state information for pickling.
|
| __setstate__(...)
| Set state information for unpickling.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
class set(object)
| set() -> new empty set object
| set(iterable) -> new set object
|
| Build an unordered collection of unique elements.
|
| Methods defined here:
|
| __and__(self, value, /)
| Return self&value.
|
| __contains__(...)
| x.__contains__(y) <==> y in x.
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __gt__(self, value, /)
| Return self>value.
|
| __iand__(self, value, /)
| Return self&=value.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __ior__(self, value, /)
| Return self|=value.
|
| __isub__(self, value, /)
| Return self-=value.
|
| __iter__(self, /)
| Implement iter(self).
|
| __ixor__(self, value, /)
| Return self^=value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __or__(self, value, /)
| Return self|value.
|
| __rand__(self, value, /)
| Return value&self.
|
| __reduce__(...)
| Return state information for pickling.
|
| __repr__(self, /)
| Return repr(self).
|
| __ror__(self, value, /)
| Return value|self.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(...)
| S.__sizeof__() -> size of S in memory, in bytes
|
| __sub__(self, value, /)
| Return self-value.
|
| __xor__(self, value, /)
| Return self^value.
|
| add(...)
| Add an element to a set.
|
| This has no effect if the element is already present.
|
| clear(...)
| Remove all elements from this set.
|
| copy(...)
| Return a shallow copy of a set.
|
| difference(...)
| Return the difference of two or more sets as a new set.
|
| (i.e. all elements that are in this set but not the others.)
|
| difference_update(...)
| Remove all elements of another set from this set.
|
| discard(...)
| Remove an element from a set if it is a member.
|
| Unlike set.remove(), the discard() method does not raise
| an exception when an element is missing from the set.
|
| intersection(...)
| Return the intersection of two sets as a new set.
|
| (i.e. all elements that are in both sets.)
|
| intersection_update(...)
| Update a set with the intersection of itself and another.
|
| isdisjoint(...)
| Return True if two sets have a null intersection.
|
| issubset(self, other, /)
| Test whether every element in the set is in other.
|
| issuperset(self, other, /)
| Test whether every element in other is in the set.
|
| pop(...)
| Remove and return an arbitrary set element.
| Raises KeyError if the set is empty.
|
| remove(...)
| Remove an element from a set; it must be a member.
|
| If the element is not a member, raise a KeyError.
|
| symmetric_difference(...)
| Return the symmetric difference of two sets as a new set.
|
| (i.e. all elements that are in exactly one of the sets.)
|
| symmetric_difference_update(...)
| Update a set with the symmetric difference of itself and another.
|
| union(...)
| Return the union of sets as a new set.
|
| (i.e. all elements that are in either set.)
|
| update(...)
| Update a set with the union of itself and others.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__(...)
| See PEP 585
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class slice(object)
| slice(stop)
| slice(start, stop[, step])
|
| Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).
|
| Methods defined here:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __reduce__(...)
| Return state information for pickling.
|
| __repr__(self, /)
| Return repr(self).
|
| indices(...)
| S.indices(len) -> (start, stop, stride)
|
| Assuming a sequence of length len, calculate the start and stop
| indices, and the stride length of the extended slice described by
| S. Out of bounds indices are clipped in a manner consistent with the
| handling of normal slices.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| start
|
| step
|
| stop
class staticmethod(object)
| staticmethod(function) -> method
|
| Convert a function to be a static method.
|
| A static method does not receive an implicit first argument.
| To declare a static method, use this idiom:
|
| class C:
| @staticmethod
| def f(arg1, arg2, argN):
| ...
|
| It can be called either on the class (e.g. C.f()) or on an instance
| (e.g. C().f()). Both the class and the instance are ignored, and
| neither is passed implicitly as the first argument to the method.
|
| Static methods in Python are similar to those found in Java or C++.
| For a more advanced concept, see the classmethod builtin.
|
| Methods defined here:
|
| __call__(self, /, *args, **kwargs)
| Call self as a function.
|
| __get__(self, instance, owner=None, /)
| Return an attribute of instance, which is of type owner.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
|
| __func__
|
| __isabstractmethod__
|
| __wrapped__
class str(object)
| str(object='') -> str
| str(bytes_or_buffer[, encoding[, errors]]) -> str
|
| Create a new string object from the given object. If encoding or
| errors is specified, then the object must expose a data buffer
| that will be decoded using the given encoding and error handler.
| Otherwise, returns the result of object.__str__() (if defined)
| or repr(object).
| encoding defaults to sys.getdefaultencoding().
| errors defaults to 'strict'.
|
| Methods defined here:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __format__(self, format_spec, /)
| Return a formatted version of the string as described by format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| __str__(self, /)
| Return str(self).
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
class super(object)
| super() -> same as super(__class__, <first argument>)
| super(type) -> unbound super object
| super(type, obj) -> bound super object; requires isinstance(obj, type)
| super(type, type2) -> bound super object; requires issubclass(type2, type)
| Typical use to call a cooperative superclass method:
| class C(B):
| def meth(self, arg):
| super().meth(arg)
| This works for class methods too:
| class C(B):
| @classmethod
| def cmeth(cls, arg):
| super().cmeth(arg)
|
| Methods defined here:
|
| __get__(self, instance, owner=None, /)
| Return an attribute of instance, which is of type owner.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __self__
| the instance invoking super(); may be None
|
| __self_class__
| the type of the instance invoking super(); may be None
|
| __thisclass__
| the class invoking super()
class tuple(object)
| tuple(iterable=(), /)
|
| Built-in immutable sequence.
|
| If no argument is given, the constructor returns an empty tuple.
| If iterable is specified the tuple is initialized from iterable's items.
|
| If the argument is a tuple, the return value is the same object.
|
| Built-in subclasses:
| asyncgen_hooks
| UnraisableHookArgs
|
| Methods defined here:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__(...)
| See PEP 585
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
class type(object)
| type(object) -> the object's type
| type(name, bases, dict, **kwds) -> a new type
|
| Methods defined here:
|
| __call__(self, /, *args, **kwargs)
| Call self as a function.
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __dir__(self, /)
| Specialized __dir__ implementation for types.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __instancecheck__(self, instance, /)
| Check if an object is an instance.
|
| __or__(self, value, /)
| Return self|value.
|
| __repr__(self, /)
| Return repr(self).
|
| __ror__(self, value, /)
| Return value|self.
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __sizeof__(self, /)
| Return memory consumption of the type object.
|
| __subclasscheck__(self, subclass, /)
| Check if a class is a subclass.
|
| __subclasses__(self, /)
| Return a list of immediate subclasses.
|
| mro(self, /)
| Return a type's method resolution order.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __prepare__(...)
| __prepare__() -> dict
| used to create the namespace for the class statement
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __abstractmethods__
|
| __annotations__
|
| __dict__
|
| __text_signature__
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __base__ = <class 'object'>
| The base class of the class hierarchy.
|
| When called, it accepts no arguments and returns a new featureless
| instance that has no instance attributes and cannot be given any.
|
|
| __bases__ = (<class 'object'>,)
|
| __basicsize__ = 920
|
| __dictoffset__ = 264
|
| __flags__ = 2156420354
|
| __itemsize__ = 40
|
| __mro__ = (<class 'type'>, <class 'object'>)
|
| __type_params__ = ()
|
| __weakrefoffset__ = 368
class zip(object)
| zip(*iterables, strict=False) --> Yield tuples until an input is exhausted.
|
| >>> list(zip('abcdefg', range(3), range(4)))
| [('a', 0, 0), ('b', 1, 1), ('c', 2, 2)]
|
| The zip object yields n-length tuples, where n is the number of iterables
| passed as positional arguments to zip(). The i-th element in every tuple
| comes from the i-th iterable argument to zip(). This continues until the
| shortest argument is exhausted.
|
| If strict is true and one of the arguments is exhausted before the others,
| raise a ValueError.
|
| Methods defined here:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __iter__(self, /)
| Implement iter(self).
|
| __next__(self, /)
| Implement next(self).
|
| __reduce__(...)
| Return state information for pickling.
|
| __setstate__(...)
| Set state information for unpickling.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
FUNCTIONS
__build_class__(...)
__build_class__(func, name, /, *bases, [metaclass], **kwds) -> class
Internal helper function used by the class statement.
__import__(name, globals=None, locals=None, fromlist=(), level=0)
Import a module.
Because this function is meant for use by the Python
interpreter and not for general use, it is better to use
importlib.import_module() to programmatically import a module.
The globals argument is only used to determine the context;
they are not modified. The locals argument is unused. The fromlist
should be a list of names to emulate ``from name import ...``, or an
empty list to emulate ``import name``.
When importing a module from a package, note that __import__('A.B', ...)
returns package A when fromlist is empty, but its submodule B when
fromlist is not empty. The level argument is used to determine whether to
perform absolute or relative imports: 0 is absolute, while a positive number
is the number of parent directories to search relative to the current module.
abs(x, /)
Return the absolute value of the argument.
aiter(async_iterable, /)
Return an AsyncIterator for an AsyncIterable object.
all(iterable, /)
Return True if bool(x) is True for all values x in the iterable.
If the iterable is empty, return True.
anext(...)
async anext(aiterator[, default])
Return the next item from the async iterator. If default is given and the async
iterator is exhausted, it is returned instead of raising StopAsyncIteration.
any(iterable, /)
Return True if bool(x) is True for any x in the iterable.
If the iterable is empty, return False.
ascii(obj, /)
Return an ASCII-only representation of an object.
As repr(), return a string containing a printable representation of an
object, but escape the non-ASCII characters in the string returned by
repr() using \\x, \\u or \\U escapes. This generates a string similar
to that returned by repr() in Python 2.
bin(number, /)
Return the binary representation of an integer.
>>> bin(2796202)
'0b1010101010101010101010'
breakpoint(...)
breakpoint(*args, **kws)
Call sys.breakpointhook(*args, **kws). sys.breakpointhook() must accept
whatever arguments are passed.
By default, this drops you into the pdb debugger.
callable(obj, /)
Return whether the object is callable (i.e., some kind of function).
Note that classes are callable, as are instances of classes with a
__call__() method.
chr(i, /)
Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.
compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1, *, _feature_version=-1)
Compile source into a code object that can be executed by exec() or eval().
The source code may represent a Python module, statement or expression.
The filename will be used for run-time error messages.
The mode must be 'exec' to compile a module, 'single' to compile a
single (interactive) statement, or 'eval' to compile an expression.
The flags argument, if present, controls which future statements influence
the compilation of the code.
The dont_inherit argument, if true, stops the compilation inheriting
the effects of any future statements in effect in the code calling
compile; if absent or false these statements do influence the compilation,
in addition to any features explicitly specified.
delattr(obj, name, /)
Deletes the named attribute from the given object.
delattr(x, 'y') is equivalent to ``del x.y``
dir(...)
Show attributes of an object.
If called without an argument, return the names in the current scope.
Else, return an alphabetized list of names comprising (some of) the attributes
of the given object, and of attributes reachable from it.
If the object supplies a method named __dir__, it will be used; otherwise
the default dir() logic is used and returns:
for a module object: the module's attributes.
for a class object: its attributes, and recursively the attributes
of its bases.
for any other object: its attributes, its class's attributes, and
recursively the attributes of its class's base classes.
divmod(x, y, /)
Return the tuple (x//y, x%y). Invariant: div*y + mod == x.
eval(source, globals=None, locals=None, /)
Evaluate the given source in the context of globals and locals.
The source may be a string representing a Python expression
or a code object as returned by compile().
The globals must be a dictionary and locals can be any mapping,
defaulting to the current globals and locals.
If only globals is given, locals defaults to it.
exec(source, globals=None, locals=None, /, *, closure=None)
Execute the given source in the context of globals and locals.
The source may be a string representing one or more Python statements
or a code object as returned by compile().
The globals must be a dictionary and locals can be any mapping,
defaulting to the current globals and locals.
If only globals is given, locals defaults to it.
The closure must be a tuple of cellvars, and can only be used
when source is a code object requiring exactly that many cellvars.
format(value, format_spec='', /)
Return type(value).__format__(value, format_spec)
Many built-in types implement format_spec according to the
Format Specification Mini-language. See help('FORMATTING').
If type(value) does not supply a method named __format__
and format_spec is empty, then str(value) is returned.
See also help('SPECIALMETHODS').
getattr(...)
Get a named attribute from an object.
getattr(x, 'y') is equivalent to x.y
When a default argument is given, it is returned when the attribute doesn't
exist; without it, an exception is raised in that case.
globals()
Return the dictionary containing the current scope's global variables.
NOTE: Updates to this dictionary *will* affect name lookups in the current
global scope and vice-versa.
hasattr(obj, name, /)
Return whether the object has an attribute with the given name.
This is done by calling getattr(obj, name) and catching AttributeError.
hash(obj, /)
Return the hash value for the given object.
Two objects that compare equal must also have the same hash value, but the
reverse is not necessarily true.
hex(number, /)
Return the hexadecimal representation of an integer.
>>> hex(12648430)
'0xc0ffee'
id(obj, /)
Return the identity of an object.
This is guaranteed to be unique among simultaneously existing objects.
(CPython uses the object's memory address.)
input(prompt='', /)
Read a string from standard input. The trailing newline is stripped.
The prompt string, if given, is printed to standard output without a
trailing newline before reading input.
If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
On *nix systems, readline is used if available.
isinstance(obj, class_or_tuple, /)
Return whether an object is an instance of a class or of a subclass thereof.
A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to
check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)
or ...`` etc.
issubclass(cls, class_or_tuple, /)
Return whether 'cls' is derived from another class or is the same class.
A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to
check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)
or ...``.
iter(...)
Get an iterator from an object.
In the first form, the argument must supply its own iterator, or be a sequence.
In the second form, the callable is called until it returns the sentinel.
len(obj, /)
Return the number of items in a container.
locals()
Return a dictionary containing the current scope's local variables.
NOTE: Whether or not updates to this dictionary will affect name lookups in
the local scope and vice-versa is *implementation dependent* and not
covered by any backwards compatibility guarantees.
max(...)
max(iterable, *[, default=obj, key=func]) -> value
max(arg1, arg2, *args, *[, key=func]) -> value
With a single iterable argument, return its biggest item. The
default keyword-only argument specifies an object to return if
the provided iterable is empty.
With two or more arguments, return the largest argument.
min(...)
min(iterable, *[, default=obj, key=func]) -> value
min(arg1, arg2, *args, *[, key=func]) -> value
With a single iterable argument, return its smallest item. The
default keyword-only argument specifies an object to return if
the provided iterable is empty.
With two or more arguments, return the smallest argument.
next(...)
Return the next item from the iterator.
If default is given and the iterator is exhausted,
it is returned instead of raising StopIteration.
oct(number, /)
Return the octal representation of an integer.
>>> oct(342391)
'0o1234567'
open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
Open file and return a stream. Raise OSError upon failure.
file is either a text or byte string giving the name (and the path
if the file isn't in the current working directory) of the file to
be opened or an integer file descriptor of the file to be
wrapped. (If a file descriptor is given, it is closed when the
returned I/O object is closed, unless closefd is set to False.)
mode is an optional string that specifies the mode in which the file
is opened. It defaults to 'r' which means open for reading in text
mode. Other common values are 'w' for writing (truncating the file if
it already exists), 'x' for creating and writing to a new file, and
'a' for appending (which on some Unix systems, means that all writes
append to the end of the file regardless of the current seek position).
In text mode, if encoding is not specified the encoding used is platform
dependent: locale.getencoding() is called to get the current locale encoding.
(For reading and writing raw bytes use binary mode and leave encoding
unspecified.) The available modes are:
========= ===============================================================
Character Meaning
--------- ---------------------------------------------------------------
'r' open for reading (default)
'w' open for writing, truncating the file first
'x' create a new file and open it for writing
'a' open for writing, appending to the end of the file if it exists
'b' binary mode
't' text mode (default)
'+' open a disk file for updating (reading and writing)
========= ===============================================================
The default mode is 'rt' (open for reading text). For binary random
access, the mode 'w+b' opens and truncates the file to 0 bytes, while
'r+b' opens the file without truncation. The 'x' mode implies 'w' and
raises an `FileExistsError` if the file already exists.
Python distinguishes between files opened in binary and text modes,
even when the underlying operating system doesn't. Files opened in
binary mode (appending 'b' to the mode argument) return contents as
bytes objects without any decoding. In text mode (the default, or when
't' is appended to the mode argument), the contents of the file are
returned as strings, the bytes having been first decoded using a
platform-dependent encoding or using the specified encoding if given.
buffering is an optional integer used to set the buffering policy.
Pass 0 to switch buffering off (only allowed in binary mode), 1 to select
line buffering (only usable in text mode), and an integer > 1 to indicate
the size of a fixed-size chunk buffer. When no buffering argument is
given, the default buffering policy works as follows:
* Binary files are buffered in fixed-size chunks; the size of the buffer
is chosen using a heuristic trying to determine the underlying device's
"block size" and falling back on `io.DEFAULT_BUFFER_SIZE`.
On many systems, the buffer will typically be 4096 or 8192 bytes long.
* "Interactive" text files (files for which isatty() returns True)
use line buffering. Other text files use the policy described above
for binary files.
encoding is the name of the encoding used to decode or encode the
file. This should only be used in text mode. The default encoding is
platform dependent, but any encoding supported by Python can be
passed. See the codecs module for the list of supported encodings.
errors is an optional string that specifies how encoding errors are to
be handled---this argument should not be used in binary mode. Pass
'strict' to raise a ValueError exception if there is an encoding error
(the default of None has the same effect), or pass 'ignore' to ignore
errors. (Note that ignoring encoding errors can lead to data loss.)
See the documentation for codecs.register or run 'help(codecs.Codec)'
for a list of the permitted encoding error strings.
newline controls how universal newlines works (it only applies to text
mode). It can be None, '', '\n', '\r', and '\r\n'. It works as
follows:
* On input, if newline is None, universal newlines mode is
enabled. Lines in the input can end in '\n', '\r', or '\r\n', and
these are translated into '\n' before being returned to the
caller. If it is '', universal newline mode is enabled, but line
endings are returned to the caller untranslated. If it has any of
the other legal values, input lines are only terminated by the given
string, and the line ending is returned to the caller untranslated.
* On output, if newline is None, any '\n' characters written are
translated to the system default line separator, os.linesep. If
newline is '' or '\n', no translation takes place. If newline is any
of the other legal values, any '\n' characters written are translated
to the given string.
If closefd is False, the underlying file descriptor will be kept open
when the file is closed. This does not work when a file name is given
and must be True in that case.
A custom opener can be used by passing a callable as *opener*. The
underlying file descriptor for the file object is then obtained by
calling *opener* with (*file*, *flags*). *opener* must return an open
file descriptor (passing os.open as *opener* results in functionality
similar to passing None).
open() returns a file object whose type depends on the mode, and
through which the standard file operations such as reading and writing
are performed. When open() is used to open a file in a text mode ('w',
'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open
a file in a binary mode, the returned class varies: in read binary
mode, it returns a BufferedReader; in write binary and append binary
modes, it returns a BufferedWriter, and in read/write mode, it returns
a BufferedRandom.
It is also possible to use a string or bytearray as a file for both
reading and writing. For strings StringIO can be used like a file
opened in a text mode, and for bytes a BytesIO can be used like a file
opened in a binary mode.
ord(c, /)
Return the Unicode code point for a one-character string.
pow(base, exp, mod=None)
Equivalent to base**exp with 2 arguments or base**exp % mod with 3 arguments
Some types, such as ints, are able to use a more efficient algorithm when
invoked using the three argument form.
print(*args, sep=' ', end='\n', file=None, flush=False)
Prints the values to a stream, or to sys.stdout by default.
sep
string inserted between values, default a space.
end
string appended after the last value, default a newline.
file
a file-like object (stream); defaults to the current sys.stdout.
flush
whether to forcibly flush the stream.
repr(obj, /)
Return the canonical string representation of the object.
For many object types, including most builtins, eval(repr(obj)) == obj.
round(number, ndigits=None)
Round a number to a given precision in decimal digits.
The return value is an integer if ndigits is omitted or None. Otherwise
the return value has the same type as the number. ndigits may be negative.
setattr(obj, name, value, /)
Sets the named attribute on the given object to the specified value.
setattr(x, 'y', v) is equivalent to ``x.y = v``
sorted(iterable, /, *, key=None, reverse=False)
Return a new list containing all items from the iterable in ascending order.
A custom key function can be supplied to customize the sort order, and the
reverse flag can be set to request the result in descending order.
sum(iterable, /, start=0)
Return the sum of a 'start' value (default: 0) plus an iterable of numbers
When the iterable is empty, return the start value.
This function is intended specifically for use with numeric values and may
reject non-numeric types.
vars(...)
Show vars.
Without arguments, equivalent to locals().
With an argument, equivalent to object.__dict__.
DATA
Ellipsis = Ellipsis
False = False
None = None
NotImplemented = NotImplemented
True = True
__debug__ = True
copyright = Copyright (c) 2001-2023 Python Software Foundati...ematisc...
credits = Thanks to CWI, CNRI, BeOpen.com, Zope Corpor...opment. ...
exit = Use exit() or Ctrl-Z plus Return to exit
help = Type help() for interactive help, or help(object) for help abou...
license = Type license() to see the full license text
quit = Use quit() or Ctrl-Z plus Return to exit
FILE
(built-in)
torch.can_cast
Python Library Documentation: built-in function can_cast in module torch
can_cast(...)
can_cast(from_, to) -> bool
Determines if a type conversion is allowed under PyTorch casting rules
described in the type promotion :ref:`documentation <type-promotion-doc>`.
Args:
from\_ (dtype): The original :class:`torch.dtype`.
to (dtype): The target :class:`torch.dtype`.
Example::
>>> torch.can_cast(torch.double, torch.float)
True
>>> torch.can_cast(torch.float, torch.int)
False
torch.cartesian_prod
Python Library Documentation: function cartesian_prod in module torch.functional
cartesian_prod(*tensors: torch.Tensor) -> torch.Tensor
Do cartesian product of the given sequence of tensors. The behavior is similar to
python's `itertools.product`.
Args:
*tensors: any number of 1 dimensional tensors.
Returns:
Tensor: A tensor equivalent to converting all the input tensors into lists,
do `itertools.product` on these lists, and finally convert the resulting list
into tensor.
Example::
>>> import itertools
>>> a = [1, 2, 3]
>>> b = [4, 5]
>>> list(itertools.product(a, b))
[(1, 4), (1, 5), (2, 4), (2, 5), (3, 4), (3, 5)]
>>> tensor_a = torch.tensor(a)
>>> tensor_b = torch.tensor(b)
>>> torch.cartesian_prod(tensor_a, tensor_b)
tensor([[1, 4],
[1, 5],
[2, 4],
[2, 5],
[3, 4],
[3, 5]])
torch.cat
Python Library Documentation: built-in function cat in module torch
cat(...)
cat(tensors, dim=0, *, out=None) -> Tensor
Concatenates the given sequence of tensors in :attr:`tensors` in the given dimension.
All tensors must either have the same shape (except in the concatenating
dimension) or be a 1-D empty tensor with size ``(0,)``.
:func:`torch.cat` can be seen as an inverse operation for :func:`torch.split`
and :func:`torch.chunk`.
:func:`torch.cat` can be best understood via examples.
.. seealso::
:func:`torch.stack` concatenates the given sequence along a new dimension.
Args:
tensors (sequence of Tensors): Non-empty tensors provided must have the same shape,
except in the cat dimension.
dim (int, optional): the dimension over which the tensors are concatenated
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.randn(2, 3)
>>> x
tensor([[ 0.6580, -1.0969, -0.4614],
[-0.1034, -0.5790, 0.1497]])
>>> torch.cat((x, x, x), 0)
tensor([[ 0.6580, -1.0969, -0.4614],
[-0.1034, -0.5790, 0.1497],
[ 0.6580, -1.0969, -0.4614],
[-0.1034, -0.5790, 0.1497],
[ 0.6580, -1.0969, -0.4614],
[-0.1034, -0.5790, 0.1497]])
>>> torch.cat((x, x, x), 1)
tensor([[ 0.6580, -1.0969, -0.4614, 0.6580, -1.0969, -0.4614, 0.6580,
-1.0969, -0.4614],
[-0.1034, -0.5790, 0.1497, -0.1034, -0.5790, 0.1497, -0.1034,
-0.5790, 0.1497]])
torch.ccol_indices_copy
Python Library Documentation: built-in function ccol_indices_copy in module torch ccol_indices_copy(...)
torch.cdist
Python Library Documentation: function cdist in module torch.functional
cdist(x1, x2, p=2.0, compute_mode='use_mm_for_euclid_dist_if_necessary')
Computes batched the p-norm distance between each pair of the two collections of row vectors.
Args:
x1 (Tensor): input tensor where the last two dimensions represent the points and the feature dimension respectively.
The shape can be :math:`D_1 \times D_2 \times \cdots \times D_n \times P \times M`,
where :math:`P` is the number of points and :math:`M` is the feature dimension.
x2 (Tensor): input tensor where the last two dimensions also represent the points and the feature dimension respectively.
The shape can be :math:`D_1' \times D_2' \times \cdots \times D_m' \times R \times M`,
where :math:`R` is the number of points and :math:`M` is the feature dimension,
which should match the feature dimension of `x1`.
p: p value for the p-norm distance to calculate between each vector pair
:math:`\in [0, \infty]`.
compute_mode:
'use_mm_for_euclid_dist_if_necessary' - will use matrix multiplication approach to calculate
euclidean distance (p = 2) if P > 25 or R > 25
'use_mm_for_euclid_dist' - will always use matrix multiplication approach to calculate
euclidean distance (p = 2)
'donot_use_mm_for_euclid_dist' - will never use matrix multiplication approach to calculate
euclidean distance (p = 2)
Default: use_mm_for_euclid_dist_if_necessary.
If x1 has shape :math:`B \times P \times M` and x2 has shape :math:`B \times R \times M` then the
output will have shape :math:`B \times P \times R`.
This function is equivalent to `scipy.spatial.distance.cdist(input,'minkowski', p=p)`
if :math:`p \in (0, \infty)`. When :math:`p = 0` it is equivalent to
`scipy.spatial.distance.cdist(input, 'hamming') * M`. When :math:`p = \infty`, the closest
scipy function is `scipy.spatial.distance.cdist(xn, lambda x, y: np.abs(x - y).max())`.
Example:
>>> a = torch.tensor([[0.9041, 0.0196], [-0.3108, -2.4423], [-0.4821, 1.059]])
>>> a
tensor([[ 0.9041, 0.0196],
[-0.3108, -2.4423],
[-0.4821, 1.0590]])
>>> b = torch.tensor([[-2.1763, -0.4713], [-0.6986, 1.3702]])
>>> b
tensor([[-2.1763, -0.4713],
[-0.6986, 1.3702]])
>>> torch.cdist(a, b, p=2)
tensor([[3.1193, 2.0959],
[2.7138, 3.8322],
[2.2830, 0.3791]])
torch.cdouble
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.ceil
Python Library Documentation: built-in function ceil in module torch
ceil(...)
ceil(input, *, out=None) -> Tensor
Returns a new tensor with the ceil of the elements of :attr:`input`,
the smallest integer greater than or equal to each element.
For integer inputs, follows the array-api convention of returning a
copy of the input tensor.
.. math::
\text{out}_{i} = \left\lceil \text{input}_{i} \right\rceil
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-0.6341, -1.4208, -1.0900, 0.5826])
>>> torch.ceil(a)
tensor([-0., -1., -1., 1.])
torch.ceil_
Python Library Documentation: built-in function ceil_ in module torch ceil_(...)
torch.celu
Python Library Documentation: built-in function celu in module torch celu(...)
torch.celu_
Python Library Documentation: built-in function celu_ in module torch
celu_(...)
celu_(input, alpha=1.) -> Tensor
In-place version of :func:`~celu`.
torch.cfloat
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.chain_matmul
Python Library Documentation: function chain_matmul in module torch.functional
chain_matmul(*matrices, out=None)
Returns the matrix product of the :math:`N` 2-D tensors. This product is efficiently computed
using the matrix chain order algorithm which selects the order in which incurs the lowest cost in terms
of arithmetic operations (`[CLRS]`_). Note that since this is a function to compute the product, :math:`N`
needs to be greater than or equal to 2; if equal to 2 then a trivial matrix-matrix product is returned.
If :math:`N` is 1, then this is a no-op - the original matrix is returned as is.
.. warning::
:func:`torch.chain_matmul` is deprecated and will be removed in a future PyTorch release.
Use :func:`torch.linalg.multi_dot` instead, which accepts a list of two or more tensors
rather than multiple arguments.
Args:
matrices (Tensors...): a sequence of 2 or more 2-D tensors whose product is to be determined.
out (Tensor, optional): the output tensor. Ignored if :attr:`out` = ``None``.
Returns:
Tensor: if the :math:`i^{th}` tensor was of dimensions :math:`p_{i} \times p_{i + 1}`, then the product
would be of dimensions :math:`p_{1} \times p_{N + 1}`.
Example::
>>> # xdoctest: +SKIP
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> a = torch.randn(3, 4)
>>> b = torch.randn(4, 5)
>>> c = torch.randn(5, 6)
>>> d = torch.randn(6, 7)
>>> # will raise a deprecation warning
>>> torch.chain_matmul(a, b, c, d)
tensor([[ -2.3375, -3.9790, -4.1119, -6.6577, 9.5609, -11.5095, -3.2614],
[ 21.4038, 3.3378, -8.4982, -5.2457, -10.2561, -2.4684, 2.7163],
[ -0.9647, -5.8917, -2.3213, -5.2284, 12.8615, -12.2816, -2.5095]])
.. _`[CLRS]`: https://mitpress.mit.edu/books/introduction-algorithms-third-edition
torch.chalf
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.channel_shuffle
Python Library Documentation: built-in function channel_shuffle in module torch
channel_shuffle(...)
channel_shuffle(input, groups) -> Tensor
Divide the channels in a tensor of shape :math:`(*, C , H, W)`
into g groups and rearrange them as :math:`(*, C \frac g, g, H, W)`,
while keeping the original tensor shape.
See :class:`~torch.nn.ChannelShuffle` for details.
Args:
input (Tensor): the input tensor
groups (int): number of groups to divide channels in and rearrange.
Examples::
>>> input = torch.randn(1, 4, 2, 2)
>>> print(input)
[[[[1, 2],
[3, 4]],
[[5, 6],
[7, 8]],
[[9, 10],
[11, 12]],
[[13, 14],
[15, 16]],
]]
>>> output = torch.nn.functional.channel_shuffle(input, 2)
>>> print(output)
[[[[1, 2],
[3, 4]],
[[9, 10],
[11, 12]],
[[5, 6],
[7, 8]],
[[13, 14],
[15, 16]],
]]
torch.channels_last
Python Library Documentation: memory_format object class memory_format(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self).
torch.channels_last_3d
Python Library Documentation: memory_format object class memory_format(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self).
torch.cholesky
Python Library Documentation: built-in function cholesky in module torch
cholesky(...)
cholesky(input, upper=False, *, out=None) -> Tensor
Computes the Cholesky decomposition of a symmetric positive-definite
matrix :math:`A` or for batches of symmetric positive-definite matrices.
If :attr:`upper` is ``True``, the returned matrix ``U`` is upper-triangular, and
the decomposition has the form:
.. math::
A = U^TU
If :attr:`upper` is ``False``, the returned matrix ``L`` is lower-triangular, and
the decomposition has the form:
.. math::
A = LL^T
If :attr:`upper` is ``True``, and :math:`A` is a batch of symmetric positive-definite
matrices, then the returned tensor will be composed of upper-triangular Cholesky factors
of each of the individual matrices. Similarly, when :attr:`upper` is ``False``, the returned
tensor will be composed of lower-triangular Cholesky factors of each of the individual
matrices.
.. warning::
:func:`torch.cholesky` is deprecated in favor of :func:`torch.linalg.cholesky`
and will be removed in a future PyTorch release.
``L = torch.cholesky(A)`` should be replaced with
.. code:: python
L = torch.linalg.cholesky(A)
``U = torch.cholesky(A, upper=True)`` should be replaced with
.. code:: python
U = torch.linalg.cholesky(A).mH
This transform will produce equivalent results for all valid (symmetric positive definite) inputs.
Args:
input (Tensor): the input tensor :math:`A` of size :math:`(*, n, n)` where `*` is zero or more
batch dimensions consisting of symmetric positive-definite matrices.
upper (bool, optional): flag that indicates whether to return a
upper or lower triangular matrix. Default: ``False``
Keyword args:
out (Tensor, optional): the output matrix
Example::
>>> a = torch.randn(3, 3)
>>> a = a @ a.mT + 1e-3 # make symmetric positive-definite
>>> l = torch.cholesky(a)
>>> a
tensor([[ 2.4112, -0.7486, 1.4551],
[-0.7486, 1.3544, 0.1294],
[ 1.4551, 0.1294, 1.6724]])
>>> l
tensor([[ 1.5528, 0.0000, 0.0000],
[-0.4821, 1.0592, 0.0000],
[ 0.9371, 0.5487, 0.7023]])
>>> l @ l.mT
tensor([[ 2.4112, -0.7486, 1.4551],
[-0.7486, 1.3544, 0.1294],
[ 1.4551, 0.1294, 1.6724]])
>>> a = torch.randn(3, 2, 2) # Example for batched input
>>> a = a @ a.mT + 1e-03 # make symmetric positive-definite
>>> l = torch.cholesky(a)
>>> z = l @ l.mT
>>> torch.dist(z, a)
tensor(2.3842e-07)
torch.cholesky_inverse
Python Library Documentation: built-in function cholesky_inverse in module torch
cholesky_inverse(...)
cholesky_inverse(L, upper=False, *, out=None) -> Tensor
Computes the inverse of a complex Hermitian or real symmetric
positive-definite matrix given its Cholesky decomposition.
Let :math:`A` be a complex Hermitian or real symmetric positive-definite matrix,
and :math:`L` its Cholesky decomposition such that:
.. math::
A = LL^{\text{H}}
where :math:`L^{\text{H}}` is the conjugate transpose when :math:`L` is complex,
and the transpose when :math:`L` is real-valued.
Computes the inverse matrix :math:`A^{-1}`.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :math:`A` is a batch of matrices
then the output has the same batch dimensions.
Args:
L (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
consisting of lower or upper triangular Cholesky decompositions of
symmetric or Hermitian positive-definite matrices.
upper (bool, optional): flag that indicates whether :math:`L` is lower triangular
or upper triangular. Default: ``False``
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Example::
>>> A = torch.randn(3, 3)
>>> A = A @ A.T + torch.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix
>>> L = torch.linalg.cholesky(A) # Extract Cholesky decomposition
>>> torch.cholesky_inverse(L)
tensor([[ 1.9314, 1.2251, -0.0889],
[ 1.2251, 2.4439, 0.2122],
[-0.0889, 0.2122, 0.1412]])
>>> A.inverse()
tensor([[ 1.9314, 1.2251, -0.0889],
[ 1.2251, 2.4439, 0.2122],
[-0.0889, 0.2122, 0.1412]])
>>> A = torch.randn(3, 2, 2, dtype=torch.complex64)
>>> A = A @ A.mH + torch.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices
>>> L = torch.linalg.cholesky(A)
>>> torch.dist(torch.inverse(A), torch.cholesky_inverse(L))
tensor(5.6358e-7)
torch.cholesky_solve
Python Library Documentation: built-in function cholesky_solve in module torch
cholesky_solve(...)
cholesky_solve(B, L, upper=False, *, out=None) -> Tensor
Computes the solution of a system of linear equations with complex Hermitian
or real symmetric positive-definite lhs given its Cholesky decomposition.
Let :math:`A` be a complex Hermitian or real symmetric positive-definite matrix,
and :math:`L` its Cholesky decomposition such that:
.. math::
A = LL^{\text{H}}
where :math:`L^{\text{H}}` is the conjugate transpose when :math:`L` is complex,
and the transpose when :math:`L` is real-valued.
Returns the solution :math:`X` of the following linear system:
.. math::
AX = B
Supports inputs of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :math:`A` or :math:`B` is a batch of matrices
then the output has the same batch dimensions.
Args:
B (Tensor): right-hand side tensor of shape `(*, n, k)`
where :math:`*` is zero or more batch dimensions
L (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
consisting of lower or upper triangular Cholesky decompositions of
symmetric or Hermitian positive-definite matrices.
upper (bool, optional): flag that indicates whether :math:`L` is lower triangular
or upper triangular. Default: ``False``.
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Example::
>>> A = torch.randn(3, 3)
>>> A = A @ A.T + torch.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix
>>> L = torch.linalg.cholesky(A) # Extract Cholesky decomposition
>>> B = torch.randn(3, 2)
>>> torch.cholesky_solve(B, L)
tensor([[ -8.1625, 19.6097],
[ -5.8398, 14.2387],
[ -4.3771, 10.4173]])
>>> A.inverse() @ B
tensor([[ -8.1626, 19.6097],
[ -5.8398, 14.2387],
[ -4.3771, 10.4173]])
>>> A = torch.randn(3, 2, 2, dtype=torch.complex64)
>>> A = A @ A.mH + torch.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices
>>> L = torch.linalg.cholesky(A)
>>> B = torch.randn(2, 1, dtype=torch.complex64)
>>> X = torch.cholesky_solve(B, L)
>>> torch.dist(X, A.inverse() @ B)
tensor(1.6881e-5)
torch.choose_qparams_optimized
Python Library Documentation: built-in function choose_qparams_optimized in module torch choose_qparams_optimized(...)
torch.chunk
Python Library Documentation: built-in function chunk in module torch
chunk(...)
chunk(input: Tensor, chunks: int, dim: int = 0) -> Tuple[Tensor, ...]
Attempts to split a tensor into the specified number of chunks. Each chunk is a view of
the input tensor.
.. note::
This function may return fewer than the specified number of chunks!
.. seealso::
:func:`torch.tensor_split` a function that always returns exactly the specified number of chunks
If the tensor size along the given dimension :attr:`dim` is divisible by :attr:`chunks`,
all returned chunks will be the same size.
If the tensor size along the given dimension :attr:`dim` is not divisible by :attr:`chunks`,
all returned chunks will be the same size, except the last one.
If such division is not possible, this function may return fewer
than the specified number of chunks.
Arguments:
input (Tensor): the tensor to split
chunks (int): number of chunks to return
dim (int): dimension along which to split the tensor
Example:
>>> torch.arange(11).chunk(6)
(tensor([0, 1]),
tensor([2, 3]),
tensor([4, 5]),
tensor([6, 7]),
tensor([8, 9]),
tensor([10]))
>>> torch.arange(12).chunk(6)
(tensor([0, 1]),
tensor([2, 3]),
tensor([4, 5]),
tensor([6, 7]),
tensor([8, 9]),
tensor([10, 11]))
>>> torch.arange(13).chunk(6)
(tensor([0, 1, 2]),
tensor([3, 4, 5]),
tensor([6, 7, 8]),
tensor([ 9, 10, 11]),
tensor([12]))
torch.clamp
Python Library Documentation: built-in function clamp in module torch
clamp(...)
clamp(input, min=None, max=None, *, out=None) -> Tensor
Clamps all elements in :attr:`input` into the range `[` :attr:`min`, :attr:`max` `]`.
Letting min_value and max_value be :attr:`min` and :attr:`max`, respectively, this returns:
.. math::
y_i = \min(\max(x_i, \text{min\_value}_i), \text{max\_value}_i)
If :attr:`min` is ``None``, there is no lower bound.
Or, if :attr:`max` is ``None`` there is no upper bound.
.. note::
If :attr:`min` is greater than :attr:`max` :func:`torch.clamp(..., min, max) <torch.clamp>`
sets all elements in :attr:`input` to the value of :attr:`max`.
Args:
input (Tensor): the input tensor.
min (Number or Tensor, optional): lower-bound of the range to be clamped to
max (Number or Tensor, optional): upper-bound of the range to be clamped to
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-1.7120, 0.1734, -0.0478, -0.0922])
>>> torch.clamp(a, min=-0.5, max=0.5)
tensor([-0.5000, 0.1734, -0.0478, -0.0922])
>>> min = torch.linspace(-1, 1, steps=4)
>>> torch.clamp(a, min=min)
tensor([-1.0000, 0.1734, 0.3333, 1.0000])
torch.clamp_
Python Library Documentation: built-in function clamp_ in module torch clamp_(...)
torch.clamp_max
Python Library Documentation: built-in function clamp_max in module torch clamp_max(...)
torch.clamp_max_
Python Library Documentation: built-in function clamp_max_ in module torch clamp_max_(...)
torch.clamp_min
Python Library Documentation: built-in function clamp_min in module torch clamp_min(...)
torch.clamp_min_
Python Library Documentation: built-in function clamp_min_ in module torch clamp_min_(...)
torch.classes
Error rendering doc: '_ClassNamespace' object is not iterable
torch.classproperty
Python Library Documentation: function classproperty in module torch._utils classproperty(func)
torch.clear_autocast_cache
Python Library Documentation: built-in function clear_autocast_cache in module torch clear_autocast_cache(...)
torch.clip
Python Library Documentation: built-in function clip in module torch
clip(...)
clip(input, min=None, max=None, *, out=None) -> Tensor
Alias for :func:`torch.clamp`.
torch.clip_
Python Library Documentation: built-in function clip_ in module torch clip_(...)
torch.clone
Python Library Documentation: built-in function clone in module torch
clone(...)
clone(input, *, memory_format=torch.preserve_format) -> Tensor
Returns a copy of :attr:`input`.
.. note::
This function is differentiable, so gradients will flow back from the
result of this operation to :attr:`input`. To create a tensor without an
autograd relationship to :attr:`input` see :meth:`~Tensor.detach`.
In addition, when ``torch.preserve_format`` is used:
If the input tensor is dense (i.e., non-overlapping strided),
its memory format (including strides) is retained.
Otherwise (e.g., a non-dense view like a stepped slice),
the output is converted to the dense (contiguous) format.
Args:
input (Tensor): the input tensor.
Keyword args:
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned tensor. Default: ``torch.preserve_format``.
torch.col_indices_copy
Python Library Documentation: built-in function col_indices_copy in module torch
col_indices_copy(...)
Performs the same operation as :func:`torch.col_indices`, but all output tensors
are freshly created instead of aliasing the input.
torch.column_stack
Python Library Documentation: built-in function column_stack in module torch
column_stack(...)
column_stack(tensors, *, out=None) -> Tensor
Creates a new tensor by horizontally stacking the tensors in :attr:`tensors`.
Equivalent to ``torch.hstack(tensors)``, except each zero or one dimensional tensor ``t``
in :attr:`tensors` is first reshaped into a ``(t.numel(), 1)`` column before being stacked horizontally.
Args:
tensors (sequence of Tensors): sequence of tensors to concatenate
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([1, 2, 3])
>>> b = torch.tensor([4, 5, 6])
>>> torch.column_stack((a, b))
tensor([[1, 4],
[2, 5],
[3, 6]])
>>> a = torch.arange(5)
>>> b = torch.arange(10).reshape(5, 2)
>>> torch.column_stack((a, b, b))
tensor([[0, 0, 1, 0, 1],
[1, 2, 3, 2, 3],
[2, 4, 5, 4, 5],
[3, 6, 7, 6, 7],
[4, 8, 9, 8, 9]])
torch.combinations
Python Library Documentation: built-in function combinations in module torch
combinations(...)
combinations(input: Tensor, r: int = 2, with_replacement: bool = False) -> seq
Compute combinations of length :math:`r` of the given tensor. The behavior is similar to
python's `itertools.combinations` when `with_replacement` is set to `False`, and
`itertools.combinations_with_replacement` when `with_replacement` is set to `True`.
Arguments:
input (Tensor): 1D vector.
r (int, optional): number of elements to combine
with_replacement (bool, optional): whether to allow duplication in combination
Returns:
Tensor: A tensor equivalent to converting all the input tensors into lists, do
`itertools.combinations` or `itertools.combinations_with_replacement` on these
lists, and finally convert the resulting list into tensor.
Example::
>>> a = [1, 2, 3]
>>> list(itertools.combinations(a, r=2))
[(1, 2), (1, 3), (2, 3)]
>>> list(itertools.combinations(a, r=3))
[(1, 2, 3)]
>>> list(itertools.combinations_with_replacement(a, r=2))
[(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)]
>>> tensor_a = torch.tensor(a)
>>> torch.combinations(tensor_a)
tensor([[1, 2],
[1, 3],
[2, 3]])
>>> torch.combinations(tensor_a, r=3)
tensor([[1, 2, 3]])
>>> torch.combinations(tensor_a, with_replacement=True)
tensor([[1, 1],
[1, 2],
[1, 3],
[2, 2],
[2, 3],
[3, 3]])
torch.compile
Python Library Documentation: function compile in module torch
compile(model: collections.abc.Callable[~_InputT, ~_RetT] | None = None, *, fullgraph: bool = False, dynamic: bool | None = None, backend: str | collections.abc.Callable | None = None, mode: str | None = None, options: dict[str, str | int | bool | collections.abc.Callable] | None = None, name: str | None = None, disable: bool = False, recompile_limit: int | None = None, isolate_recompiles: bool = False, shapes_spec: Any = None) -> collections.abc.Callable[[collections.abc.Callable[~_InputT, ~_RetT]], collections.abc.Callable[~_InputT, ~_RetT]] | collections.abc.Callable[~_InputT, ~_RetT]
Optimizes given model/function using TorchDynamo and specified backend.
If you are compiling an :class:`torch.nn.Module`, you can also use :meth:`torch.nn.Module.compile`
to compile the module inplace without changing its structure.
Concretely, for every frame executed within the compiled region, we will attempt
to compile it and cache the compiled result on the code object for future
use. A single frame may be compiled multiple times if previous compiled
results are not applicable for subsequent calls (this is called a "guard
failure"), you can use TORCH_LOGS=guards to debug these situations.
Multiple compiled results can be associated with a frame up to
``torch._dynamo.config.recompile_limit``, which defaults to 8; at which
point we will fall back to eager. Note that compile caches are per
*code object*, not frame; if you dynamically create multiple copies of a
function, they will all share the same code cache.
Args:
model (Callable or None): Module/function to optimize
fullgraph (bool): If False (default), torch.compile attempts to discover compilable regions
in the function that it will optimize. If True, then we require that the entire function be
capturable into a single graph. If this is not possible (that is, if there are graph breaks),
then this will raise an error. This also opts into unbacked semantics, notably it will turn on
capture_scalar_outputs and capture_dynamic_output_shape_ops on by default.
dynamic (bool or None): Use dynamic shape tracing. When this is True, we will up-front attempt
to generate a kernel that is as dynamic as possible to avoid recompilations when
sizes change. This may not always work as some operations/optimizations will
force specialization; use TORCH_LOGS=dynamic to debug overspecialization.
When this is False, we will NEVER generate dynamic kernels, we will always specialize.
By default (None), we automatically detect if dynamism has occurred and compile a more
dynamic kernel upon recompile.
backend (str or Callable): backend to be used
- "inductor" is the default backend, which is a good balance between performance and overhead
- Non experimental in-tree backends can be seen with `torch._dynamo.list_backends()`
- Experimental or debug in-tree backends can be seen with `torch._dynamo.list_backends(None)`
- To register an out-of-tree custom backend:
https://docs.pytorch.org/docs/main/user_guide/torch_compiler/torch.compiler_custom_backends.html#registering-custom-backends
mode (str): Can be either "default", "reduce-overhead", "max-autotune" or "max-autotune-no-cudagraphs"
- "default" is the default mode, which is a good balance between performance and overhead
- "reduce-overhead" is a mode that reduces the overhead of python with CUDA graphs,
useful for small batches. Reduction of overhead can come at the cost of more memory
usage, as we will cache the workspace memory required for the invocation so that we
do not have to reallocate it on subsequent runs. Reduction of overhead is not guaranteed
to work; today, we only reduce overhead for CUDA only graphs which do not mutate inputs.
There are other circumstances where CUDA graphs are not applicable; use TORCH_LOGS=perf_hints
to debug.
- "max-autotune" is a mode that leverages Triton or template based matrix multiplications
on supported devices and Triton based convolutions on GPU.
It enables CUDA graphs by default on GPU.
- "max-autotune-no-cudagraphs" is a mode similar to "max-autotune" but without CUDA graphs
- To see the exact configs that each mode sets you can call `torch._inductor.list_mode_options()`
options (dict): A dictionary of options to pass to the backend. Some notable ones to try out are
- `epilogue_fusion` which fuses pointwise ops into templates. Requires `max_autotune` to also be set
- `max_autotune` which will profile to pick the best matmul configuration
- `fallback_random` which is useful when debugging accuracy issues
- `shape_padding` which pads matrix shapes to better align loads on GPUs especially for tensor cores
- `triton.cudagraphs` which will reduce the overhead of python with CUDA graphs
- `trace.enabled` which is the most useful debugging flag to turn on
- `trace.graph_diagram` which will show you a picture of your graph after fusion
- `guard_filter_fn` that controls which dynamo guards are saved with compilations.
This is an unsafe feature and there is no backward compatibility guarantee provided
for dynamo guards as data types.
For stable helper functions to use, see the documentations in `torch.compiler`, for example:
- `torch.compiler.skip_guard_on_inbuilt_nn_modules_unsafe`
- `torch.compiler.skip_guard_on_all_nn_modules_unsafe`
- `torch.compiler.keep_tensor_guards_unsafe`
- For inductor you can see the full list of configs that it supports by calling `torch._inductor.list_options()`
name (str or None): Optional identifier for the compiled region. When supported by downstream
tooling, this is surfaced on wrapped compiled-region higher-order operators and other debug metadata.
disable (bool): Turn torch.compile() into a no-op for testing
recompile_limit (int or None): Maximum number of recompilations allowed for this
``torch.compile()`` call before falling back to eager. If None (default), uses
the global ``torch._dynamo.config.recompile_limit`` (default 8). With
``fullgraph=True``, exceeding the limit raises ``FailOnRecompileLimitHit``.
isolate_recompiles (bool): If True, this ``torch.compile()`` call tracks
recompilations independently. By default, all ``torch.compile()`` calls on the
same function share a single set of compiled entries, so one call's
recompilations count against every other call's limit. With
``isolate_recompiles=True``, each call gets its own isolated set of entries.
Lookups for an isolated compile call will still fall back to entries from
non-isolated compile calls (BC-friendly reuse), but new compilations are
stored separately. ``recompile_limit`` is checked per-region;
``accumulated_recompile_limit`` is a global cap across all regions.
Default-strategy behavior is asymmetric: SKIP decisions (from
``skip_code``, ``@torch._dynamo.skip``, FX-generated code, etc.) are
inherited by isolated regions — those remain skipped. RUN_ONLY persisted
by a non-isolated region hitting its recompile limit does NOT bleed
into isolated regions — each region manages its own RUN_ONLY state.
Default False.
Example::
@torch.compile(options={"triton.cudagraphs": True}, fullgraph=True)
def foo(x):
return torch.sin(x) + torch.cos(x)
torch.compiled_with_cxx11_abi
Python Library Documentation: function compiled_with_cxx11_abi in module torch
compiled_with_cxx11_abi() -> bool
Returns whether PyTorch was built with _GLIBCXX_USE_CXX11_ABI=1
torch.compiler
Python Library Documentation: package torch.compiler in torch
NAME
torch.compiler - # mypy: allow-untyped-defs
PACKAGE CONTENTS
_cache
config
FUNCTIONS
allow_in_graph(fn)
Tells the compiler frontend (Dynamo) to skip symbolic introspection of the function
and instead directly write it to the graph when encountered.
If you are using :func:`torch.compile` (with backend="inductor" (the default)), or
:func:`torch.export.export`, and trying to black-box a Python function throughout
all tracing, do not use this API.
Instead, please create a custom operator (see `PyTorch Custom Operators Landing Page
<https://pytorch.org/tutorials/advanced/custom_ops_landing_page.html>`_)
.. warning::
If you're a typical torch.compile user (e.g. you're applying torch.compile to
a model to make it run faster), you probably don't want to use this function.
:func:`allow_in_graph` is a footgun because it skips the compiler frontend
(Dynamo) that is responsible for doing safety checks (graph breaks, handling
closures, etc). Incorrect usage will lead to difficult-to-debug silent
incorrectness issues.
Given a Python function with no allow_in_graph decorator, regular execution
of torch.compile traces through the function. :func:`allow_in_graph` changes
it so that the frontend does not trace inside the function, but the compiler
backend still traces through it. Compare this to custom operators, which
treats a function as a black box throughout the torch.compile stack. The following
table compares these mechanisms.
+------------------------+-----------------------+--------------------------------+
| Mechanism | Frontend (Dynamo) | Backend (AOTAutograd+Inductor) |
+========================+=======================+================================+
| no decorator | trace inside | trace inside |
+------------------------+-----------------------+--------------------------------+
| allow_in_graph | opaque callable | trace inside |
+------------------------+-----------------------+--------------------------------+
| custom op | opaque callable | opaque callable |
+------------------------+-----------------------+--------------------------------+
One common use case for :func:`allow_in_graph()` is as an escape hatch for the compiler
frontend: if you know the function works w.r.t. to the downstream components of the
compilation stack (AOTAutograd and Inductor) but there is a Dynamo bug that prevents it from
symbolically introspecting the function properly (or if your code is in C/C++ and
therefore cannot be introspected with Dynamo), then one can decorate said function
with :func:`allow_in_graph` to bypass Dynamo.
We require that ``fn`` adhere to the following restrictions. Failure to adhere
results in undefined behavior:
- The inputs to ``fn`` must be Proxy-able types in the FX graph. Valid types include:
Tensor/int/bool/float/None/List[Tensor?]/List[int?]/List[float?]
Tuple[Tensor?, ...]/Tuple[int?, ...]/Tuple[float?, ...]/torch.dtype/torch.device
- The outputs to ``fn`` must be Proxy-able types in the FX graph (see previous bullet)
- all Tensors used inside of ``fn`` must be passed directly as inputs to ``fn``
(as opposed to being captured variables).
Args:
fn: A callable representing the function to be included in the graph.
If ``fn`` is a list or tuple of callables it recursively applies
:func:`allow_in_graph()` to each function and returns a new list or
tuple containing the modified functions.
Example::
torch.compiler.allow_in_graph(my_custom_function)
@torch.compile(...)
def fn(x):
x = torch.add(x, 1)
x = my_custom_function(x)
x = torch.add(x, 1)
return x
fn(...)
Will capture a single graph containing ``my_custom_function()``.
assume_constant_result(fn)
This function is used to mark a function `fn` as having a constant result.
This allows the compiler to optimize away your function.
Returns The same function `fn`
Args:
fn: The function to be marked as having a constant result.
.. warning::
`assume_constant_result` can if invalid cause safety and soundness issues, :func:`torch.compile`
will not attempt to validate whether the constant assumption is true or not
compile(*args, **kwargs)
See :func:`torch.compile` for details on the arguments for this function.
cudagraph_mark_step_begin()
Indicates that a new iteration of inference or training is about to begin.
CUDA Graphs will free tensors of a prior iteration. A new iteration is started on each invocation of
torch.compile, so long as there is not a pending backward that has not been called.
If that heuristic is wrong, such as in the following example, manually mark it with this api.
.. code-block:: python
@torch.compile(mode="reduce-overhead")
def rand_foo():
return torch.rand([4], device="cuda")
for _ in range(5):
torch.compiler.cudagraph_mark_step_begin()
rand_foo() + rand_foo()
For more details, see `torch.compiler_cudagraph_trees <https://docs.pytorch.org/docs/main/user_guide/torch_compiler/torch.compiler_cudagraph_trees.html>`__ # noqa: B950
disable(fn=None, recursive=True, *, reason=None)
This function provides a decorator to disable compilation on a function.
It also provides the option of recursively disabling called functions.
Args:
fn (optional): The function to disable
recursive (optional): A boolean value indicating whether the disabling should be recursive.
reason (optional): A string value indicating the reason for disabling the function.
get_default_backend() -> str | collections.abc.Callable[..., typing.Any]
Return the current default backend for ``torch.compile``.
Returns:
The current default backend (string or callable). Initially ``"inductor"``.
is_compiling() -> bool
Indicates whether a graph is executed/traced as part of torch.compile() or torch.export().
Note that there are 2 other related flags that should deprecated eventually:
* torch._dynamo.external_utils.is_compiling()
* torch._utils.is_compiling()
Example::
>>> def forward(self, x):
>>> if not torch.compiler.is_compiling():
>>> pass # ...logic that is not needed in a compiled/traced graph...
>>>
>>> # ...rest of the function...
is_dynamo_compiling() -> bool
Indicates whether a graph is traced via TorchDynamo.
It's stricter than is_compiling() flag, as it would only be set to True when
TorchDynamo is used.
Example::
>>> def forward(self, x):
>>> if not torch.compiler.is_dynamo_compiling():
>>> pass # ...logic that is not needed in a TorchDynamo-traced graph...
>>>
>>> # ...rest of the function...
is_exporting() -> bool
Indicated whether we're under exporting.
It's stricter than is_compiling() flag, as it would only be set to True when
torch.export is used.
Example::
>>> def forward(self, x):
>>> if not torch.compiler.is_exporting():
>>> pass # ...logic that is not needed in export...
>>>
>>> # ...rest of the function...
keep_portable_guards_unsafe(guard_entries)
A common function to only keep guards that can be used in both Python and non-Python environments.
This includes:
- Tensor metadata and dynamic shape information.
- Global contexts state (e.g. autocast, no_grad, etc.)
This is unsafe to use by default.
To use this API, use guard_filter_fn argument while calling torch.compile
>> opt_mod = torch.compile(
>> mod,
>> options={"guard_filter_fn": torch.compiler.keep_global_context_and_tensor_guards_unsafe},
>> )
keep_tensor_guards_unsafe(guard_entries, keep_parameters=False)
A common function to keep tensor guards on all tensors. This is unsafe to
use by default. But if you don't expect any changes in the model code, you
can just keep the tensor guards.
>> opt_mod = torch.compile(
>> mod,
>> options={"guard_filter_fn": torch.compiler.keep_tensor_guards},
>> )
list_backends(exclude_tags=('debug', 'experimental')) -> list[str]
Return valid strings that can be passed to `torch.compile(..., backend="name")`.
Args:
exclude_tags(optional): A tuple of strings representing tags to exclude.
load_cache_artifacts(serialized_artifacts: bytes) -> torch.compiler._cache.CacheInfo | None
Hot loads cache artifacts that were previously serialized via
save_cache_artifacts
Example:
# From a previous invocation
artifacts = torch.compiler.save_cache_artifacts()
torch.compiler.load_cache_artifacts(artifacts[0])
load_compiled_function(file: io.IOBase, *, f_globals: dict[str, object] | None = None, external_data: dict[str, typing.Any] | None = None) -> collections.abc.Callable[..., typing.Any]
Load an aot-compiled function from a file.
.. warning::
This API is currently experimental and subject to change.
Args:
file: A file-like object containing the serialized compiled function.
f_globals: Optional global scope enclosing the compiled function.
external_data: Optional data to be loaded into the runtime environment
of the compiled function. This should contains the same
data as AOTCompileResult.external_data returned from save_compiled_function() call.
Returns:
A torch-compiled function with compilation preloaded from disk.
nested_compile_region(fn=None, *, options: torch._higher_order_ops.invoke_subgraph.NestedCompileRegionOptions | None = None, max_reuse_entries: int = 8, reuse_hash_fn=None)
Tells **``torch.compile``** that the marked set of operations forms a nested
compile region (which is often repeated in the full model) whose code can be
compiled once and safely reused. ``nested_compile_region`` can also be used
as a decorator.
During **``torch.compile``** tracing, the compiler applies *hierarchical
compilation* with ``nested_compile_region``: it emits optimized code for the
marked region the first time it is encountered and re-emits (or "stamps
out") the previously compiled code on every subsequent invocation. This can
substantially reduce overall compile time for deeply-stacked,
structurally-identical components such as the transformer layers of a
large-language-model (LLM).
Outside a ``torch.compile`` context—i.e., in standard eager execution—the
call is a no-op, so existing workflows remain unaffected.
Note that ``nested_compile_region`` **does not** promise that a region will
be compiled exactly once. If the compiler detects that new input conditions
(shape, dtype, device, stride, globals etc.) make the cached version invalid
to reuse, it will transparently re-compile the region. Using it is
therefore *safe*: correctness is always preserved, and you pay the extra
compilation cost only when required.
Args:
fn: The function to wrap
options: Optional backend to use for compiling the subgraph.
Warning: this is an experimental feature under development and
not ready for use yet.
max_reuse_entries: Maximum number of reuse cache entries per function
before raising an error. If this limit is hit, guards keep failing
across invocations and hierarchical compilation is not effective.
reuse_hash_fn: Optional callable that takes the same ``*args, **kwargs``
as the wrapped function and returns an integer hash key. When
provided, Dynamo traces this function to obtain a constant integer
and uses it as the cache key for subgraph reuse, bypassing the
automatic fingerprint/guard machinery. Two calls that produce the
same hash key reuse the same cached subgraph. The hash function
must be fully traceable (no graph breaks) and must return a
constant integer.
reset() -> None
Reset the in-process compiler state.
This function clears Dynamo's in-memory compilation caches and related
process-local state used by :func:`torch.compile`. It does not delete
filesystem caches, such as Inductor's disk cache.
save_cache_artifacts() -> tuple[bytes, torch.compiler._cache.CacheInfo] | None
Serializes all the cache artifacts that were created during the compilation
Example:
- Execute torch.compile
- Call torch.compiler.save_cache_artifacts()
set_default_backend(backend: str | collections.abc.Callable[..., typing.Any] | None) -> None
Set the default backend for ``torch.compile`` when no ``backend`` argument is specified.
Passing ``None`` resets the default back to ``"inductor"``.
Args:
backend: A backend name (string), a callable backend, or ``None``.
Example::
>>> torch.compiler.set_default_backend("eager")
>>> torch.compiler.get_default_backend()
'eager'
>>> torch.compiler.set_default_backend(None) # reset
>>> torch.compiler.get_default_backend()
'inductor'
set_enable_guard_collectives(enabled: bool)
Enables use of collectives *during* guard evaluation to synchronize behavior
across ranks. This is expensive: we have to issue a collective every time
we enter a compiled code region, even if no rank actually would need to
compile. This can help prevent NCCL hangs by ensuring that we never have a
situation where one rank starts recompiling while other ranks don't compile;
it is especially useful in conjunction with enable_compiler_collectives
where such a situation would immediately cause a hang (as it is necessary
for all ranks to compile at the same time to run compiler collectives). Like
compiler collectives, you can only run this on SPMD programs; you will hang
otherwise. Note that a guard collective is only issued if there is any
compiled code to guard on; if this the first time we encounter a frame or
the frame is skipped, we don't issue collectives.
Returns the previous setting of enabled.
set_stance(stance: str = 'default', *, skip_guard_eval_unsafe: bool = False, force_backend: str | collections.abc.Callable[..., typing.Any] | None = None)
Set the current stance of the compiler.
Can be used as a function, context manager, or decorator.
Do not use this function inside a `torch.compile` region - an error will be raised otherwise.
.. code-block:: python
@torch.compile
def foo(x): ...
@torch.compiler.set_stance("force_eager")
def bar():
# will not be compiled
foo(...)
bar()
with torch.compiler.set_stance("force_eager"):
# will also not be compiled
foo(...)
torch.compiler.set_stance("force_eager")
# will also not be compiled
foo(...)
torch.compiler.set_stance("default")
# will be compiled
foo(...)
Args:
stance: The stance to set the compiler to. Valid values are:
- "default": The default stance, used for normal compilation.
- "force_eager": Ignore all `torch.compile` directives.
- "eager_on_recompile": Run code eagerly when a recompile is necessary.
If there is cached compiled code valid for the input, it will still be used.
- "fail_on_recompile": Raise an error when recompiling a function.
- "eager_then_compile": Run the first invocation in eager mode, then compile on
subsequent calls. This is beneficial for dynamic shapes as it allows inferring
dynamism from the first two invocations instead of wasting a static compile on
the first invocation.
- "aot_eager_then_compile": Run the first invocation with AOT eager to get memory
benefits from activation checkpointing, then compile on subsequent calls. Like
eager_then_compile, this improves handling of dynamic shapes by avoiding an
initial static compile.
skip_guard_eval_unsafe: A flag to run only differentiating guards.
CAUTION - This flag is unsafe and should only be used if your setup
meets the following conditions.
torch.compile uses a guard system to support recompilations and
choose which compiled artifact to run at runtime. These guards,
though efficient, add some overhead, which may impact performance in
scenarios where you need to optimize for minimal guard processing
time. This API enables you to disable guard evaluation, assuming
that you have warmed up the compiled model with a sufficient variety
of inputs. This assumption means that, after the warmup phase, no
further recompilations will be necessary. If this assumption fails,
there is a risk of silently producing incorrect results (hence the
term "unsafe" in the API name).
force_backend: If `stance` is "default", this argument can be used to force `torch.compile`
to use a specific backend. Otherwise, an error is raised.
skip_all_guards_unsafe(guard_entries)
A function for skipping all guards on a compiled function.
WARNING: This function will drop all the safety guarantees from Dynamo
compiled function. Use this with caution.
To use this API, use guard_filter_fn argument while calling torch.compile
>> opt_mod = torch.compile(
>> mod,
>> options={"guard_filter_fn": torch.compiler.skip_all_guards_unsafe},
>> )
skip_guard_on_all_nn_modules_unsafe(guard_entries)
A common function to skip guards on all nn modules, both user defined as
well inbuilt nn modules (like torch.nn.Linear). This is unsafe to use by
default. But for majority of torch.compile users, the model code does not
modify the nn module attributes. They can benefit from reduction in guard
latency overhead using this API.
To use this API, use guard_filter_fn argument while calling torch.compile
>> opt_mod = torch.compile(
>> mod,
>> options={"guard_filter_fn": torch.compiler.skip_guard_on_all_nn_modules_unsafe},
>> )
skip_guard_on_globals_unsafe(guard_entries)
A common function to skip guards on all globals. This is unsafe to use by
default. But if you don't expect any changes in the globals, you can just
keep the tensor guards.
>> opt_mod = torch.compile(
>> mod,
>> options={"guard_filter_fn": torch.compiler.skip_guard_on_globals},
>> )
skip_guard_on_inbuilt_nn_modules_unsafe(guard_entries)
A common function to skip guards on the inbuilt nn modules like
torch.nn.Linear. This is unsafe to use by default. But for majority of
torch.compile users, the model code does not modify the inbuilt nn module
attributes. They can benefit from reduction in guard latency overhead using
this API.
To use this API, use guard_filter_fn argument while calling torch.compile
>> opt_mod = torch.compile(
>> mod,
>> options={"guard_filter_fn": torch.compiler.skip_guard_on_all_nn_modules_unsafe},
>> )
substitute_in_graph(original_fn: collections.abc.Callable[~_P, ~_R], *, can_constant_fold_through: bool = False, skip_signature_check: bool = False) -> collections.abc.Callable[[collections.abc.Callable[~_P, ~_R]], collections.abc.Callable[~_P, ~_R]]
Register a polyfill handler for a function, usually a C function from the C extension, to be
used in place of the original function when inlining the original function in the graph.
.. note::
The polyfill handler is only used when inlining the original function. It is not used when
the original function is called directly. In the eager mode, the decorated function calls
the performant C function rather than the polyfill handler.
The polyfill handler is a function that will be called in place of the original function when
inlining the original function. The polyfill handler should have the same signature and the same
behavior as the original function.
Args:
original_fn (callable): The original function, usually a C function, to register a polyfill
handler for.
can_constant_fold_through (bool, optional): Whether the polyfill handler can be constant
folded through. That is, if the polyfill handler is a pure function and its arguments
are constant, the result of the polyfill handler can be constant folded during the
compilation. Defaults to ``False``.
skip_signature_check (bool, optional): Whether to skip the signature check between the
original function and the polyfill handler. Defaults to ``False``.
Returns:
A decorator that registers the polyfill handler for the original function.
Example::
>>> import operator
>>> operator.indexOf([1, 2, 3, 4, 5], 3)
2
>>> torch.compile(operator.indexOf, fullgraph=True)([1, 2, 3, 4, 5], 3)
... # xdoctest: +SKIP("Long tracebacks")
Traceback (most recent call last):
...
torch._dynamo.exc.Unsupported: ...
>>> @torch.compiler.substitute_in_graph(operator.indexOf)
... def indexOf(a, b, /):
... for i, item in enumerate(a):
... if item is b or item == b:
... return i
... raise ValueError("sequence.index(x): x not in sequence")
>>>
>>> torch.compile(operator.indexOf, fullgraph=True)([1, 2, 3, 4, 5], 3)
2
wrap_numpy(fn)
Decorator that turns a function from ``np.ndarray``\ s to ``np.ndarray``\ s into a function
from ``torch.Tensor``\ s to ``torch.Tensor``\ s.
It is designed to be used with :func:`torch.compile` with ``fullgraph=True``. It allows to
compile a NumPy function as if it were a PyTorch function. This allows you to run NumPy code
on CUDA or compute its gradients.
.. note::
This decorator does not work without :func:`torch.compile`.
Example::
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
>>> # Compile a NumPy function as a Tensor -> Tensor function
>>> @torch.compile(fullgraph=True)
>>> @torch.compiler.wrap_numpy
>>> def fn(a: np.ndarray):
>>> return np.sum(a * a)
>>> # Execute the NumPy function using Tensors on CUDA and compute the gradients
>>> x = torch.arange(6, dtype=torch.float32, device="cuda", requires_grad=True)
>>> out = fn(x)
>>> out.backward()
>>> print(x.grad)
tensor([ 0., 2., 4., 6., 8., 10.], device='cuda:0')
DATA
__all__ = ['compile', 'config', 'assume_constant_result', 'reset', 'al...
__annotations__ = {'_is_compiling_flag': <class 'bool'>, '_is_exportin...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\compiler\__init__.py
torch.complex
Python Library Documentation: built-in function complex in module torch
complex(...)
complex(real, imag, *, out=None) -> Tensor
Constructs a complex tensor with its real part equal to :attr:`real` and its
imaginary part equal to :attr:`imag`.
Args:
real (Tensor): The real part of the complex tensor. Must be half, float or double.
imag (Tensor): The imaginary part of the complex tensor. Must be same dtype
as :attr:`real`.
Keyword args:
out (Tensor): If the inputs are ``torch.float32``, must be
``torch.complex64``. If the inputs are ``torch.float64``, must be
``torch.complex128``.
Example::
>>> real = torch.tensor([1, 2], dtype=torch.float32)
>>> imag = torch.tensor([3, 4], dtype=torch.float32)
>>> z = torch.complex(real, imag)
>>> z
tensor([(1.+3.j), (2.+4.j)])
>>> z.dtype
torch.complex64
torch.complex128
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.complex32
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.complex64
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.concat
Python Library Documentation: built-in function concat in module torch
concat(...)
concat(tensors, dim=0, *, out=None) -> Tensor
Alias of :func:`torch.cat`.
torch.concatenate
Python Library Documentation: built-in function concatenate in module torch
concatenate(...)
concatenate(tensors, axis=0, out=None) -> Tensor
Alias of :func:`torch.cat`.
torch.cond
Python Library Documentation: function cond in module torch
cond(pred: bool | int | float | torch.Tensor, true_fn: collections.abc.Callable, false_fn: collections.abc.Callable, operands: tuple | list = ()) -> Any
Conditionally applies `true_fn` or `false_fn`.
.. warning::
`torch.cond` is a prototype feature in PyTorch. It has limited support for input and output types.
Please look forward to a more stable implementation in a future version of PyTorch.
Read more about feature classification at: https://pytorch.org/blog/pytorch-feature-classification-changes/#prototype
`cond` is structured control flow operator. That is, it is like a Python if-statement,
but has restrictions on `true_fn`, `false_fn`, and `operands` that enable it to be
capturable using torch.compile and torch.export.
Assuming the constraints on `cond`'s arguments are met, `cond` is equivalent to the following::
def cond(pred, true_branch, false_branch, operands):
if pred:
return true_branch(*operands)
else:
return false_branch(*operands)
Args:
pred (Union[bool, torch.Tensor]): A boolean expression or a tensor with one element,
indicating which branch function to apply.
true_fn (Callable): A callable function (a -> b) that is within the
scope that is being traced.
false_fn (Callable): A callable function (a -> b) that is within the
scope that is being traced. The true branch and false branch must
have consistent input and outputs, meaning the inputs have to be
the same, and the outputs have to be the same type and shape. Int
output is also allowed. We'll make the output dynamic by turning it
into a symint.
operands (Tuple of possibly nested dict/list/tuple of torch.Tensor): A tuple of inputs to the
true/false functions. It can be empty if true_fn/false_fn doesn't require input. Defaults to ().
Example::
def true_fn(x: torch.Tensor):
return x.cos()
def false_fn(x: torch.Tensor):
return x.sin()
return cond(x.shape[0] > 4, true_fn, false_fn, (x,))
Restrictions:
- The conditional statement (aka `pred`) must meet one of the following constraints:
- It's a `torch.Tensor` with only one element, and torch.bool dtype
- It's a boolean expression, e.g. `x.shape[0] > 10` or `x.dim() > 1 and x.shape[1] > 10`
- The branch function (aka `true_fn`/`false_fn`) must meet all of the following constraints:
- The function signature must match with operands.
- The function must return a tensor with the same metadata, e.g. shape,
dtype, etc.
- The function cannot have in-place mutations on global variables.
(Note: in-place tensor operations such as `add_` for intermediate results
are allowed in a branch)
- The function can perform in-place mutations on its input tensors during inference (i.e.,
when `torch.is_grad_enabled()` is False).
Note: When using `torch.compile()` with a non-constant predicate, the outputs will always
be new tensors that do not share object identity with the original inputs.
Example::
def true_fn(x):
return x.sin_()
def false_fn(x):
return x + 1
def f(x):
return cond(x.sum() > 0, true_fn, false_fn, (x,))
x = torch.ones(4)
with torch.no_grad():
result = torch.compile(f)(x)
assert result is not x # result is a new tensor, not the original x
torch.conj
Python Library Documentation: built-in function conj in module torch
conj(...)
conj(input) -> Tensor
Returns a view of :attr:`input` with a flipped conjugate bit. If :attr:`input` has a non-complex dtype,
this function just returns :attr:`input`.
.. note::
:func:`torch.conj` performs a lazy conjugation, but the actual conjugated tensor can be materialized
at any time using :func:`torch.resolve_conj`.
.. warning:: In the future, :func:`torch.conj` may return a non-writeable view for an :attr:`input` of
non-complex dtype. It's recommended that programs not modify the tensor returned by :func:`torch.conj_physical`
when :attr:`input` is of non-complex dtype to be compatible with this change.
Args:
input (Tensor): the input tensor.
Example::
>>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
>>> x.is_conj()
False
>>> y = torch.conj(x)
>>> y.is_conj()
True
torch.conj_physical
Python Library Documentation: built-in function conj_physical in module torch
conj_physical(...)
conj_physical(input, *, out=None) -> Tensor
Computes the element-wise conjugate of the given :attr:`input` tensor.
If :attr:`input` has a non-complex dtype, this function just returns :attr:`input`.
.. note::
This performs the conjugate operation regardless of the fact conjugate bit is set or not.
.. warning:: In the future, :func:`torch.conj_physical` may return a non-writeable view for an :attr:`input` of
non-complex dtype. It's recommended that programs not modify the tensor returned by :func:`torch.conj_physical`
when :attr:`input` is of non-complex dtype to be compatible with this change.
.. math::
\text{out}_{i} = conj(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.conj_physical(torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))
tensor([-1 - 1j, -2 - 2j, 3 + 3j])
torch.conj_physical_
Python Library Documentation: built-in function conj_physical_ in module torch conj_physical_(...)
torch.constant_pad_nd
Python Library Documentation: built-in function constant_pad_nd in module torch constant_pad_nd(...)
torch.contiguous_format
Python Library Documentation: memory_format object class memory_format(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self).
torch.conv1d
Python Library Documentation: built-in function conv1d in module torch
conv1d(...)
conv1d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) -> Tensor
Applies a 1D convolution over an input signal composed of several input
planes.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
See :class:`~torch.nn.Conv1d` for details and output shape.
Note:
In some circumstances when given tensors on a CUDA device and using CuDNN, this operator may select a nondeterministic algorithm to increase performance. If this is undesirable, you can try to make the operation deterministic (potentially at a performance cost) by setting ``torch.backends.cudnn.deterministic = True``. See :doc:`/notes/randomness` for more information.
Note:
This operator supports complex data types i.e. ``complex32, complex64, complex128``.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iW)`
weight: filters of shape :math:`(\text{out\_channels} , \frac{\text{in\_channels}}{\text{groups}} , kW)`
bias: optional bias of shape :math:`(\text{out\_channels})`. Default: ``None``
stride: the stride of the convolving kernel. Can be a single number or
a one-element tuple `(sW,)`. Default: 1
padding: implicit paddings on both sides of the input. Can be a string {'valid', 'same'},
single number or a one-element tuple `(padW,)`. Default: 0
``padding='valid'`` is the same as no padding. ``padding='same'`` pads
the input so the output has the same shape as the input. However, this mode
doesn't support any stride values other than 1.
.. warning::
For ``padding='same'``, if the ``weight`` is even-length and
``dilation`` is odd in any dimension, a full :func:`pad` operation
may be needed internally. Lowering performance.
dilation: the spacing between kernel elements. Can be a single number or
a one-element tuple `(dW,)`. Default: 1
groups: split input into groups, :math:`\text{in\_channels}` should be divisible by
the number of groups. Default: 1
Examples::
>>> inputs = torch.randn(33, 16, 30)
>>> filters = torch.randn(20, 16, 5)
>>> F.conv1d(inputs, filters)
torch.conv2d
Python Library Documentation: built-in function conv2d in module torch
conv2d(...)
conv2d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) -> Tensor
Applies a 2D convolution over an input image composed of several input
planes.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
See :class:`~torch.nn.Conv2d` for details and output shape.
Note:
In some circumstances when given tensors on a CUDA device and using CuDNN, this operator may select a nondeterministic algorithm to increase performance. If this is undesirable, you can try to make the operation deterministic (potentially at a performance cost) by setting ``torch.backends.cudnn.deterministic = True``. See :doc:`/notes/randomness` for more information.
Note:
This operator supports complex data types i.e. ``complex32, complex64, complex128``.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iH , iW)`
weight: filters of shape :math:`(\text{out\_channels} , \frac{\text{in\_channels}}{\text{groups}} , kH , kW)`
bias: optional bias tensor of shape :math:`(\text{out\_channels})`. Default: ``None``
stride: the stride of the convolving kernel. Can be a single number or a
tuple `(sH, sW)`. Default: 1
padding: implicit paddings on both sides of the input. Can be a string {'valid', 'same'},
single number or a tuple `(padH, padW)`. Default: 0
``padding='valid'`` is the same as no padding. ``padding='same'`` pads
the input so the output has the same shape as the input. However, this mode
doesn't support any stride values other than 1.
.. warning::
For ``padding='same'``, if the ``weight`` is even-length and
``dilation`` is odd in any dimension, a full :func:`pad` operation
may be needed internally. Lowering performance.
dilation: the spacing between kernel elements. Can be a single number or
a tuple `(dH, dW)`. Default: 1
groups: split input into groups, both :math:`\text{in\_channels}` and :math:`\text{out\_channels}`
should be divisible by the number of groups. Default: 1
Examples::
>>> # With square kernels and equal stride
>>> filters = torch.randn(8, 4, 3, 3)
>>> inputs = torch.randn(1, 4, 5, 5)
>>> F.conv2d(inputs, filters, padding=1)
torch.conv3d
Python Library Documentation: built-in function conv3d in module torch
conv3d(...)
conv3d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) -> Tensor
Applies a 3D convolution over an input image composed of several input
planes.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
See :class:`~torch.nn.Conv3d` for details and output shape.
Note:
In some circumstances when given tensors on a CUDA device and using CuDNN, this operator may select a nondeterministic algorithm to increase performance. If this is undesirable, you can try to make the operation deterministic (potentially at a performance cost) by setting ``torch.backends.cudnn.deterministic = True``. See :doc:`/notes/randomness` for more information.
Note:
This operator supports complex data types i.e. ``complex32, complex64, complex128``.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iT , iH , iW)`
weight: filters of shape :math:`(\text{out\_channels} , \frac{\text{in\_channels}}{\text{groups}} , kT , kH , kW)`
bias: optional bias tensor of shape :math:`(\text{out\_channels})`. Default: None
stride: the stride of the convolving kernel. Can be a single number or a
tuple `(sT, sH, sW)`. Default: 1
padding: implicit paddings on both sides of the input. Can be a string {'valid', 'same'},
single number or a tuple `(padT, padH, padW)`. Default: 0
``padding='valid'`` is the same as no padding. ``padding='same'`` pads
the input so the output has the same shape as the input. However, this mode
doesn't support any stride values other than 1.
.. warning::
For ``padding='same'``, if the ``weight`` is even-length and
``dilation`` is odd in any dimension, a full :func:`pad` operation
may be needed internally. Lowering performance.
dilation: the spacing between kernel elements. Can be a single number or
a tuple `(dT, dH, dW)`. Default: 1
groups: split input into groups, :math:`\text{in\_channels}` should be divisible by
the number of groups. Default: 1
Examples::
>>> filters = torch.randn(33, 16, 3, 3, 3)
>>> inputs = torch.randn(20, 16, 50, 10, 20)
>>> F.conv3d(inputs, filters)
torch.conv_tbc
Python Library Documentation: built-in function conv_tbc in module torch
conv_tbc(...)
Applies a 1-dimensional sequence convolution over an input sequence.
Input and output dimensions are (Time, Batch, Channels) - hence TBC.
Args:
input: input tensor of shape :math:`(\text{sequence length} \times batch \times \text{in\_channels})`
weight: filter of shape (:math:`\text{kernel width} \times \text{in\_channels} \times \text{out\_channels}`)
bias: bias of shape (:math:`\text{out\_channels}`)
pad: number of timesteps to pad. Default: 0
torch.conv_transpose1d
Python Library Documentation: built-in function conv_transpose1d in module torch
conv_transpose1d(...)
conv_transpose1d(input, weight, bias=None, stride=1, padding=0, output_padding=0, groups=1, dilation=1) -> Tensor
Applies a 1D transposed convolution operator over an input signal
composed of several input planes, sometimes also called "deconvolution".
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
See :class:`~torch.nn.ConvTranspose1d` for details and output shape.
Note:
In some circumstances when given tensors on a CUDA device and using CuDNN, this operator may select a nondeterministic algorithm to increase performance. If this is undesirable, you can try to make the operation deterministic (potentially at a performance cost) by setting ``torch.backends.cudnn.deterministic = True``. See :doc:`/notes/randomness` for more information.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iW)`
weight: filters of shape :math:`(\text{in\_channels} , \frac{\text{out\_channels}}{\text{groups}} , kW)`
bias: optional bias of shape :math:`(\text{out\_channels})`. Default: None
stride: the stride of the convolving kernel. Can be a single number or a
tuple ``(sW,)``. Default: 1
padding: ``dilation * (kernel_size - 1) - padding`` zero-padding will be added to both
sides of each dimension in the input. Can be a single number or a tuple
``(padW,)``. Default: 0
output_padding: additional size added to one side of each dimension in the
output shape. Can be a single number or a tuple ``(out_padW)``. Default: 0
groups: split input into groups, :math:`\text{in\_channels}` should be divisible by the
number of groups. Default: 1
dilation: the spacing between kernel elements. Can be a single number or
a tuple ``(dW,)``. Default: 1
Examples::
>>> inputs = torch.randn(20, 16, 50)
>>> weights = torch.randn(16, 33, 5)
>>> F.conv_transpose1d(inputs, weights)
torch.conv_transpose2d
Python Library Documentation: built-in function conv_transpose2d in module torch
conv_transpose2d(...)
conv_transpose2d(input, weight, bias=None, stride=1, padding=0, output_padding=0, groups=1, dilation=1) -> Tensor
Applies a 2D transposed convolution operator over an input image
composed of several input planes, sometimes also called "deconvolution".
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
See :class:`~torch.nn.ConvTranspose2d` for details and output shape.
Note:
In some circumstances when given tensors on a CUDA device and using CuDNN, this operator may select a nondeterministic algorithm to increase performance. If this is undesirable, you can try to make the operation deterministic (potentially at a performance cost) by setting ``torch.backends.cudnn.deterministic = True``. See :doc:`/notes/randomness` for more information.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iH , iW)`
weight: filters of shape :math:`(\text{in\_channels} , \frac{\text{out\_channels}}{\text{groups}} , kH , kW)`
bias: optional bias of shape :math:`(\text{out\_channels})`. Default: None
stride: the stride of the convolving kernel. Can be a single number or a
tuple ``(sH, sW)``. Default: 1
padding: ``dilation * (kernel_size - 1) - padding`` zero-padding will be added to both
sides of each dimension in the input. Can be a single number or a tuple
``(padH, padW)``. Default: 0
output_padding: additional size added to one side of each dimension in the
output shape. Can be a single number or a tuple ``(out_padH, out_padW)``.
Default: 0
groups: split input into groups, :math:`\text{in\_channels}` should be divisible by the
number of groups. Default: 1
dilation: the spacing between kernel elements. Can be a single number or
a tuple ``(dH, dW)``. Default: 1
Examples::
>>> # With square kernels and equal stride
>>> inputs = torch.randn(1, 4, 5, 5)
>>> weights = torch.randn(4, 8, 3, 3)
>>> F.conv_transpose2d(inputs, weights, padding=1)
torch.conv_transpose3d
Python Library Documentation: built-in function conv_transpose3d in module torch
conv_transpose3d(...)
conv_transpose3d(input, weight, bias=None, stride=1, padding=0, output_padding=0, groups=1, dilation=1) -> Tensor
Applies a 3D transposed convolution operator over an input image
composed of several input planes, sometimes also called "deconvolution"
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
See :class:`~torch.nn.ConvTranspose3d` for details and output shape.
Note:
In some circumstances when given tensors on a CUDA device and using CuDNN, this operator may select a nondeterministic algorithm to increase performance. If this is undesirable, you can try to make the operation deterministic (potentially at a performance cost) by setting ``torch.backends.cudnn.deterministic = True``. See :doc:`/notes/randomness` for more information.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iT , iH , iW)`
weight: filters of shape :math:`(\text{in\_channels} , \frac{\text{out\_channels}}{\text{groups}} , kT , kH , kW)`
bias: optional bias of shape :math:`(\text{out\_channels})`. Default: None
stride: the stride of the convolving kernel. Can be a single number or a
tuple ``(sT, sH, sW)``. Default: 1
padding: ``dilation * (kernel_size - 1) - padding`` zero-padding will be added to both
sides of each dimension in the input. Can be a single number or a tuple
``(padT, padH, padW)``. Default: 0
output_padding: additional size added to one side of each dimension in the
output shape. Can be a single number or a tuple
``(out_padT, out_padH, out_padW)``. Default: 0
groups: split input into groups, :math:`\text{in\_channels}` should be divisible by the
number of groups. Default: 1
dilation: the spacing between kernel elements. Can be a single number or
a tuple `(dT, dH, dW)`. Default: 1
Examples::
>>> inputs = torch.randn(20, 16, 50, 10, 20)
>>> weights = torch.randn(16, 33, 3, 3, 3)
>>> F.conv_transpose3d(inputs, weights)
torch.convolution
Python Library Documentation: built-in function convolution in module torch convolution(...)
torch.copysign
Python Library Documentation: built-in function copysign in module torch
copysign(...)
copysign(input, other, *, out=None) -> Tensor
Create a new floating-point tensor with the magnitude of :attr:`input` and the sign of :attr:`other`, elementwise.
.. math::
\text{out}_{i} = \begin{cases}
-|\text{input}_{i}| & \text{if } \text{other}_{i} \leq -0.0 \\
|\text{input}_{i}| & \text{if } \text{other}_{i} \geq 0.0 \\
\end{cases}
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
and integer and float inputs.
Args:
input (Tensor): magnitudes.
other (Tensor or Number): contains value(s) whose signbit(s) are
applied to the magnitudes in :attr:`input`.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(5)
>>> a
tensor([-1.2557, -0.0026, -0.5387, 0.4740, -0.9244])
>>> torch.copysign(a, 1)
tensor([1.2557, 0.0026, 0.5387, 0.4740, 0.9244])
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.7079, 0.2778, -1.0249, 0.5719],
[-0.0059, -0.2600, -0.4475, -1.3948],
[ 0.3667, -0.9567, -2.5757, -0.1751],
[ 0.2046, -0.0742, 0.2998, -0.1054]])
>>> b = torch.randn(4)
tensor([ 0.2373, 0.3120, 0.3190, -1.1128])
>>> torch.copysign(a, b)
tensor([[ 0.7079, 0.2778, 1.0249, -0.5719],
[ 0.0059, 0.2600, 0.4475, -1.3948],
[ 0.3667, 0.9567, 2.5757, -0.1751],
[ 0.2046, 0.0742, 0.2998, -0.1054]])
>>> a = torch.tensor([1.])
>>> b = torch.tensor([-0.])
>>> torch.copysign(a, b)
tensor([-1.])
.. note::
copysign handles signed zeros. If the other argument has a negative zero (-0),
the corresponding output value will be negative.
torch.corrcoef
Python Library Documentation: built-in function corrcoef in module torch
corrcoef(...)
corrcoef(input) -> Tensor
Estimates the Pearson product-moment correlation coefficient matrix of the variables given by the :attr:`input` matrix,
where rows are the variables and columns are the observations.
.. note::
The correlation coefficient matrix R is computed using the covariance matrix C as given by
:math:`R_{ij} = \frac{ C_{ij} } { \sqrt{ C_{ii} * C_{jj} } }`
.. note::
Due to floating point rounding, the resulting array may not be Hermitian and its diagonal elements may not be 1.
The real and imaginary values are clipped to the interval [-1, 1] in an attempt to improve this situation.
Args:
input (Tensor): A 2D matrix containing multiple variables and observations, or a
Scalar or 1D vector representing a single variable.
Returns:
(Tensor) The correlation coefficient matrix of the variables.
.. seealso::
:func:`torch.cov` covariance matrix.
Example::
>>> x = torch.tensor([[0, 1, 2], [2, 1, 0]])
>>> torch.corrcoef(x)
tensor([[ 1., -1.],
[-1., 1.]])
>>> x = torch.randn(2, 4)
>>> x
tensor([[-0.2678, -0.0908, -0.3766, 0.2780],
[-0.5812, 0.1535, 0.2387, 0.2350]])
>>> torch.corrcoef(x)
tensor([[1.0000, 0.3582],
[0.3582, 1.0000]])
>>> torch.corrcoef(x[0])
tensor(1.)
torch.cos
Python Library Documentation: built-in function cos in module torch
cos(...)
cos(input, *, out=None) -> Tensor
Returns a new tensor with the cosine of the elements of :attr:`input` given in radians.
.. math::
\text{out}_{i} = \cos(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 1.4309, 1.2706, -0.8562, 0.9796])
>>> torch.cos(a)
tensor([ 0.1395, 0.2957, 0.6553, 0.5574])
torch.cos_
Python Library Documentation: built-in function cos_ in module torch cos_(...)
torch.cosh
Python Library Documentation: built-in function cosh in module torch
cosh(...)
cosh(input, *, out=None) -> Tensor
Returns a new tensor with the hyperbolic cosine of the elements of
:attr:`input`.
.. math::
\text{out}_{i} = \cosh(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.1632, 1.1835, -0.6979, -0.7325])
>>> torch.cosh(a)
tensor([ 1.0133, 1.7860, 1.2536, 1.2805])
.. note::
When :attr:`input` is on the CPU, the implementation of torch.cosh may use
the Sleef library, which rounds very large results to infinity or negative
infinity. See `here <https://sleef.org/purec.xhtml>`_ for details.
torch.cosh_
Python Library Documentation: built-in function cosh_ in module torch cosh_(...)
torch.cosine_embedding_loss
Python Library Documentation: built-in function cosine_embedding_loss in module torch cosine_embedding_loss(...)
torch.cosine_similarity
Python Library Documentation: built-in function cosine_similarity in module torch
cosine_similarity(...)
cosine_similarity(x1, x2, dim=1, eps=1e-8) -> Tensor
Returns cosine similarity between ``x1`` and ``x2``, computed along dim. ``x1`` and ``x2`` must be broadcastable
to a common shape. ``dim`` refers to the dimension in this common shape. Dimension ``dim`` of the output is
squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 fewer dimension.
.. math ::
\text{similarity} = \dfrac{x_1 \cdot x_2}{\max(\Vert x_1 \Vert _2, \epsilon) \cdot \max(\Vert x_2 \Vert _2, \epsilon)}
Supports :ref:`type promotion <type-promotion-doc>`.
Args:
x1 (Tensor): First input.
x2 (Tensor): Second input.
dim (int, optional): Dimension along which cosine similarity is computed. Default: 1
eps (float, optional): Small value to avoid division by zero.
Default: 1e-8
Example::
>>> input1 = torch.randn(100, 128)
>>> input2 = torch.randn(100, 128)
>>> output = F.cosine_similarity(input1, input2)
>>> print(output)
torch.count_nonzero
Python Library Documentation: built-in function count_nonzero in module torch
count_nonzero(...)
count_nonzero(input, dim=None) -> Tensor
Counts the number of non-zero values in the tensor :attr:`input` along the given :attr:`dim`.
If no dim is specified then all non-zeros in the tensor are counted.
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): Dim or tuple of dims along which to count non-zeros.
Example::
>>> x = torch.zeros(3,3)
>>> x[torch.randn(3,3) > 0.5] = 1
>>> x
tensor([[0., 1., 1.],
[0., 0., 0.],
[0., 0., 1.]])
>>> torch.count_nonzero(x)
tensor(3)
>>> torch.count_nonzero(x, dim=0)
tensor([0, 1, 2])
torch.cov
Python Library Documentation: built-in function cov in module torch
cov(...)
cov(input, *, correction=1, fweights=None, aweights=None) -> Tensor
Estimates the covariance matrix of the variables given by the :attr:`input` matrix, where rows are
the variables and columns are the observations.
A covariance matrix is a square matrix giving the covariance of each pair of variables. The diagonal contains
the variance of each variable (covariance of a variable with itself). By definition, if :attr:`input` represents
a single variable (Scalar or 1D) then its variance is returned.
The sample covariance of the variables :math:`x` and :math:`y` is given by:
.. math::
\text{cov}(x,y) = \frac{\sum^{N}_{i = 1}(x_{i} - \bar{x})(y_{i} - \bar{y})}{\max(0,~N~-~\delta N)}
where :math:`\bar{x}` and :math:`\bar{y}` are the simple means of the :math:`x` and :math:`y` respectively, and
:math:`\delta N` is the :attr:`correction`.
If :attr:`fweights` and/or :attr:`aweights` are provided, the weighted covariance
is calculated, which is given by:
.. math::
\text{cov}_w(x,y) = \frac{\sum^{N}_{i = 1}w_i(x_{i} - \mu_x^*)(y_{i} - \mu_y^*)}
{\max(0,~\sum^{N}_{i = 1}w_i~-~\frac{\sum^{N}_{i = 1}w_ia_i}{\sum^{N}_{i = 1}w_i}~\delta N)}
where :math:`w` denotes :attr:`fweights` or :attr:`aweights` (``f`` and ``a`` for brevity) based on whichever is
provided, or :math:`w = f \times a` if both are provided, and
:math:`\mu_x^* = \frac{\sum^{N}_{i = 1}w_ix_{i} }{\sum^{N}_{i = 1}w_i}` is the weighted mean of the variable. If not
provided, ``f`` and/or ``a`` can be seen as a :math:`\mathbb{1}` vector of appropriate size.
Args:
input (Tensor): A 2D matrix containing multiple variables and observations, or a
Scalar or 1D vector representing a single variable.
Keyword Args:
correction (int, optional): difference between the sample size and sample degrees of freedom.
Defaults to Bessel's correction, ``correction = 1`` which returns the unbiased estimate,
even if both :attr:`fweights` and :attr:`aweights` are specified. ``correction = 0``
will return the simple average. Defaults to ``1``.
fweights (tensor, optional): A Scalar or 1D tensor of observation vector frequencies representing the number of
times each observation should be repeated. Its numel must equal the number of columns of :attr:`input`.
Must have integral dtype. Ignored if ``None``. Defaults to ``None``.
aweights (tensor, optional): A Scalar or 1D array of observation vector weights.
These relative weights are typically large for observations considered "important" and smaller for
observations considered less "important". Its numel must equal the number of columns of :attr:`input`.
Must have floating point dtype. Ignored if ``None``. Defaults to ``None``.
Returns:
(Tensor) The covariance matrix of the variables.
.. seealso::
:func:`torch.corrcoef` normalized covariance matrix.
Example::
>>> x = torch.tensor([[0, 2], [1, 1], [2, 0]]).T
>>> x
tensor([[0, 1, 2],
[2, 1, 0]])
>>> torch.cov(x)
tensor([[ 1., -1.],
[-1., 1.]])
>>> torch.cov(x, correction=0)
tensor([[ 0.6667, -0.6667],
[-0.6667, 0.6667]])
>>> fw = torch.randint(1, 10, (3,))
>>> fw
tensor([1, 6, 9])
>>> aw = torch.rand(3)
>>> aw
tensor([0.4282, 0.0255, 0.4144])
>>> torch.cov(x, fweights=fw, aweights=aw)
tensor([[ 0.4169, -0.4169],
[-0.4169, 0.4169]])
torch.cpp
Python Library Documentation: module torch._C.cpp in torch._C
NAME
torch._C.cpp
SUBMODULES
nn
CLASSES
pybind11_builtins.pybind11_object(builtins.object)
OrderedModuleDict
OrderedTensorDict
class OrderedModuleDict(pybind11_builtins.pybind11_object)
| Method resolution order:
| OrderedModuleDict
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __contains__(...)
| __contains__(self: torch._C.cpp.OrderedModuleDict, arg0: str) -> bool
|
| __getitem__(...)
| __getitem__(*args, **kwargs)
| Overloaded function.
|
| 1. __getitem__(self: torch._C.cpp.OrderedModuleDict, arg0: str) -> torch::nn::Module
|
| 2. __getitem__(self: torch._C.cpp.OrderedModuleDict, arg0: typing.SupportsInt | typing.SupportsIndex) -> OrderedModuleDictItem
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(...)
| __iter__(self: torch._C.cpp.OrderedModuleDict) -> collections.abc.Iterator[OrderedModuleDictItem]
|
| __len__(...)
| __len__(self: torch._C.cpp.OrderedModuleDict) -> int
|
| items(...)
| items(self: torch._C.cpp.OrderedModuleDict) -> list[OrderedModuleDictItem]
|
| keys(...)
| keys(self: torch._C.cpp.OrderedModuleDict) -> list[str]
|
| values(...)
| values(self: torch._C.cpp.OrderedModuleDict) -> list[torch::nn::Module]
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class OrderedTensorDict(pybind11_builtins.pybind11_object)
| Method resolution order:
| OrderedTensorDict
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __contains__(...)
| __contains__(self: torch._C.cpp.OrderedTensorDict, arg0: str) -> bool
|
| __getitem__(...)
| __getitem__(*args, **kwargs)
| Overloaded function.
|
| 1. __getitem__(self: torch._C.cpp.OrderedTensorDict, arg0: str) -> torch.Tensor
|
| 2. __getitem__(self: torch._C.cpp.OrderedTensorDict, arg0: typing.SupportsInt | typing.SupportsIndex) -> OrderedTensorDictItem
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(...)
| __iter__(self: torch._C.cpp.OrderedTensorDict) -> collections.abc.Iterator[OrderedTensorDictItem]
|
| __len__(...)
| __len__(self: torch._C.cpp.OrderedTensorDict) -> int
|
| items(...)
| items(self: torch._C.cpp.OrderedTensorDict) -> list[OrderedTensorDictItem]
|
| keys(...)
| keys(self: torch._C.cpp.OrderedTensorDict) -> list[str]
|
| values(...)
| values(self: torch._C.cpp.OrderedTensorDict) -> list[torch.Tensor]
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
FILE
(built-in)
torch.cpu
Python Library Documentation: package torch.cpu in torch
NAME
torch.cpu
DESCRIPTION
This package implements abstractions found in ``torch.cuda``
to facilitate writing device-agnostic code.
PACKAGE CONTENTS
amp (package)
CLASSES
builtins.object
Event
Stream
contextlib.AbstractContextManager(abc.ABC)
StreamContext
class Event(builtins.object)
| Methods defined here:
|
| query(self) -> bool
|
| record(self, stream=None) -> None
|
| synchronize(self) -> None
|
| wait(self, stream=None) -> None
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Stream(builtins.object)
| Stream(priority: int = -1) -> None
|
| N.B. This class only exists to facilitate device-agnostic code
|
| Methods defined here:
|
| __init__(self, priority: int = -1) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| record_event(self) -> None
|
| wait_event(self, event) -> None
|
| wait_stream(self, stream) -> None
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class StreamContext(contextlib.AbstractContextManager)
| StreamContext(stream)
|
| Context-manager that selects a given stream.
|
| N.B. This class only exists to facilitate device-agnostic code
|
| Method resolution order:
| StreamContext
| contextlib.AbstractContextManager
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| __enter__(self)
| Return `self` upon entering the runtime context.
|
| __exit__(self, type: Any, value: Any, traceback: Any) -> None
| Raise any exception triggered within the runtime context.
|
| __init__(self, stream)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {'cur_stream': torch.cpu.Stream | None}
|
| ----------------------------------------------------------------------
| Class methods inherited from contextlib.AbstractContextManager:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| __subclasshook__(C)
| Abstract classes can override this to customize issubclass().
|
| This is invoked early on by abc.ABCMeta.__subclasscheck__().
| It should return True, False or NotImplemented. If it returns
| NotImplemented, the normal algorithm is used. Otherwise, it
| overrides the normal algorithm (and the outcome is cached).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from contextlib.AbstractContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
current_device() -> str
Returns current device for cpu. Always 'cpu'.
N.B. This function only exists to facilitate device-agnostic code
current_stream(device: torch.device | str | int | None = None) -> torch.cpu.Stream
Returns the currently selected :class:`Stream` for a given device.
Args:
device (torch.device or int, optional): Ignored.
N.B. This function only exists to facilitate device-agnostic code
device_count() -> int
Returns number of CPU devices (not cores). Always 1.
N.B. This function only exists to facilitate device-agnostic code
get_capabilities() -> collections.abc.Mapping[str, typing.Any]
Returns an immutable mapping of CPU capabilities detected at runtime.
This function queries the CPU for supported instruction sets and features
using cpuinfo. The result is cached after the first call for efficiency.
The returned mapping contains architecture-specific capabilities:
For x86/x86_64:
- SSE family: sse, sse2, sse3, ssse3, sse4_1, sse4_2, sse4a
- AVX family: avx, avx2, avx_vnni
- AVX-512 family: avx512_f, avx512_cd, avx512_dq, avx512_bw, avx512_vl,
avx512_ifma, avx512_vbmi, avx512_vbmi2, avx512_bitalg, avx512_vpopcntdq,
avx512_vnni, avx512_bf16, avx512_fp16, avx512_vp2intersect,
avx512_4vnniw, avx512_4fmaps
- AVX10 family: avx10_1, avx10_2
- AVX-VNNI-INT: avx_vnni_int8, avx_vnni_int16, avx_ne_convert
- AMX: amx_bf16, amx_tile, amx_int8, amx_fp16
- FMA: fma3, fma4
- Other: f16c, bmi, bmi2, popcnt, lzcnt, aes, sha, clflush, clflushopt, clwb
For ARM64:
- SIMD: neon, fp16_arith, bf16, i8mm, dot
- SVE: sve, sve2, sve_bf16, sve_max_length (when supported)
- SME: sme, sme2, sme_max_length (when supported)
- Other: atomics, fhm, rdm, crc32, aes, sha1, sha2, pmull
Common to all architectures:
- architecture: string identifying the CPU architecture
Returns:
MappingProxyType: An immutable mapping where keys are capability names
(e.g., 'avx2', 'sve') and values are booleans indicating
support, or integers for properties like vector lengths.
Example:
>>> caps = torch.cpu.get_capabilities()
>>> if caps.get("avx2", False):
... print("AVX2 is supported")
>>> print(f"Architecture: {caps['architecture']}")
is_available() -> bool
Returns a bool indicating if CPU is currently available.
N.B. This function only exists to facilitate device-agnostic code
is_initialized() -> bool
Returns True if the CPU is initialized. Always True.
N.B. This function only exists to facilitate device-agnostic code
set_device(device: torch.device | str | int | None) -> None
Sets the current device, in CPU we do nothing.
N.B. This function only exists to facilitate device-agnostic code
stream(stream: torch.cpu.Stream) -> contextlib.AbstractContextManager
Wrapper around the Context-manager StreamContext that
selects a given stream.
N.B. This function only exists to facilitate device-agnostic code
synchronize(device: torch.device | str | int | None = None) -> None
Waits for all kernels in all streams on the CPU device to complete.
Args:
device (torch.device or int, optional): ignored, there's only one CPU device.
N.B. This function only exists to facilitate device-agnostic code.
DATA
__all__ = ['is_available', 'is_initialized', 'synchronize', 'current_d...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\cpu\__init__.py
torch.cross
Python Library Documentation: built-in function cross in module torch
cross(...)
cross(input, other, dim=None, *, out=None) -> Tensor
Returns the cross product of vectors in dimension :attr:`dim` of :attr:`input`
and :attr:`other`.
Supports input of float, double, cfloat and cdouble dtypes. Also supports batches
of vectors, for which it computes the product along the dimension :attr:`dim`.
In this case, the output has the same batch dimensions as the inputs.
.. warning::
If :attr:`dim` is not given, it defaults to the first dimension found
with the size 3. Note that this might be unexpected.
This behavior is deprecated and will be changed to match that of :func:`torch.linalg.cross`
in a future release.
.. seealso::
:func:`torch.linalg.cross` which has dim=-1 as default.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
dim (int, optional): the dimension to take the cross-product in.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4, 3)
>>> a
tensor([[-0.3956, 1.1455, 1.6895],
[-0.5849, 1.3672, 0.3599],
[-1.1626, 0.7180, -0.0521],
[-0.1339, 0.9902, -2.0225]])
>>> b = torch.randn(4, 3)
>>> b
tensor([[-0.0257, -1.4725, -1.2251],
[-1.1479, -0.7005, -1.9757],
[-1.3904, 0.3726, -1.1836],
[-0.9688, -0.7153, 0.2159]])
>>> torch.cross(a, b, dim=1)
tensor([[ 1.0844, -0.5281, 0.6120],
[-2.4490, -1.5687, 1.9792],
[-0.8304, -1.3037, 0.5650],
[-1.2329, 1.9883, 1.0551]])
>>> torch.cross(a, b)
tensor([[ 1.0844, -0.5281, 0.6120],
[-2.4490, -1.5687, 1.9792],
[-0.8304, -1.3037, 0.5650],
[-1.2329, 1.9883, 1.0551]])
torch.crow_indices_copy
Python Library Documentation: built-in function crow_indices_copy in module torch
crow_indices_copy(...)
Performs the same operation as :func:`torch.crow_indices`, but all output tensors
are freshly created instead of aliasing the input.
torch.ctc_loss
Python Library Documentation: built-in function ctc_loss in module torch ctc_loss(...)
torch.ctypes
Python Library Documentation: package ctypes
NAME
ctypes - create and manipulate C data types in Python
MODULE REFERENCE
https://docs.python.org/3.12/library/ctypes.html
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
PACKAGE CONTENTS
_aix
_endian
macholib (package)
util
wintypes
CLASSES
_ctypes._SimpleCData(_ctypes._CData)
HRESULT
c_bool
c_byte
c_char
c_char_p
c_double
c_float
c_long
c_longlong
c_short
c_ubyte
c_ulong
c_ulonglong
c_ushort
c_void_p
c_wchar
c_wchar_p
py_object
builtins.Exception(builtins.BaseException)
ArgumentError
builtins.object
CDLL
OleDLL
PyDLL
WinDLL
LibraryLoader
class ArgumentError(builtins.Exception)
| Method resolution order:
| ArgumentError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class CDLL(builtins.object)
| CDLL(name, mode=0, handle=None, use_errno=False, use_last_error=False, winmode=None)
|
| An instance of this class represents a loaded dll/shared
| library, exporting functions using the standard C calling
| convention (named 'cdecl' on Windows).
|
| The exported functions can be accessed as attributes, or by
| indexing with the function name. Examples:
|
| <obj>.qsort -> callable object
| <obj>['qsort'] -> callable object
|
| Calling the functions releases the Python GIL during the call and
| reacquires it afterwards.
|
| Methods defined here:
|
| __getattr__(self, name)
|
| __getitem__(self, name_or_ordinal)
|
| __init__(self, name, mode=0, handle=None, use_errno=False, use_last_error=False, winmode=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class HRESULT(_ctypes._SimpleCData)
| Method resolution order:
| HRESULT
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.HRESULT'>
|
| __ctype_le__ = <class 'ctypes.HRESULT'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class LibraryLoader(builtins.object)
| LibraryLoader(dlltype)
|
| Methods defined here:
|
| LoadLibrary(self, name)
|
| __getattr__(self, name)
|
| __getitem__(self, name)
|
| __init__(self, dlltype)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class OleDLL(CDLL)
| OleDLL(name, mode=0, handle=None, use_errno=False, use_last_error=False, winmode=None)
|
| This class represents a dll exporting functions using the
| Windows stdcall calling convention, and returning HRESULT.
| HRESULT error values are automatically raised as OSError
| exceptions.
|
| Method resolution order:
| OleDLL
| CDLL
| builtins.object
|
| Methods inherited from CDLL:
|
| __getattr__(self, name)
|
| __getitem__(self, name_or_ordinal)
|
| __init__(self, name, mode=0, handle=None, use_errno=False, use_last_error=False, winmode=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from CDLL:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class PyDLL(CDLL)
| PyDLL(name, mode=0, handle=None, use_errno=False, use_last_error=False, winmode=None)
|
| This class represents the Python library itself. It allows
| accessing Python API functions. The GIL is not released, and
| Python exceptions are handled correctly.
|
| Method resolution order:
| PyDLL
| CDLL
| builtins.object
|
| Methods inherited from CDLL:
|
| __getattr__(self, name)
|
| __getitem__(self, name_or_ordinal)
|
| __init__(self, name, mode=0, handle=None, use_errno=False, use_last_error=False, winmode=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from CDLL:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class WinDLL(CDLL)
| WinDLL(name, mode=0, handle=None, use_errno=False, use_last_error=False, winmode=None)
|
| This class represents a dll exporting functions using the
| Windows stdcall calling convention.
|
| Method resolution order:
| WinDLL
| CDLL
| builtins.object
|
| Methods inherited from CDLL:
|
| __getattr__(self, name)
|
| __getitem__(self, name_or_ordinal)
|
| __init__(self, name, mode=0, handle=None, use_errno=False, use_last_error=False, winmode=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from CDLL:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class c_bool(_ctypes._SimpleCData)
| Method resolution order:
| c_bool
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_byte(_ctypes._SimpleCData)
| Method resolution order:
| c_byte
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_byte'>
|
| __ctype_le__ = <class 'ctypes.c_byte'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_char(_ctypes._SimpleCData)
| Method resolution order:
| c_char
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_char'>
|
| __ctype_le__ = <class 'ctypes.c_char'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_char_p(_ctypes._SimpleCData)
| Method resolution order:
| c_char_p
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Methods defined here:
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_param(...)
| Convert a Python object into a function call parameter.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_double(_ctypes._SimpleCData)
| Method resolution order:
| c_double
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_double'>
|
| __ctype_le__ = <class 'ctypes.c_double'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_float(_ctypes._SimpleCData)
| Method resolution order:
| c_float
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_float'>
|
| __ctype_le__ = <class 'ctypes.c_float'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_int = class c_long(_ctypes._SimpleCData)
| Method resolution order:
| c_long
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_long'>
|
| __ctype_le__ = <class 'ctypes.c_long'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_int16 = class c_short(_ctypes._SimpleCData)
| Method resolution order:
| c_short
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_short'>
|
| __ctype_le__ = <class 'ctypes.c_short'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_int32 = class c_long(_ctypes._SimpleCData)
| Method resolution order:
| c_long
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_long'>
|
| __ctype_le__ = <class 'ctypes.c_long'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_int64 = class c_longlong(_ctypes._SimpleCData)
| Method resolution order:
| c_longlong
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_longlong'>
|
| __ctype_le__ = <class 'ctypes.c_longlong'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_int8 = class c_byte(_ctypes._SimpleCData)
| Method resolution order:
| c_byte
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_byte'>
|
| __ctype_le__ = <class 'ctypes.c_byte'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_long(_ctypes._SimpleCData)
| Method resolution order:
| c_long
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_long'>
|
| __ctype_le__ = <class 'ctypes.c_long'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_longdouble = class c_double(_ctypes._SimpleCData)
| Method resolution order:
| c_double
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_double'>
|
| __ctype_le__ = <class 'ctypes.c_double'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_longlong(_ctypes._SimpleCData)
| Method resolution order:
| c_longlong
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_longlong'>
|
| __ctype_le__ = <class 'ctypes.c_longlong'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_short(_ctypes._SimpleCData)
| Method resolution order:
| c_short
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_short'>
|
| __ctype_le__ = <class 'ctypes.c_short'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_size_t = class c_ulonglong(_ctypes._SimpleCData)
| Method resolution order:
| c_ulonglong
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_ulonglong'>
|
| __ctype_le__ = <class 'ctypes.c_ulonglong'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_ssize_t = class c_longlong(_ctypes._SimpleCData)
| Method resolution order:
| c_longlong
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_longlong'>
|
| __ctype_le__ = <class 'ctypes.c_longlong'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_time_t = class c_longlong(_ctypes._SimpleCData)
| Method resolution order:
| c_longlong
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_longlong'>
|
| __ctype_le__ = <class 'ctypes.c_longlong'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_ubyte(_ctypes._SimpleCData)
| Method resolution order:
| c_ubyte
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_ubyte'>
|
| __ctype_le__ = <class 'ctypes.c_ubyte'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_uint = class c_ulong(_ctypes._SimpleCData)
| Method resolution order:
| c_ulong
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_ulong'>
|
| __ctype_le__ = <class 'ctypes.c_ulong'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_uint16 = class c_ushort(_ctypes._SimpleCData)
| Method resolution order:
| c_ushort
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_ushort'>
|
| __ctype_le__ = <class 'ctypes.c_ushort'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_uint32 = class c_ulong(_ctypes._SimpleCData)
| Method resolution order:
| c_ulong
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_ulong'>
|
| __ctype_le__ = <class 'ctypes.c_ulong'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_uint64 = class c_ulonglong(_ctypes._SimpleCData)
| Method resolution order:
| c_ulonglong
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_ulonglong'>
|
| __ctype_le__ = <class 'ctypes.c_ulonglong'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_uint8 = class c_ubyte(_ctypes._SimpleCData)
| Method resolution order:
| c_ubyte
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_ubyte'>
|
| __ctype_le__ = <class 'ctypes.c_ubyte'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_ulong(_ctypes._SimpleCData)
| Method resolution order:
| c_ulong
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_ulong'>
|
| __ctype_le__ = <class 'ctypes.c_ulong'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_ulonglong(_ctypes._SimpleCData)
| Method resolution order:
| c_ulonglong
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_ulonglong'>
|
| __ctype_le__ = <class 'ctypes.c_ulonglong'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_ushort(_ctypes._SimpleCData)
| Method resolution order:
| c_ushort
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __ctype_be__ = <class 'ctypes.c_ushort'>
|
| __ctype_le__ = <class 'ctypes.c_ushort'>
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_void_p(_ctypes._SimpleCData)
| Method resolution order:
| c_void_p
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Class methods defined here:
|
| from_param(...)
| Convert a Python object into a function call parameter.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
c_voidp = class c_void_p(_ctypes._SimpleCData)
| Method resolution order:
| c_void_p
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Class methods defined here:
|
| from_param(...)
| Convert a Python object into a function call parameter.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_wchar(_ctypes._SimpleCData)
| Method resolution order:
| c_wchar
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class c_wchar_p(_ctypes._SimpleCData)
| Method resolution order:
| c_wchar_p
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Methods defined here:
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_param(...)
| Convert a Python object into a function call parameter.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
class py_object(_ctypes._SimpleCData)
| Method resolution order:
| py_object
| _ctypes._SimpleCData
| _ctypes._CData
| builtins.object
|
| Methods defined here:
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._SimpleCData:
|
| __bool__(self, /)
| True if self else False
|
| __buffer__(self, flags, /)
| Return a buffer object that exposes the underlying memory of the object.
|
| __ctypes_from_outparam__(...)
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from _ctypes._SimpleCData:
|
| __new__(*args, **kwargs) class method of _ctypes._SimpleCData
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ctypes._SimpleCData:
|
| value
| current value
|
| ----------------------------------------------------------------------
| Methods inherited from _ctypes._CData:
|
| __hash__(self, /)
| Return hash(self).
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
FUNCTIONS
ARRAY(typ, len)
# XXX Deprecated
CFUNCTYPE(restype, *argtypes, **kw)
CFUNCTYPE(restype, *argtypes,
use_errno=False, use_last_error=False) -> function prototype.
restype: the result type
argtypes: a sequence specifying the argument types
The function prototype can be called in different ways to create a
callable object:
prototype(integer address) -> foreign function
prototype(callable) -> create and return a C callable function from callable
prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method
prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal
prototype((function name, dll object)[, paramflags]) -> foreign function exported by name
DllCanUnloadNow()
DllGetClassObject(rclsid, riid, ppv)
FormatError(...)
FormatError([integer]) -> string
Convert a win32 error code into a string. If the error code is not
given, the return value of a call to GetLastError() is used.
POINTER(...)
PYFUNCTYPE(restype, *argtypes)
SetPointerType(pointer, cls)
# XXX Deprecated
WINFUNCTYPE(restype, *argtypes, **kw)
WinError(code=None, descr=None)
addressof(...)
addressof(C instance) -> integer
Return the address of the C instance internal buffer
alignment(...)
alignment(C type) -> integer
alignment(C instance) -> integer
Return the alignment requirements of a C instance
byref(...)
byref(C instance[, offset=0]) -> byref-object
Return a pointer lookalike to a C instance, only usable
as function argument
c_buffer = create_string_buffer(init, size=None)
create_string_buffer(aBytes) -> character array
create_string_buffer(anInteger) -> character array
create_string_buffer(aBytes, anInteger) -> character array
cast(obj, typ)
create_string_buffer(init, size=None)
create_string_buffer(aBytes) -> character array
create_string_buffer(anInteger) -> character array
create_string_buffer(aBytes, anInteger) -> character array
create_unicode_buffer(init, size=None)
create_unicode_buffer(aString) -> character array
create_unicode_buffer(anInteger) -> character array
create_unicode_buffer(aString, anInteger) -> character array
get_errno(...)
get_last_error(...)
pointer(...)
resize(...)
Resize the memory buffer of a ctypes instance
set_errno(...)
set_last_error(...)
sizeof(...)
sizeof(C type) -> integer
sizeof(C instance) -> integer
Return the size in bytes of a C instance
string_at(ptr, size=-1)
string_at(ptr[, size]) -> string
Return the byte string at void *ptr.
wstring_at(ptr, size=-1)
wstring_at(ptr[, size]) -> string
Return the wide-character string at void *ptr.
DATA
DEFAULT_MODE = 0
GetLastError = <_FuncPtr object>
RTLD_GLOBAL = 0
RTLD_LOCAL = 0
SIZEOF_TIME_T = 8
cdll = <ctypes.LibraryLoader object>
memmove = <CFunctionType object>
memset = <CFunctionType object>
oledll = <ctypes.LibraryLoader object>
pydll = <ctypes.LibraryLoader object>
pythonapi = <PyDLL 'python dll', handle 7ffd90be0000>
windll = <ctypes.LibraryLoader object>
VERSION
1.1.0
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\ctypes\__init__.py
torch.cuda
Python Library Documentation: package torch.cuda in torch
NAME
torch.cuda - This package adds support for CUDA tensor types.
DESCRIPTION
It implements the same function as CPU tensors, but they utilize
GPUs for computation.
It is lazily initialized, so you can always import it, and use
:func:`is_available()` to determine if your system supports CUDA.
:ref:`cuda-semantics` has more details about working with CUDA.
PACKAGE CONTENTS
_annotate_cuda_graph_trace
_device_limits
_gpu_trace
_graph_annotations
_memory_viz
_pin_memory_utils
_sanitizer
_utils
amp (package)
comm
gds
graphs
green_contexts
jiterator
memory
nccl
nvtx
profiler
random
sparse
streams
tunable
CLASSES
builtins.Exception(builtins.BaseException)
DeferredCudaCallError
builtins.RuntimeError(builtins.Exception)
CudaError
builtins.object
BFloat16Tensor
BoolTensor
ByteTensor
CharTensor
DoubleTensor
FloatTensor
HalfTensor
IntTensor
LongTensor
ShortTensor
StreamContext
cudaStatus
device
device_of
torch.cuda.graphs.graph
torch.cuda.green_contexts.GreenContext
torch._utils._CUDAGraph(builtins.object)
torch.cuda.graphs.CUDAGraph
torch._utils._CudaEventBase(builtins.object)
torch.cuda.streams.Event
torch._utils._CudaStreamBase(builtins.object)
torch.cuda.streams.Stream
torch.cuda.streams.ExternalStream
torch._utils._MemPool(builtins.object)
torch.cuda.memory.MemPool
_CudaLegacyStorage(torch.storage._LegacyStorage)
BFloat16Storage
BoolStorage
ByteStorage
CharStorage
ComplexDoubleStorage
ComplexFloatStorage
DoubleStorage
FloatStorage
HalfStorage
IntStorage
LongStorage
ShortStorage
torch.cuda.memory._CUDAAllocator(builtins.object)
torch.cuda.memory.CUDAPluggableAllocator
class BFloat16Storage(_CudaLegacyStorage)
| BFloat16Storage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| BFloat16Storage
| _CudaLegacyStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.bfloat16
|
| ----------------------------------------------------------------------
| Class methods inherited from _CudaLegacyStorage:
|
| from_buffer(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class BFloat16Tensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.bfloat16
|
| is_cuda = True
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class BoolStorage(_CudaLegacyStorage)
| BoolStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| BoolStorage
| _CudaLegacyStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.bool
|
| ----------------------------------------------------------------------
| Class methods inherited from _CudaLegacyStorage:
|
| from_buffer(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class BoolTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.bool
|
| is_cuda = True
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class ByteStorage(_CudaLegacyStorage)
| ByteStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| ByteStorage
| _CudaLegacyStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.uint8
|
| ----------------------------------------------------------------------
| Class methods inherited from _CudaLegacyStorage:
|
| from_buffer(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class ByteTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.uint8
|
| is_cuda = True
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class CUDAGraph(torch._utils._CUDAGraph)
| CUDAGraph(keep_graph: 'bool' = False) -> 'Self'
|
| Wrapper around a CUDA graph.
|
| Arguments:
| keep_graph (bool, optional): If ``keep_graph=False``, the
| cudaGraphExec_t will be instantiated on GPU at the end of
| ``capture_end`` and the underlying cudaGraph_t will be
| destroyed. Users who want to query or otherwise modify the
| underlying cudaGraph_t before instantiation can set
| ``keep_graph=True`` and access it via ``raw_cuda_graph`` after
| ``capture_end``. Note that the cudaGraphExec_t will not be
| instantiated at the end of ``capture_end`` in this
| case. Instead, it will be instantiated via an explicit called
| to ``instantiate`` or automatically on the first call to
| ``replay`` if ``instantiate`` was not already called. Calling
| ``instantiate`` manually before ``replay`` is recommended to
| prevent increased latency on the first call to ``replay``. It
| is allowed to modify the raw cudaGraph_t after first calling
| ``instantiate``, but the user must call ``instantiate`` again
| manually to make sure the instantiated graph has these
| changes. Pytorch has no means of tracking these changes.
|
| .. warning::
| This API is in beta and may change in future releases.
|
| Method resolution order:
| CUDAGraph
| torch._utils._CUDAGraph
| builtins.object
|
| Methods defined here:
|
| __del__(self) -> 'None'
|
| capture_begin(self, pool: '_POOL_HANDLE | None' = None, capture_error_mode: 'str' = 'global', check_input_liveness: 'bool' = False) -> 'None'
| Begin capturing CUDA work on the current stream.
|
| Typically, you shouldn't call ``capture_begin`` yourself.
| Use :class:`~torch.cuda.graph` or :func:`~torch.cuda.make_graphed_callables`,
| which call ``capture_begin`` internally.
|
| Arguments:
| pool (optional): Token (returned by :func:`~torch.cuda.graph_pool_handle` or
| :meth:`other_Graph_instance.pool()<torch.cuda.CUDAGraph.pool>`) that hints this graph may share memory
| with the indicated pool. See :ref:`Graph memory management<graph-memory-management>`.
| capture_error_mode (str, optional): specifies the cudaStreamCaptureMode for the graph capture stream.
| Can be "global", "thread_local" or "relaxed". During cuda graph capture, some actions, such as cudaMalloc,
| may be unsafe. "global" will error on actions in other threads, "thread_local" will only error for
| actions in the current thread, and "relaxed" will not error on these actions. Do NOT change this setting
| unless you're familiar with `cudaStreamCaptureMode <https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html#group__CUDART__STREAM_1g9d0535d93a214cbf126835257b16ba85>`_
| check_input_liveness (bool, optional):
| If ``True``, tracks external tensor inputs during graph capture and
| raises an error if any are deallocated before replay. This helps debug "use after free" errors
| where input tensors are garbage collected between capture and replay. Default: ``False``.
|
| .. note::
| Custom CUDA kernels added outside PyTorch (e.g., via cuLaunchKernel or DLPack) are not
| tracked by this mechanism.
|
| capture_end(self) -> 'None'
| End CUDA graph capture on the current stream.
|
| After ``capture_end``, ``replay`` may be called on this instance.
|
| Typically, you shouldn't call ``capture_end`` yourself.
| Use :class:`~torch.cuda.graph` or :func:`~torch.cuda.make_graphed_callables`,
| which call ``capture_end`` internally.
|
| debug_dump(self, debug_path: 'str') -> 'None'
| Arguments:
| debug_path (required): Path to dump the graph to.
|
| Calls a debugging function to dump the graph if the debugging is
| enabled via CUDAGraph.enable_debug_mode()
|
| enable_debug_mode(self) -> 'None'
| Enable debugging mode for CUDAGraph.debug_dump.
|
| get_graph_data(self) -> 'dict'
| Return a dictionary describing the graph's topology and node metadata.
|
| ``keep_graph`` must be True. The graph must have been instantiated
| (via :meth:`instantiate`) before calling this method.
| Requires the ``cuda.bindings`` package.
|
| Returns a dictionary with structure::
|
| {
| "exec_graph_id": int,
| "nodes": [
| {
| "index": int,
| "node_type": str,
| "tools_id": int,
| "graph_id": int,
| "node_id": int,
| "kernel_name": str or None,
| "dependencies": [int, ...],
| "dependents": [int, ...],
| },
| ...,
| ],
| }
|
| Each node's ``graph_id`` is remapped to the exec graph id so that
| ``tools_id`` values match those reported by CUPTI-based profilers.
| ``dependencies`` and ``dependents`` are lists of node indices within
| the ``nodes`` list.
|
| This structure is useful for inspecting a profiler trace and
| establishing whether a particular dependency observed in the profile
| is a true dependency (encoded in the graph) or a fake dependency
| caused by mapping of independent streams to the same hardware
| channel.
|
| instantiate(self) -> 'None'
| Instantiate the CUDA graph. Will be called by
| ``capture_end`` if ``keep_graph=False``, or by ``replay`` if
| ``keep_graph=True`` and ``instantiate`` has not already been
| explicitly called. Does not destroy the cudaGraph_t returned
| by ``raw_cuda_graph``.
|
| pool(self) -> '_POOL_HANDLE'
| Return an opaque token representing the id of this graph's memory pool.
|
| This id can optionally be passed to another graph's ``capture_begin``,
| which hints the other graph may share the same memory pool.
|
| raw_cuda_graph(self) -> 'int'
| Returns the underlying cudaGraph_t. ``keep_graph`` must be True.
|
| See the following for APIs for how to manipulate this object: `Graph Management <https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__GRAPH.html>`_ and `cuda-python Graph Management bindings <https://nvidia.github.io/cuda-python/cuda-bindings/latest/module/runtime.html#graph-management>`_
|
| raw_cuda_graph_exec(self) -> 'int'
| Returns the underlying cudaGraphExec_t. ``instantiate`` must have been called if ``keep_graph`` is True, or ``capture_end`` must have been called if ``keep_graph`` is False. If you call ``instantiate()`` after ``raw_cuda_graph_exec()``, the previously returned cudaGraphExec_t will be destroyed. It is your responsibility not to use this object after destruction.
|
| See the following for APIs for how to manipulate this object: `Graph Execution <https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__GRAPH__EXEC.html>`_ and `cuda-python Graph Execution bindings <https://nvidia.github.io/cuda-python/cuda-bindings/latest/module/runtime.html#graph-execution>`_
|
| replay(self) -> 'None'
| Replay the CUDA work captured by this graph.
|
| reset(self) -> 'None'
| Delete the graph currently held by this instance.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, keep_graph: 'bool' = False) -> 'Self'
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'_tracker': '_CUDAGraphInputLivenessTracker | None'...
|
| ----------------------------------------------------------------------
| Methods inherited from torch._utils._CUDAGraph:
|
| __init__ = err_fn(obj, *args, **kwargs) from torch._utils._dummy_type.<locals>.get_err_fn.<locals>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._utils._CUDAGraph:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class CUDAPluggableAllocator(_CUDAAllocator)
| CUDAPluggableAllocator(path_to_so_file: str, alloc_fn_name: str, free_fn_name: str)
|
| CUDA memory allocator loaded from a so file.
|
| Method resolution order:
| CUDAPluggableAllocator
| _CUDAAllocator
| builtins.object
|
| Methods defined here:
|
| __init__(self, path_to_so_file: str, alloc_fn_name: str, free_fn_name: str)
| Memory allocators are compiled in .so files and loaded dynamically using ctypes.
|
| To change the active allocator use the :func:`torch.memory.cuda.change_current_allocator` function.
|
| Args:
| path_to_so_file(str): Path in the filesystem to the `.so` file containing
| the allocator functions
| alloc_fn_name(str): Name of the function to perform the memory allocation
| in the so file. The signature must be:
| void* alloc_fn_name(ssize_t size, int device, cudaStream_t stream);
| free_fn_name(str): Name of the function to perform the memory release
| in the so file. The signature must be:
| void free_fn_name(void* ptr, size_t size, cudaStream_t stream);
|
| .. warning::
| This is currently supported only in unix OSs
|
| .. note::
| See :ref:`cuda-memory-management` for details on creating and using a custom allocator
|
| ----------------------------------------------------------------------
| Methods inherited from _CUDAAllocator:
|
| allocator(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _CUDAAllocator:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class CharStorage(_CudaLegacyStorage)
| CharStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| CharStorage
| _CudaLegacyStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.int8
|
| ----------------------------------------------------------------------
| Class methods inherited from _CudaLegacyStorage:
|
| from_buffer(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class CharTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.int8
|
| is_cuda = True
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class ComplexDoubleStorage(_CudaLegacyStorage)
| ComplexDoubleStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| ComplexDoubleStorage
| _CudaLegacyStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.complex128
|
| ----------------------------------------------------------------------
| Class methods inherited from _CudaLegacyStorage:
|
| from_buffer(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class ComplexFloatStorage(_CudaLegacyStorage)
| ComplexFloatStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| ComplexFloatStorage
| _CudaLegacyStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.complex64
|
| ----------------------------------------------------------------------
| Class methods inherited from _CudaLegacyStorage:
|
| from_buffer(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class CudaError(builtins.RuntimeError)
| CudaError(code: int) -> None
|
| Method resolution order:
| CudaError
| builtins.RuntimeError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, code: int) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.RuntimeError:
|
| __new__(*args, **kwargs) class method of builtins.RuntimeError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class DeferredCudaCallError(builtins.Exception)
| Method resolution order:
| DeferredCudaCallError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class DoubleStorage(_CudaLegacyStorage)
| DoubleStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| DoubleStorage
| _CudaLegacyStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.float64
|
| ----------------------------------------------------------------------
| Class methods inherited from _CudaLegacyStorage:
|
| from_buffer(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class DoubleTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.float64
|
| is_cuda = True
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class Event(torch._utils._CudaEventBase)
| Event(enable_timing=False, blocking=False, interprocess=False, external=False)
|
| Wrapper around a CUDA event.
|
| CUDA events are synchronization markers that can be used to monitor the
| device's progress, to accurately measure timing, and to synchronize CUDA
| streams.
|
| The underlying CUDA events are lazily initialized when the event is first
| recorded or exported to another process. After creation, only streams on the
| same device may record the event. However, streams on any device can wait on
| the event.
|
| Args:
| enable_timing (bool, optional): indicates if the event should measure time
| (default: ``False``)
| blocking (bool, optional): if ``True``, :meth:`wait` will be blocking (default: ``False``)
| interprocess (bool): if ``True``, the event can be shared between processes
| (default: ``False``)
| external (bool, optional): indicates whether this event should create event record and event wait nodes, or create an internal cross-stream dependency, when captured in a cuda graph. See `cross-stream dependencies <https://docs.nvidia.com/cuda/archive/12.9.0/cuda-c-programming-guide/index.html#cross-stream-dependencies-and-events>`_, `cudaEventRecordExternal <https://docs.nvidia.com/cuda/archive/12.9.0/cuda-runtime-api/group__CUDART__TYPES.html#group__CUDART__TYPES_1g3457b81d1d32c6a00f6132fbc2693d47>`_, and `cudaEventWaitExternal <https://docs.nvidia.com/cuda/archive/12.9.0/cuda-runtime-api/group__CUDART__TYPES.html#group__CUDART__TYPES_1g0c23426b7252eaa9cef695859991304e>`_ for more information about internal vs. external events. (default: ``False``)
|
| .. _CUDA Event Documentation:
| https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__EVENT.html
|
| Method resolution order:
| Event
| torch._utils._CudaEventBase
| builtins.object
|
| Methods defined here:
|
| __repr__(self) -> 'str'
| Return repr(self).
|
| elapsed_time(self, end_event: 'Event')
| Return the time elapsed.
|
| Time reported in milliseconds after the event was recorded and
| before the end_event was recorded.
|
| Args:
| end_event (Event): the end event.
|
| ipc_handle(self)
| Return an IPC handle of this event.
|
| If not recorded yet, the event will use the current device.
|
| query(self)
| Check if all work currently captured by event has completed.
|
| Returns:
| A boolean indicating if all work currently captured by event has
| completed.
|
| record(self, stream: 'Stream | torch.Stream | None' = None)
| Record the event in a given stream.
|
| Args:
| stream (Stream, torch.Stream, optional): Uses ``torch.cuda.current_stream()`` if no stream is specified.
| The stream's device must match the event's device.
|
| synchronize(self) -> 'None'
| Wait for the event to complete.
|
| Waits until the completion of all work currently captured in this event.
| This prevents the CPU thread from proceeding until the event completes.
|
| .. note:: This is a wrapper around ``cudaEventSynchronize()``: see
| `CUDA Event documentation`_ for more info.
|
| wait(self, stream: 'Stream | torch.Stream | None' = None) -> 'None'
| Make all future work submitted to the given stream wait for this event.
|
| Args:
| stream (Stream, torch.Stream, optional): Uses ``torch.cuda.current_stream()`` if no stream is specified.
|
| .. note:: This is a wrapper around ``cudaStreamWaitEvent()``: see
| `CUDA Event documentation`_ for more info.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_ipc_handle(device, handle)
| Reconstruct an event from an IPC handle on the given device.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, enable_timing=False, blocking=False, interprocess=False, external=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from torch._utils._CudaEventBase:
|
| __init__ = err_fn(obj, *args, **kwargs) from torch._utils._dummy_type.<locals>.get_err_fn.<locals>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._utils._CudaEventBase:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class ExternalStream(Stream)
| ExternalStream(stream_ptr, device=None, **kwargs)
|
| Wrapper around an externally allocated CUDA stream.
|
| This class is used to wrap streams allocated in other libraries in order
| to facilitate data exchange and multi-library interactions.
|
| .. note:: This class doesn't manage the stream life-cycle, it is the user
| responsibility to keep the referenced stream alive while this class is
| being used.
|
| Args:
| stream_ptr(int): Integer representation of the `cudaStream_t` value.
| allocated externally.
| device(torch.device or int, optional): the device where the stream
| was originally allocated. If device is specified incorrectly,
| subsequent launches using this stream may fail.
|
| Method resolution order:
| ExternalStream
| Stream
| torch._utils._CudaStreamBase
| builtins.object
|
| Static methods defined here:
|
| __new__(cls, stream_ptr, device=None, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from Stream:
|
| __cuda_stream__(self)
| Implements the CUDA Stream Protocol:
| https://nvidia.github.io/cuda-python/cuda-core/latest/interoperability.html#cuda-stream-protocol
|
| Returns:
| tuple: A 2-tuple of (version, handle) where version is the protocol version
| and handle is the address of cudaStream_t (CUDA) or hipStream_t (ROCm) as a Python int.
|
| __eq__(self, o) -> 'bool'
| Return self==value.
|
| __hash__(self)
| Return hash(self).
|
| __repr__(self)
| Return repr(self).
|
| query(self) -> 'bool'
| Check if all the work submitted has been completed.
|
| Returns:
| A boolean indicating if all kernels in this stream are completed.
|
| record_event(self, event: 'Event | torch.Event | None' = None)
| Record an event.
|
| Args:
| event (Event, torch.Event, optional): event to record. If not given, a new one
| will be allocated.
|
| Returns:
| Recorded event.
|
| synchronize(self) -> 'None'
| Wait for all the kernels in this stream to complete.
|
| .. note:: This is a wrapper around ``cudaStreamSynchronize()``: see
| `CUDA Stream documentation`_ for more info.
|
| wait_event(self, event: 'Event | torch.Event') -> 'None'
| Make all future work submitted to the stream wait for an event.
|
| Args:
| event (Event, torch.Event): an event to wait for.
|
| .. note:: This is a wrapper around ``cudaStreamWaitEvent()``: see
| `CUDA Stream documentation`_ for more info.
|
| This function returns without waiting for :attr:`event`: only future
| operations are affected.
|
| .. _CUDA Stream documentation:
| https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html
|
| wait_stream(self, stream: 'Stream | torch.Stream') -> 'None'
| Synchronize with another stream.
|
| All future work submitted to this stream will wait until all kernels
| submitted to a given stream at the time of call complete.
|
| Args:
| stream (Stream, torch.Stream): a stream to synchronize.
|
| .. note:: This function returns without waiting for currently enqueued
| kernels in :attr:`stream`: only future operations are affected.
|
| ----------------------------------------------------------------------
| Methods inherited from torch._utils._CudaStreamBase:
|
| __init__ = err_fn(obj, *args, **kwargs) from torch._utils._dummy_type.<locals>.get_err_fn.<locals>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._utils._CudaStreamBase:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class FloatStorage(_CudaLegacyStorage)
| FloatStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| FloatStorage
| _CudaLegacyStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.float32
|
| ----------------------------------------------------------------------
| Class methods inherited from _CudaLegacyStorage:
|
| from_buffer(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class FloatTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.float32
|
| is_cuda = True
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class GreenContext(builtins.object)
| Wrapper around a CUDA green context.
|
| .. warning::
| This API is in beta and may change in future releases.
|
| Methods defined here:
|
| Stream(self) -> 'torch.cuda.Stream'
| Return the CUDA Stream used by the green context.
|
| pop_context(self) -> None
| Assuming the green context is the current context, pop it from the
| context stack and restore the previous context.
|
| set_context(self) -> None
| Make the green context the current context.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| create(*, num_sms: int | None = None, workqueue_scope: str | None = None, workqueue_concurrency_limit: int | None = None, device_id: int | None = None) -> object
| Create a CUDA green context.
|
| At least one of ``num_sms`` or ``workqueue_scope`` must be specified.
| Both can be combined to partition SMs and configure workqueues in the
| same green context.
|
| Arguments:
| num_sms (int, optional): The number of SMs to use in the green
| context. When ``None``, SMs are not partitioned.
| workqueue_scope (str, optional): Workqueue sharing scope. One of
| ``"device_ctx"`` (shared across all contexts, default driver
| behaviour) or ``"balanced"`` (non-overlapping workqueues with
| other balanced green contexts). When ``None``, no workqueue
| configuration is applied.
| workqueue_concurrency_limit (int, optional): Maximum number of
| concurrent stream-ordered workloads for the workqueue. Requires
| ``workqueue_scope`` to be set.
| device_id (int, optional): The device index of green context.
| When ``None``, the current device is used.
|
| max_workqueue_concurrency(device_id: int | None = None) -> int
| Return the maximum workqueue concurrency limit for the device.
|
| This queries the device for the default number of concurrent
| stream-ordered workloads supported by workqueue configuration
| resources.
|
| Arguments:
| device_id (int, optional): The device index to query. When
| ``None``, the current device is used.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class HalfStorage(_CudaLegacyStorage)
| HalfStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| HalfStorage
| _CudaLegacyStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.float16
|
| ----------------------------------------------------------------------
| Class methods inherited from _CudaLegacyStorage:
|
| from_buffer(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class HalfTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.float16
|
| is_cuda = True
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class IntStorage(_CudaLegacyStorage)
| IntStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| IntStorage
| _CudaLegacyStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.int32
|
| ----------------------------------------------------------------------
| Class methods inherited from _CudaLegacyStorage:
|
| from_buffer(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class IntTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.int32
|
| is_cuda = True
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class LongStorage(_CudaLegacyStorage)
| LongStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| LongStorage
| _CudaLegacyStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.int64
|
| ----------------------------------------------------------------------
| Class methods inherited from _CudaLegacyStorage:
|
| from_buffer(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class LongTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.int64
|
| is_cuda = True
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class MemPool(torch._utils._MemPool)
| MemPool(allocator: torch._utils._cuda_CUDAAllocator | None = None, use_on_oom: bool = False, no_split: bool = False)
|
| MemPool represents a pool of memory in a caching allocator. Currently,
| it's just the ID of the pool object maintained in the CUDACachingAllocator.
|
| Args:
| allocator(torch._C._cuda_CUDAAllocator, optional): a
| torch._C._cuda_CUDAAllocator object that can be used to
| define how memory gets allocated in the pool. If :attr:`allocator`
| is ``None`` (default), memory allocation follows the default/
| current configuration of the CUDACachingAllocator.
| use_on_oom(bool): a bool that indicates if this pool can be used
| as a last resort if a memory allocation outside of the pool fails due
| to Out Of Memory. This is False by default.
| no_split(bool): a bool that indicates if this pool should not split a segment.
| This is False by default.
|
| Method resolution order:
| MemPool
| torch._utils._MemPool
| builtins.object
|
| Methods defined here:
|
| __init__(self, allocator: torch._utils._cuda_CUDAAllocator | None = None, use_on_oom: bool = False, no_split: bool = False)
| Initialize self. See help(type(self)) for accurate signature.
|
| snapshot(self, include_traces=True)
| Return a snapshot of the CUDA memory allocator pool state across all
| devices.
|
| Interpreting the output of this function requires familiarity with the
| memory allocator internals.
|
| Args:
| include_traces: Whether to include trace entries in the snapshot.
| If True (default), all trace entries are included.
| If False, no trace entries are included (lightweight/fast snapshot).
|
| .. note::
| See :ref:`cuda-memory-management` for more details about GPU memory
| management.
|
| use_count(self) -> int
| Returns the reference count of this pool.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| id
| Returns the ID of this pool as a tuple of two ints.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch._utils._MemPool:
|
| __new__ = err_fn(obj, *args, **kwargs) from torch._utils._dummy_type.<locals>.get_err_fn.<locals>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._utils._MemPool:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class ShortStorage(_CudaLegacyStorage)
| ShortStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| ShortStorage
| _CudaLegacyStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.int16
|
| ----------------------------------------------------------------------
| Class methods inherited from _CudaLegacyStorage:
|
| from_buffer(*args, **kwargs)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class ShortTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.int16
|
| is_cuda = True
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class Stream(torch._utils._CudaStreamBase)
| Stream(device=None, priority=0, **kwargs)
|
| Wrapper around a CUDA stream.
|
| A CUDA stream is a linear sequence of execution that belongs to a specific
| device, independent from other streams. It supports with statement as a
| context manager to ensure the operators within the with block are running
| on the corresponding stream. See :ref:`cuda-semantics` for details.
|
| Args:
| device(torch.device or int, optional): a device on which to allocate
| the stream. If :attr:`device` is ``None`` (default) or a negative
| integer, this will use the current device.
| priority(int, optional): priority of the stream, which can be positive, 0, or negative.
| A lower number indicates a higher priority. By default, the priority is set to 0.
| If the value falls outside of the allowed priority range, it will automatically be
| mapped to the nearest valid priority (lowest for large positive numbers or
| highest for large negative numbers).
|
| Method resolution order:
| Stream
| torch._utils._CudaStreamBase
| builtins.object
|
| Methods defined here:
|
| __cuda_stream__(self)
| Implements the CUDA Stream Protocol:
| https://nvidia.github.io/cuda-python/cuda-core/latest/interoperability.html#cuda-stream-protocol
|
| Returns:
| tuple: A 2-tuple of (version, handle) where version is the protocol version
| and handle is the address of cudaStream_t (CUDA) or hipStream_t (ROCm) as a Python int.
|
| __eq__(self, o) -> 'bool'
| Return self==value.
|
| __hash__(self)
| Return hash(self).
|
| __repr__(self)
| Return repr(self).
|
| query(self) -> 'bool'
| Check if all the work submitted has been completed.
|
| Returns:
| A boolean indicating if all kernels in this stream are completed.
|
| record_event(self, event: 'Event | torch.Event | None' = None)
| Record an event.
|
| Args:
| event (Event, torch.Event, optional): event to record. If not given, a new one
| will be allocated.
|
| Returns:
| Recorded event.
|
| synchronize(self) -> 'None'
| Wait for all the kernels in this stream to complete.
|
| .. note:: This is a wrapper around ``cudaStreamSynchronize()``: see
| `CUDA Stream documentation`_ for more info.
|
| wait_event(self, event: 'Event | torch.Event') -> 'None'
| Make all future work submitted to the stream wait for an event.
|
| Args:
| event (Event, torch.Event): an event to wait for.
|
| .. note:: This is a wrapper around ``cudaStreamWaitEvent()``: see
| `CUDA Stream documentation`_ for more info.
|
| This function returns without waiting for :attr:`event`: only future
| operations are affected.
|
| .. _CUDA Stream documentation:
| https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html
|
| wait_stream(self, stream: 'Stream | torch.Stream') -> 'None'
| Synchronize with another stream.
|
| All future work submitted to this stream will wait until all kernels
| submitted to a given stream at the time of call complete.
|
| Args:
| stream (Stream, torch.Stream): a stream to synchronize.
|
| .. note:: This function returns without waiting for currently enqueued
| kernels in :attr:`stream`: only future operations are affected.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, device=None, priority=0, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from torch._utils._CudaStreamBase:
|
| __init__ = err_fn(obj, *args, **kwargs) from torch._utils._dummy_type.<locals>.get_err_fn.<locals>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._utils._CudaStreamBase:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class StreamContext(builtins.object)
| StreamContext(stream: Optional[ForwardRef('torch.cuda.Stream')])
|
| Context-manager that selects a given stream.
|
| All CUDA kernels queued within its context will be enqueued on a selected
| stream.
|
| Args:
| Stream (Stream): selected stream. This manager is a no-op if it's
| ``None``.
| .. note:: Streams are per-device.
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, type: Any, value: Any, traceback: Any)
|
| __init__(self, stream: Optional[ForwardRef('torch.cuda.Stream')])
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'cur_stream': typing.Optional[ForwardRef('torch.cud...
class cudaStatus(builtins.object)
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ERROR_NOT_READY = 34
|
| SUCCESS = 0
|
| __annotations__ = {'ERROR_NOT_READY': <class 'int'>, 'SUCCESS': <class...
class device(builtins.object)
| device(device: Any)
|
| Context-manager that changes the selected device.
|
| Args:
| device (torch.device or int): device index to select. It's a no-op if
| this argument is a negative integer or ``None``.
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, type: Any, value: Any, traceback: Any)
|
| __init__(self, device: Any)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class device_of(device)
| device_of(obj)
|
| Context-manager that changes the current device to that of given object.
|
| You can use both tensors and storages as arguments. If a given object is
| not allocated on a GPU, this is a no-op.
|
| Args:
| obj (Tensor or Storage): object allocated on the selected device.
|
| Method resolution order:
| device_of
| device
| builtins.object
|
| Methods defined here:
|
| __init__(self, obj)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from device:
|
| __enter__(self)
|
| __exit__(self, type: Any, value: Any, traceback: Any)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from device:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class graph(builtins.object)
| graph(cuda_graph: 'CUDAGraph', pool: '_POOL_HANDLE | None' = None, stream: 'torch.cuda.Stream | None' = None, capture_error_mode: 'str' = 'global', enable_annotations: 'bool' = False, check_input_liveness: 'bool' = False)
|
| Context-manager that captures CUDA work into a :class:`torch.cuda.CUDAGraph` object for later replay.
|
| See :ref:`CUDA Graphs <cuda-graph-semantics>` for a general introduction,
| detailed use, and constraints.
|
| Arguments:
| cuda_graph (torch.cuda.CUDAGraph): Graph object used for capture.
| pool (optional): Opaque token (returned by a call to :func:`~torch.cuda.graph_pool_handle()` or
| :meth:`other_Graph_instance.pool()<torch.cuda.CUDAGraph.pool>`) hinting this graph's capture
| may share memory from the specified pool. See :ref:`Graph memory management<graph-memory-management>`.
| stream (torch.cuda.Stream, optional): If supplied, will be set as the current stream in the context.
| If not supplied, ``graph`` sets its own internal side stream as the current stream in the context.
| capture_error_mode (str, optional): specifies the cudaStreamCaptureMode for the graph capture stream.
| Can be "global", "thread_local" or "relaxed". During cuda graph capture, some actions, such as cudaMalloc,
| may be unsafe. "global" will error on actions in other threads, "thread_local" will only error for
| actions in the current thread, and "relaxed" will not error on actions. Do NOT change this setting
| unless you're familiar with `cudaStreamCaptureMode <https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html#group__CUDART__STREAM_1g9d0535d93a214cbf126835257b16ba85>`_
| enable_annotations (bool, optional): If ``True``, enables kernel annotation
| recording on entry and automatically calls
| :func:`~torch.cuda._graph_annotations.resolve_pending_annotations` before
| the capture ends. Annotations are **not** cleared on exit so that multiple
| graphs in the same workload can accumulate annotations.
| Requires ``cuda.bindings`` package and cuda-compat >= 13.1 or CUDA driver >= 13.1.
| check_input_liveness (bool, optional): If ``True``, tracks external tensor inputs during graph capture and
| raises an error if any are deallocated before replay. This helps debug "use after free" errors
| where input tensors are garbage collected between capture and replay. Default: ``False``.
|
| .. note::
| Custom CUDA kernels added outside PyTorch (e.g., via cuLaunchKernel or DLPack) are not
| tracked by this mechanism.
|
| .. note::
| For effective memory sharing, if you pass a ``pool`` used by a previous capture and the previous capture
| used an explicit ``stream`` argument, you should pass the same ``stream`` argument to this capture.
|
| .. warning::
| This API is in beta and may change in future releases.
|
| .. _cudaStreamCaptureMode:
| https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html#group__CUDART__STREAM_1g9d0535d93a214cbf126835257b16ba85
|
| Methods defined here:
|
| __enter__(self) -> 'None'
|
| __exit__(self, *args: 'object') -> 'None'
|
| __init__(self, cuda_graph: 'CUDAGraph', pool: '_POOL_HANDLE | None' = None, stream: 'torch.cuda.Stream | None' = None, capture_error_mode: 'str' = 'global', enable_annotations: 'bool' = False, check_input_liveness: 'bool' = False)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'default_capture_stream': 'torch.cuda.Stream | None...
|
| default_capture_stream = None
FUNCTIONS
caching_allocator_alloc(size, device: 'Device' = None, stream=None)
Perform a memory allocation using the CUDA memory allocator.
Memory is allocated for a given device and a stream, this
function is intended to be used for interoperability with other
frameworks. Allocated memory is released through
:func:`~torch.cuda.caching_allocator_delete`.
Args:
size (int): number of bytes to be allocated.
device (torch.device or int, optional): selected device. If it is
``None`` the default CUDA device is used.
stream (torch.cuda.Stream or int, optional): selected stream. If is ``None`` then
the default stream for the selected device is used.
.. note::
See :ref:`cuda-memory-management` for more details about GPU memory
management.
caching_allocator_delete(mem_ptr)
Delete memory allocated using the CUDA memory allocator.
Memory allocated with :func:`~torch.cuda.caching_allocator_alloc`.
is freed here. The associated device and stream are tracked inside
the allocator.
Args:
mem_ptr (int): memory address to be freed by the allocator.
.. note::
See :ref:`cuda-memory-management` for more details about GPU memory
management.
caching_allocator_disabled()
Context manager that temporarily disables the CUDA caching allocator.
caching_allocator_enable(value: bool = True) -> None
Enable or disable the CUDA memory allocator. On by default.
can_device_access_peer(device: torch.device | str | int | None, peer_device: torch.device | str | int | None) -> bool
Check if peer access between two devices is possible.
change_current_allocator(allocator: torch.cuda.memory._CUDAAllocator) -> None
Change the currently used memory allocator to be the one provided.
If the current allocator has already been used/initialized, this function will error.
Args:
allocator (torch.cuda.memory._CUDAAllocator): allocator to be set as the active one.
.. note::
See :ref:`cuda-memory-management` for details on creating and using a custom allocator
check_error(res: int) -> None
Raise an error if the result of a CUDA runtime API call is not success.
clock_rate(device: torch.device | str | int | None = None) -> int
Return the clock speed of the GPU SM in MHz (megahertz) over the past sample period as given by `nvidia-smi`.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
Warning: Each sample period may be between 1 second and 1/6 second,
depending on the product being queried.
cudart()
Retrieves the CUDA runtime API module.
This function initializes the CUDA runtime environment if it is not already
initialized and returns the CUDA runtime API module (_cudart). The CUDA
runtime API module provides access to various CUDA runtime functions.
Args:
``None``
Returns:
module: The CUDA runtime API module (_cudart).
Raises:
RuntimeError: If CUDA cannot be re-initialized in a forked subprocess.
AssertionError: If PyTorch is not compiled with CUDA support or if libcudart functions are unavailable.
Example of CUDA operations with profiling:
>>> import torch
>>> from torch.cuda import cudart, check_error
>>> import os
>>>
>>> os.environ["CUDA_PROFILE"] = "1"
>>>
>>> def perform_cuda_operations_with_streams():
>>> stream = torch.cuda.Stream()
>>> with torch.cuda.stream(stream):
>>> x = torch.randn(100, 100, device='cuda')
>>> y = torch.randn(100, 100, device='cuda')
>>> z = torch.mul(x, y)
>>> return z
>>>
>>> torch.cuda.synchronize()
>>> print("====== Start nsys profiling ======")
>>> check_error(cudart().cudaProfilerStart())
>>> with torch.autograd.profiler.emit_nvtx():
>>> result = perform_cuda_operations_with_streams()
>>> print("CUDA operations completed.")
>>> check_error(torch.cuda.cudart().cudaProfilerStop())
>>> print("====== End nsys profiling ======")
To run this example and save the profiling information, execute:
>>> $ nvprof --profile-from-start off --csv --print-summary -o trace_name.prof -f -- python cudart_test.py
This command profiles the CUDA operations in the provided script and saves
the profiling information to a file named `trace_name.prof`.
The `--profile-from-start off` option ensures that profiling starts only
after the `cudaProfilerStart` call in the script.
The `--csv` and `--print-summary` options format the profiling output as a
CSV file and print a summary, respectively.
The `-o` option specifies the output file name, and the `-f` option forces the
overwrite of the output file if it already exists.
current_blas_handle()
Return cublasHandle_t pointer to current cuBLAS handle
current_device() -> int
Return the index of a currently selected device.
current_solver_handle()
Return cusolverDnHandle_t pointer to current cuSOLVER handle
current_stream(device: torch.device | str | int | None = None) -> torch.cuda.streams.Stream
Return the currently selected :class:`Stream` for a given device.
Args:
device (torch.device or int, optional): selected device. Returns
the currently selected :class:`Stream` for the current device, given
by :func:`~torch.cuda.current_device`, if :attr:`device` is ``None``
(default).
default_stream(device: torch.device | str | int | None = None) -> torch.cuda.streams.Stream
Return the default :class:`Stream` for a given device.
Args:
device (torch.device or int, optional): selected device. Returns
the default :class:`Stream` for the current device, given by
:func:`~torch.cuda.current_device`, if :attr:`device` is ``None``
(default).
device_count() -> int
Return the number of GPUs available.
.. note:: This API will NOT poison fork if NVML discovery succeeds.
See :ref:`multiprocessing-poison-fork-note` for more details.
device_memory_used(device: torch.device | str | int | None = None) -> int
Return used global (device) memory in bytes as given by `nvidia-smi` or `amd-smi`.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
empty_cache() -> None
Release all unoccupied cached memory currently held by the caching
allocator so that those can be used in other GPU application and visible in
`nvidia-smi`.
.. note::
:func:`~torch.cuda.empty_cache` doesn't increase the amount of GPU
memory available for PyTorch. However, it may help reduce fragmentation
of GPU memory in certain cases. See :ref:`cuda-memory-management` for
more details about GPU memory management.
get_allocator_backend() -> str
Return a string describing the active allocator backend as set by
``PYTORCH_ALLOC_CONF``. Currently available backends are
``native`` (PyTorch's native caching allocator) and `cudaMallocAsync``
(CUDA's built-in asynchronous allocator).
.. note::
See :ref:`cuda-memory-management` for details on choosing the allocator backend.
get_arch_list() -> list[str]
Return list CUDA architectures this library was compiled for.
get_device_capability(device: torch.device | str | int | None = None) -> tuple[int, int]
Get the cuda capability of a device.
Args:
device (torch.device or int or str, optional): device for which to return the
device capability. This function is a no-op if this argument is
a negative integer. It uses the current device, given by
:func:`~torch.cuda.current_device`, if :attr:`device` is ``None``
(default).
Returns:
tuple(int, int): the major and minor cuda capability of the device
get_device_name(device: torch.device | str | int | None = None) -> str
Get the name of a device.
Args:
device (torch.device or int or str, optional): device for which to return the
name. This function is a no-op if this argument is a negative
integer. It uses the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
Returns:
str: the name of the device
get_device_properties(device: torch.device | str | int | None = None) -> torch._utils._CudaDeviceProperties
Get the properties of a device.
Args:
device (torch.device or int or str, optional): device for which to return the
properties of the device. It uses the current device, given by
:func:`~torch.cuda.current_device`, if :attr:`device` is ``None``
(default).
Returns:
_CudaDeviceProperties: the properties of the device
get_gencode_flags() -> str
Return NVCC gencode flags this library was compiled with.
get_per_process_memory_fraction(device: 'Device' = None) -> float
Get memory fraction for a process.
Args:
device (torch.device or int, optional): selected device. If it is
``None`` the default CUDA device is used.
Returns:
memory fraction, in range 0~1. Allowed memory equals total_memory * fraction.
get_rng_state(device: int | str | torch.device = 'cuda') -> torch.Tensor
Return the random number generator state of the specified GPU as a ByteTensor.
Args:
device (torch.device or int, optional): The device to return the RNG state of.
Default: ``'cuda'`` (i.e., ``torch.device('cuda')``, the current CUDA device).
.. warning::
This function eagerly initializes CUDA.
get_rng_state_all() -> list[torch.Tensor]
Return a list of ByteTensor representing the random number states of all devices.
get_stream_from_external(data_ptr: int, device: torch.device | str | int | None = None) -> torch.cuda.streams.Stream
Return a :class:`Stream` from an externally allocated CUDA stream.
This function is used to wrap streams allocated in other libraries in order
to facilitate data exchange and multi-library interactions.
.. note:: This function doesn't manage the stream life-cycle, it is the user
responsibility to keep the referenced stream alive while this returned
stream is being used.
Args:
data_ptr(int): Integer representation of the `cudaStream_t` value that
is allocated externally.
device(torch.device or int, optional): the device where the stream
was originally allocated. If device is specified incorrectly,
subsequent launches using this stream may fail.
get_sync_debug_mode() -> int
Return current value of debug mode for cuda synchronizing operations.
graph_pool_handle() -> '_POOL_HANDLE'
Return an opaque token representing the id of a graph memory pool.
See :ref:`Graph memory management<graph-memory-management>`.
.. warning::
This API is in beta and may change in future releases.
host_memory_stats() -> dict[str, typing.Any]
Return a dictionary of pinned (host) allocator statistics.
Core statistics (host pinned allocator):
- ``"allocations.{current,peak,allocated,freed}"``:
pinned blocks owned by the allocator (active + cached). Grows when a new
block is created via CUDA and shrinks when cached blocks are returned.
- ``"allocated_bytes.{current,peak,allocated,freed}"``:
bytes of pinned blocks owned by the allocator (active + cached), using
the rounded block size requested from CUDA.
- ``"active_requests.{current,peak,allocated,freed}"``:
blocks currently checked out to callers (increments on handout, decrements
when the block becomes reusable after stream deps finish).
- ``"active_bytes.{current,peak,allocated,freed}"``:
bytes corresponding to active blocks.
Metric type:
- ``current``: current value.
- ``peak``: maximum value.
- ``allocated``: historical total increase.
- ``freed``: historical total decrease.
Event/timing counters:
- ``"num_host_alloc"`` / ``"num_host_free"``: blocks created to grow the
pool / cached blocks returned to CUDA (matches allocations allocated/freed).
- ``"host_alloc_time.{total,max,min,count,avg}"``: time in CUDA alloc calls
when growing the pool (microseconds).
- ``"host_free_time.{total,max,min,count,avg}"``: time in CUDA free calls
when cached blocks are returned (microseconds).
Block sizes are rounded up to the next power of two before calling CUDA, so
byte stats reflect the rounded size. Peak values are aggregated per bucket
and are a best-effort approximation of the true peak.
host_memory_stats_as_nested_dict() -> dict[str, typing.Any]
Return the result of :func:`~torch.cuda.host_memory_stats` as a nested dictionary.
init()
Initialize PyTorch's CUDA state.
You may need to call this explicitly if you are interacting with
PyTorch via its C API, as Python bindings for CUDA functionality
will not be available until this initialization takes place.
Ordinary users should not need this, as all of PyTorch's CUDA methods
automatically initialize CUDA state on-demand.
Does nothing if the CUDA state is already initialized.
initial_seed() -> int
Return the current random seed of the current GPU.
.. warning::
This function eagerly initializes CUDA.
ipc_collect()
Force collects GPU memory after it has been released by CUDA IPC.
.. note::
Checks if any sent CUDA tensors could be cleaned from the memory. Force
closes shared memory file used for reference counting if there is no
active counters. Useful when the producer process stopped actively sending
tensors and want to release unused memory.
is_available() -> bool
Return a bool indicating if CUDA is currently available.
.. note:: This function will NOT poison fork if the environment variable
``PYTORCH_NVML_BASED_CUDA_CHECK=1`` is set. For more details, see
:ref:`multiprocessing-poison-fork-note`.
is_bf16_supported(including_emulation: bool = True)
Return a bool indicating if the current CUDA/ROCm device supports dtype bfloat16.
is_current_stream_capturing() -> 'bool'
Return True if CUDA graph capture is underway on the current CUDA stream, False otherwise.
If a CUDA context does not exist on the current device, returns False without initializing the context.
is_initialized()
Return whether PyTorch's CUDA state has been initialized.
is_tf32_supported() -> bool
Return a bool indicating if the current CUDA/ROCm device supports dtype tf32.
list_gpu_processes(device: 'Device' = None) -> str
Return a human-readable printout of the running processes and their GPU memory use for a given device.
This can be useful to display periodically during training, or when
handling out-of-memory exceptions.
Args:
device (torch.device or int, optional): selected device. Returns
printout for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
make_graphed_callables(callables: '_ModuleOrCallable | tuple[_ModuleOrCallable, ...]', sample_args: 'tuple[Tensor, ...] | tuple[tuple[Tensor, ...], ...]', num_warmup_iters: 'int' = 3, allow_unused_input: 'bool' = False, pool: '_POOL_HANDLE | None' = None) -> '_ModuleOrCallable | tuple[_ModuleOrCallable, ...]'
Accept callables (functions or :class:`nn.Module<torch.nn.Module>`\ s) and returns graphed versions.
Each graphed callable's forward pass runs its source callable's
forward CUDA work as a CUDA graph inside a single autograd node.
The graphed callable's forward pass also appends
a backward node to the autograd graph. During backward, this node runs the
callable's backward work as a CUDA graph.
Therefore, each graphed callable should be a drop-in replacement for its source callable
in an autograd-enabled training loop.
See :ref:`Partial-network capture<partial-network-capture>` for detailed use and constraints.
If you pass a tuple of several callables, their captures will use the same memory pool.
See :ref:`Graph memory management<graph-memory-management>` for when this is appropriate.
Arguments:
callables (torch.nn.Module or Python function, or tuple of these): Callable or callables to graph.
See :ref:`Graph memory management<graph-memory-management>` for when passing a tuple of callables
is appropriate. If you pass a tuple of callables, their order in the tuple must be the same order
they'll run in the live workload.
sample_args (tuple of Tensors, or tuple of tuples of Tensors): Samples args for each callable.
If a single callable was passed, ``sample_args`` must be a single tuple of argument Tensors.
If a tuple of callables was passed, ``sample_args`` must be tuple of tuples of argument Tensors.
num_warmup_iters (int): The number of warmup iterations. Currently, ``DataDistributedParallel`` needs
11 iterations for warm up. Default: ``3``.
allow_unused_input (bool): If False, specifying inputs that were not used when computing outputs
(and therefore their grad is always zero) is an error. Defaults to False.
pool (optional): Token (returned by :func:`~torch.cuda.graph_pool_handle` or
:meth:`other_Graph_instance.pool()<torch.cuda.CUDAGraph.pool>`) that hints this graph may share memory
with the indicated pool. See :ref:`Graph memory management<graph-memory-management>`.
.. note::
The ``requires_grad`` state of each Tensor in ``sample_args`` must match the state
that's expected for the corresponding real input in the training loop.
.. warning::
This API is in beta and may change in future releases.
.. warning::
``sample_args`` for each callable must contain only Tensors. Other types are not allowed.
.. warning::
Returned callables do not support higher order differentiation (e.g., double backward).
.. warning::
In any :class:`~torch.nn.Module` passed to :func:`~make_graphed_callables`, only parameters
may be trainable. Buffers must have ``requires_grad=False``.
.. warning::
After you pass a :class:`torch.nn.Module` through :func:`~make_graphed_callables`,
you may not add or remove any of that Module's parameters or buffers.
.. warning::
:class:`torch.nn.Module`\s passed to :func:`~torch.cuda.make_graphed_callables` must not have module hooks
registered on them at the time they are passed. However, registering hooks on modules *after* passing them
through :func:`~torch.cuda.make_graphed_callables` is allowed.
.. warning::
When running a graphed callable, you must pass its arguments in the same order and format
they appeared in that callable's ``sample_args``.
.. warning::
The automatic mixed precision is supported in :func:`~torch.cuda.make_graphed_callables` only with disabled
caching. The context manager `torch.cuda.amp.autocast()` must have `cache_enabled=False`.
manual_seed(seed: int) -> None
Set the seed for generating random numbers for the current GPU.
It's safe to call this function if CUDA is not available; in that
case, it is silently ignored.
Args:
seed (int): The desired seed.
.. warning::
If you are working with a multi-GPU model, this function is insufficient
to get determinism. To seed all GPUs, use :func:`manual_seed_all`.
manual_seed_all(seed: int) -> None
Set the seed for generating random numbers on all GPUs.
It's safe to call this function if CUDA is not available; in that
case, it is silently ignored.
Args:
seed (int): The desired seed.
max_memory_allocated(device: 'Device' = None) -> int
Return the maximum GPU memory occupied by tensors in bytes for a given device.
By default, this returns the peak allocated memory since the beginning of
this program. :func:`~torch.cuda.reset_peak_memory_stats` can be used to
reset the starting point in tracking this metric. For example, these two
functions can measure the peak allocated memory usage of each iteration in a
training loop.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
.. note::
See :ref:`cuda-memory-management` for more details about GPU memory
management.
max_memory_cached(device: 'Device' = None) -> int
Deprecated; see :func:`~torch.cuda.max_memory_reserved`.
max_memory_reserved(device: 'Device' = None) -> int
Return the maximum GPU memory managed by the caching allocator in bytes for a given device.
By default, this returns the peak cached memory since the beginning of this
program. :func:`~torch.cuda.reset_peak_memory_stats` can be used to reset
the starting point in tracking this metric. For example, these two functions
can measure the peak cached memory amount of each iteration in a training
loop.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
.. note::
See :ref:`cuda-memory-management` for more details about GPU memory
management.
mem_get_info(device: 'Device' = None) -> tuple[int, int]
Return the global free and total GPU memory for a given device using cudaMemGetInfo.
Args:
device (torch.device or int or str, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default) or if the device index is not specified.
.. note::
See :ref:`cuda-memory-management` for more
details about GPU memory management.
memory_allocated(device: 'Device' = None) -> int
Return the current GPU memory occupied by tensors in bytes for a given device.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
.. note::
This is likely less than the amount shown in `nvidia-smi` since some
unused memory can be held by the caching allocator and some context
needs to be created on GPU. See :ref:`cuda-memory-management` for more
details about GPU memory management.
memory_cached(device: 'Device' = None) -> int
Deprecated; see :func:`~torch.cuda.memory_reserved`.
memory_reserved(device: 'Device' = None) -> int
Return the current GPU memory managed by the caching allocator in bytes for a given device.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
.. note::
See :ref:`cuda-memory-management` for more details about GPU memory
management.
memory_snapshot(mempool_id=None, include_traces=True)
Return a snapshot of the CUDA memory allocator state across all devices.
Interpreting the output of this function requires familiarity with the
memory allocator internals.
Args:
mempool_id: Optional memory pool ID to get snapshot for a specific pool
include_traces: Whether to include trace entries in the snapshot.
If True (default), all trace entries are included.
If False, no trace entries are included (lightweight/fast snapshot).
.. note::
See :ref:`cuda-memory-management` for more details about GPU memory
management.
memory_stats(device: 'Device' = None) -> dict[str, typing.Any]
Return a dictionary of CUDA memory allocator statistics for a given device.
The return value of this function is a dictionary of statistics, each of
which is a non-negative integer.
Core statistics:
- ``"allocated.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
number of allocation requests received by the memory allocator.
- ``"allocated_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
amount of allocated memory.
- ``"segment.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
number of reserved segments from ``cudaMalloc()``.
- ``"reserved_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
amount of reserved memory.
- ``"active.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
number of active memory blocks.
- ``"active_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
amount of active memory.
- ``"inactive_split.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
number of inactive, non-releasable memory blocks.
- ``"inactive_split_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
amount of inactive, non-releasable memory.
For these core statistics, values are broken down as follows.
Pool type:
- ``all``: combined statistics across all memory pools.
- ``large_pool``: statistics for the large allocation pool
(as of June 2025, for size >= 1MB allocations).
- ``small_pool``: statistics for the small allocation pool
(as of June 2025, for size < 1MB allocations).
Metric type:
- ``current``: current value of this metric.
- ``peak``: maximum value of this metric.
- ``allocated``: historical total increase in this metric.
- ``freed``: historical total decrease in this metric.
In addition to the core statistics, we also provide some simple event
counters:
- ``"num_alloc_retries"``: number of failed ``cudaMalloc`` calls that
result in a cache flush and retry.
- ``"num_ooms"``: number of out-of-memory errors thrown.
- ``"num_sync_all_streams"``: number of ``synchronize_and_free_events`` calls.
- ``"num_device_alloc"``: number of CUDA allocation calls. This includes both
cuMemMap and cudaMalloc.
- ``"num_device_free"``: number of CUDA free calls. This includes both cuMemUnmap
and cudaFree.
- ``"num_oom_rejections"``: number of allocations preemptively rejected by the
throw_on_cudamalloc_oom + per_process_memory_fraction policy.
The caching allocator can be configured via ENV to not split blocks larger than a
defined size (see Memory Management section of the Cuda Semantics documentation).
This helps avoid memory fragmentation but may have a performance
penalty. Additional outputs to assist with tuning and evaluating impact:
- ``"max_split_size"``: blocks above this size will not be split.
- ``"oversize_allocations.{current,peak,allocated,freed}"``:
number of over-size allocation requests received by the memory allocator.
- ``"oversize_segments.{current,peak,allocated,freed}"``:
number of over-size reserved segments from ``cudaMalloc()``.
The caching allocator can be configured via ENV to round memory allocations in order
to reduce fragmentation. Sometimes the overhead from rounding can be higher than
the fragmentation it helps reduce. The following stat can be used to check if
rounding adds too much overhead:
- ``"requested_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
memory requested by client code, compare this with allocated_bytes to check if
allocation rounding adds too much overhead.
- ``"reserved_bytes_by_private_pools"``: nested dictionary keyed by
``torch.cuda.MemPool.id`` tuples. Each value has the same
``{all,large_pool,small_pool}.{current,peak,allocated,freed}`` structure
as ``reserved_bytes``, but scoped to a single private pool. In
:func:`~torch.cuda.memory_stats`, tuple keys are flattened by joining
their stringified elements with ``"_"``, so ``(0, 1)`` becomes ``"0_1"``.
Args:
device (torch.device or int, optional): selected device. Returns
statistics for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
.. note::
See :ref:`cuda-memory-management` for more details about GPU memory
management.
.. note::
With :ref:`backend:cudaMallocAsync<cuda-memory-envvars>`, some stats are not
meaningful, and are always reported as zero.
memory_stats_as_nested_dict(device: 'Device' = None) -> dict[str, typing.Any]
Return the result of :func:`~torch.cuda.memory_stats` as a nested dictionary.
memory_summary(device: 'Device' = None, abbreviated: bool = False) -> str
Return a human-readable printout of the current memory allocator statistics for a given device.
This can be useful to display periodically during training, or when
handling out-of-memory exceptions.
Args:
device (torch.device or int, optional): selected device. Returns
printout for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
abbreviated (bool, optional): whether to return an abbreviated summary
(default: False).
.. note::
See :ref:`cuda-memory-management` for more details about GPU memory
management.
memory_usage(device: torch.device | str | int | None = None) -> int
Return the percent of time over the past sample period during which global (device)
memory was being read or written as given by `nvidia-smi`.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
Warning: Each sample period may be between 1 second and 1/6 second,
depending on the product being queried.
power_draw(device: torch.device | str | int | None = None) -> int
Return the average power draw of the GPU sensor in mW (MilliWatts)
over the past sample period as given by `nvidia-smi` for Fermi or newer fully supported devices.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
Warning: Each sample period may be between 1 second and 1/6 second,
depending on the product being queried.
reset_accumulated_host_memory_stats() -> None
Reset the "accumulated" (historical) stats tracked by the host memory allocator.
See :func:`~torch.cuda.host_memory_stats` for details. Accumulated stats correspond to
the `"allocated"` and `"freed"` keys in each individual stat dict.
reset_accumulated_memory_stats(device: 'Device' = None) -> None
Reset the "accumulated" (historical) stats tracked by the CUDA memory allocator.
See :func:`~torch.cuda.memory_stats` for details. Accumulated stats correspond to
the `"allocated"` and `"freed"` keys in each individual stat dict, as well as
`"num_alloc_retries"` and `"num_ooms"`.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
.. note::
See :ref:`cuda-memory-management` for more details about GPU memory
management.
reset_max_memory_allocated(device: 'Device' = None) -> None
Reset the starting point in tracking maximum GPU memory occupied by tensors for a given device.
See :func:`~torch.cuda.max_memory_allocated` for details.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
.. warning::
This function now calls :func:`~torch.cuda.reset_peak_memory_stats`, which resets
/all/ peak memory stats.
.. note::
See :ref:`cuda-memory-management` for more details about GPU memory
management.
reset_max_memory_cached(device: 'Device' = None) -> None
Reset the starting point in tracking maximum GPU memory managed by the caching allocator for a given device.
See :func:`~torch.cuda.max_memory_cached` for details.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
.. warning::
This function now calls :func:`~torch.cuda.reset_peak_memory_stats`, which resets
/all/ peak memory stats.
.. note::
See :ref:`cuda-memory-management` for more details about GPU memory
management.
reset_peak_host_memory_stats() -> None
Reset the "peak" stats tracked by the host memory allocator.
See :func:`~torch.cuda.host_memory_stats` for details. Peak stats correspond to the
`"peak"` key in each individual stat dict.
reset_peak_memory_stats(device: 'Device' = None) -> None
Reset the "peak" stats tracked by the CUDA memory allocator.
See :func:`~torch.cuda.memory_stats` for details. Peak stats correspond to the
`"peak"` key in each individual stat dict.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
.. note::
See :ref:`cuda-memory-management` for more details about GPU memory
management.
seed() -> None
Set the seed for generating random numbers to a random number for the current GPU.
It's safe to call this function if CUDA is not available; in that
case, it is silently ignored.
.. warning::
If you are working with a multi-GPU model, this function will only initialize
the seed on one GPU. To initialize all GPUs, use :func:`seed_all`.
seed_all() -> None
Set the seed for generating random numbers to a random number on all GPUs.
It's safe to call this function if CUDA is not available; in that
case, it is silently ignored.
set_device(device: torch.device | str | int | None) -> None
Set the current device.
Usage of this function is discouraged in favor of :any:`device`. In most
cases it's better to use ``CUDA_VISIBLE_DEVICES`` environmental variable.
Args:
device (torch.device or int): selected device. This function is a no-op
if this argument is negative.
set_per_process_memory_fraction(fraction, device: 'Device' = None) -> None
Set memory fraction for a process.
The fraction is used to limit an caching allocator to allocated memory on a CUDA device.
The allowed value equals the total visible memory multiplied fraction.
If trying to allocate more than the allowed value in a process, will raise an out of
memory error in allocator.
Args:
fraction(float): Range: 0~1. Allowed memory equals total_memory * fraction.
device (torch.device or int, optional): selected device. If it is
``None`` the default CUDA device is used.
.. note::
In general, the total available free memory is less than the total capacity.
set_rng_state(new_state: torch.Tensor, device: int | str | torch.device = 'cuda') -> None
Set the random number generator state of the specified GPU.
Args:
new_state (torch.ByteTensor): The desired state
device (torch.device or int, optional): The device to set the RNG state.
Default: ``'cuda'`` (i.e., ``torch.device('cuda')``, the current CUDA device).
set_rng_state_all(new_states: collections.abc.Iterable[torch.Tensor]) -> None
Set the random number generator state of all devices.
Args:
new_states (Iterable of torch.ByteTensor): The desired state for each device.
set_stream(stream: torch.cuda.streams.Stream)
Set the current stream. This is a wrapper API to set the stream.
Usage of this function is discouraged in favor of the ``stream``
context manager.
Args:
stream (Stream): selected stream. This function is a no-op
if this argument is ``None``.
set_sync_debug_mode(debug_mode: int | str) -> None
Set the debug mode for cuda synchronizing operations.
Args:
debug_mode(str or int): if "default" or 0, don't error or warn on synchronizing operations,
if "warn" or 1, warn on synchronizing operations, if "error" or 2, error out synchronizing operations.
Warning:
This is an experimental feature, and not all synchronizing operations will trigger warning or error. In
particular, operations in torch.distributed and torch.sparse namespaces are not covered yet.
stream(stream: Optional[ForwardRef('torch.cuda.Stream')]) -> torch.cuda.StreamContext
Wrap around the Context-manager StreamContext that selects a given stream.
Arguments:
stream (Stream): selected stream. This manager is a no-op if it's
``None``.
.. note::
In eager mode stream is of type Stream class while in JIT it is
an object of the custom class ``torch.classes.cuda.Stream``.
synchronize(device: torch.device | str | int | None = None) -> None
Wait for all kernels in all streams on a CUDA device to complete.
Args:
device (torch.device or int, optional): device for which to synchronize.
It uses the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
temperature(device: torch.device | str | int | None = None) -> int
Return the average temperature of the GPU sensor in Degrees C (Centigrades).
The average temperature is computed based on past sample period as given by `nvidia-smi`.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
Warning: Each sample period may be between 1 second and 1/6 second,
depending on the product being queried.
use_mem_pool(pool: torch.cuda.memory.MemPool, device: 'Device' = None)
A context manager that routes allocations to a given pool.
Args:
pool(torch.cuda.MemPool): a MemPool object to be made active so that
allocations route to this pool.
device (torch.device or int, optional): selected device. Uses MemPool on
the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
.. note::
This context manager makes only current thread's allocations route to
the given pool. If a new thread is spawned inside the context manager
(e.g. by calling backward) the allocations in that thread will not
route to the given pool.
utilization(device: torch.device | str | int | None = None) -> int
Return the percent of time over the past sample period during which one or
more kernels was executing on the GPU as given by `nvidia-smi`.
Args:
device (torch.device or int, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.cuda.current_device`,
if :attr:`device` is ``None`` (default).
Warning: Each sample period may be between 1 second and 1/6 second,
depending on the product being queried.
DATA
__all__ = ['BFloat16Storage', 'BFloat16Tensor', 'BoolStorage', 'BoolTe...
__annotations__ = {'DEVICE_REQUIREMENT': dict[int, torch.cuda._CompatS...
default_generators = ()
has_half = True
has_magma = False
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\cuda\__init__.py
torch.cudnn_affine_grid_generator
Python Library Documentation: built-in function cudnn_affine_grid_generator in module torch cudnn_affine_grid_generator(...)
torch.cudnn_batch_norm
Python Library Documentation: built-in function cudnn_batch_norm in module torch cudnn_batch_norm(...)
torch.cudnn_convolution
Python Library Documentation: built-in function cudnn_convolution in module torch cudnn_convolution(...)
torch.cudnn_convolution_add_relu
Python Library Documentation: built-in function cudnn_convolution_add_relu in module torch cudnn_convolution_add_relu(...)
torch.cudnn_convolution_relu
Python Library Documentation: built-in function cudnn_convolution_relu in module torch cudnn_convolution_relu(...)
torch.cudnn_convolution_transpose
Python Library Documentation: built-in function cudnn_convolution_transpose in module torch cudnn_convolution_transpose(...)
torch.cudnn_grid_sampler
Python Library Documentation: built-in function cudnn_grid_sampler in module torch cudnn_grid_sampler(...)
torch.cudnn_is_acceptable
Python Library Documentation: built-in function cudnn_is_acceptable in module torch cudnn_is_acceptable(...)
torch.cummax
Python Library Documentation: built-in function cummax in module torch
cummax(...)
cummax(input, dim, *, out=None) -> (Tensor, LongTensor)
Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative maximum of
elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
location of each maximum value found in the dimension :attr:`dim`.
.. math::
y_i = max(x_1, x_2, x_3, \dots, x_i)
Args:
input (Tensor): the input tensor.
dim (int): the dimension to do the operation over
Keyword args:
out (tuple, optional): the result tuple of two output tensors (values, indices)
Example::
>>> a = torch.randn(10)
>>> a
tensor([-0.3449, -1.5447, 0.0685, -1.5104, -1.1706, 0.2259, 1.4696, -1.3284,
1.9946, -0.8209])
>>> torch.cummax(a, dim=0)
torch.return_types.cummax(
values=tensor([-0.3449, -0.3449, 0.0685, 0.0685, 0.0685, 0.2259, 1.4696, 1.4696,
1.9946, 1.9946]),
indices=tensor([0, 0, 2, 2, 2, 5, 6, 6, 8, 8]))
torch.cummin
Python Library Documentation: built-in function cummin in module torch
cummin(...)
cummin(input, dim, *, out=None) -> (Tensor, LongTensor)
Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative minimum of
elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
location of each maximum value found in the dimension :attr:`dim`.
.. math::
y_i = min(x_1, x_2, x_3, \dots, x_i)
Args:
input (Tensor): the input tensor.
dim (int): the dimension to do the operation over
Keyword args:
out (tuple, optional): the result tuple of two output tensors (values, indices)
Example::
>>> a = torch.randn(10)
>>> a
tensor([-0.2284, -0.6628, 0.0975, 0.2680, -1.3298, -0.4220, -0.3885, 1.1762,
0.9165, 1.6684])
>>> torch.cummin(a, dim=0)
torch.return_types.cummin(
values=tensor([-0.2284, -0.6628, -0.6628, -0.6628, -1.3298, -1.3298, -1.3298, -1.3298,
-1.3298, -1.3298]),
indices=tensor([0, 1, 1, 1, 4, 4, 4, 4, 4, 4]))
torch.cumprod
Python Library Documentation: built-in function cumprod in module torch
cumprod(...)
cumprod(input, dim, *, dtype=None, out=None) -> Tensor
Returns the cumulative product of elements of :attr:`input` in the dimension
:attr:`dim`.
For example, if :attr:`input` is a vector of size N, the result will also be
a vector of size N, with elements.
.. math::
y_i = x_1 \times x_2\times x_3\times \dots \times x_i
Args:
input (Tensor): the input tensor.
dim (int): the dimension to do the operation over
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(10)
>>> a
tensor([ 0.6001, 0.2069, -0.1919, 0.9792, 0.6727, 1.0062, 0.4126,
-0.2129, -0.4206, 0.1968])
>>> torch.cumprod(a, dim=0)
tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0158, -0.0065,
0.0014, -0.0006, -0.0001])
>>> a[5] = 0.0
>>> torch.cumprod(a, dim=0)
tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0000, -0.0000,
0.0000, -0.0000, -0.0000])
torch.cumsum
Python Library Documentation: built-in function cumsum in module torch
cumsum(...)
cumsum(input, dim, *, dtype=None, out=None) -> Tensor
Returns the cumulative sum of elements of :attr:`input` in the dimension
:attr:`dim`.
For example, if :attr:`input` is a vector of size N, the result will also be
a vector of size N, with elements.
.. math::
y_i = x_1 + x_2 + x_3 + \dots + x_i
Args:
input (Tensor): the input tensor.
dim (int): the dimension to do the operation over
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randint(1, 20, (10,))
>>> a
tensor([13, 7, 3, 10, 13, 3, 15, 10, 9, 10])
>>> torch.cumsum(a, dim=0)
tensor([13, 20, 23, 33, 46, 49, 64, 74, 83, 93])
torch.cumulative_trapezoid
Python Library Documentation: built-in function cumulative_trapezoid in module torch
cumulative_trapezoid(...)
cumulative_trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
Cumulatively computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_
along :attr:`dim`. By default the spacing between elements is assumed to be 1, but
:attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
used to specify arbitrary spacing along :attr:`dim`.
For more details, please read :func:`torch.trapezoid`. The difference between :func:`torch.trapezoid`
and this function is that, :func:`torch.trapezoid` returns a value for each integration,
where as this function returns a cumulative value for every spacing within the integration. This
is analogous to how `.sum` returns a value and `.cumsum` returns a cumulative sum.
Arguments:
y (Tensor): Values to use when computing the trapezoidal rule.
x (Tensor): If specified, defines spacing between values as specified above.
Keyword arguments:
dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
are specified then this defaults to 1. Effectively multiplies the result by its value.
dim (int): The dimension along which to compute the trapezoidal rule.
The last (inner-most) dimension by default.
Examples::
>>> # Cumulatively computes the trapezoidal rule in 1D, spacing is implicitly 1.
>>> y = torch.tensor([1, 5, 10])
>>> torch.cumulative_trapezoid(y)
tensor([3., 10.5])
>>> # Computes the same trapezoidal rule directly up to each element to verify
>>> (1 + 5) / 2
3.0
>>> (1 + 10 + 10) / 2
10.5
>>> # Cumulatively computes the trapezoidal rule in 1D with constant spacing of 2
>>> # NOTE: the result is the same as before, but multiplied by 2
>>> torch.cumulative_trapezoid(y, dx=2)
tensor([6., 21.])
>>> # Cumulatively computes the trapezoidal rule in 1D with arbitrary spacing
>>> x = torch.tensor([1, 3, 6])
>>> torch.cumulative_trapezoid(y, x)
tensor([6., 28.5])
>>> # Computes the same trapezoidal rule directly up to each element to verify
>>> ((3 - 1) * (1 + 5)) / 2
6.0
>>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
28.5
>>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 matrix
>>> y = torch.arange(9).reshape(3, 3)
tensor([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> torch.cumulative_trapezoid(y)
tensor([[ 0.5, 2.],
[ 3.5, 8.],
[ 6.5, 14.]])
>>> # Cumulatively computes the trapezoidal rule for each column of the matrix
>>> torch.cumulative_trapezoid(y, dim=0)
tensor([[ 1.5, 2.5, 3.5],
[ 6.0, 8.0, 10.0]])
>>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
>>> # with the same arbitrary spacing
>>> y = torch.ones(3, 3)
>>> x = torch.tensor([1, 3, 6])
>>> torch.cumulative_trapezoid(y, x)
tensor([[2., 5.],
[2., 5.],
[2., 5.]])
>>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
>>> # with different arbitrary spacing per row
>>> y = torch.ones(3, 3)
>>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
>>> torch.cumulative_trapezoid(y, x)
tensor([[1., 2.],
[2., 4.],
[3., 6.]])
torch.default_generator
Python Library Documentation: Generator in module torch._C object class Generator(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __setstate__(...) | | clone_state(...) | Generator.clone_state() -> torch.Generator | | Clones the current state of the generator and returns a new generator pointing to this cloned state. | This method is beneficial for preserving a particular state of a generator to restore at a later point. | | Returns: | torch.Generator: A Generator pointing to the newly cloned state. | | Example: | >>> g_cuda = torch.Generator(device='cuda') | >>> cloned_state = g_cuda.clone_state() | | get_offset(...) | | get_state(...) | Generator.get_state() -> Tensor | | Returns the Generator state as a ``torch.ByteTensor``. | | Returns: | Tensor: A ``torch.ByteTensor`` which contains all the necessary bits | to restore a Generator to a specific point in time. | | Example:: | | >>> g_cpu = torch.Generator() | >>> g_cpu.get_state() | | graphsafe_get_state(...) | Generator.graphsafe_get_state() -> torch.Generator | | Retrieves the current state of the generator in a manner that is safe for graph capture. | This method is crucial for ensuring that the generator's state can be captured in the CUDA graph. | | Returns: | torch.Generator: A Generator point to the current state of the generator | | Example: | >>> g_cuda = torch.Generator(device='cuda') | >>> current_state = g_cuda.graphsafe_get_state() | | graphsafe_set_state(...) | Generator.graphsafe_set_state(state) -> None | | Sets the state of the generator to the specified state in a manner that is safe for use in graph capture. | This method is crucial for ensuring that the generator's state can be captured in the CUDA graph. | | Arguments: | state (torch.Generator): A Generator point to the new state for the generator, typically obtained from `graphsafe_get_state`. | | Example: | >>> g_cuda = torch.Generator(device='cuda') | >>> g_cuda_other = torch.Generator(device='cuda') | >>> current_state = g_cuda_other.graphsafe_get_state() | >>> g_cuda.graphsafe_set_state(current_state) | | initial_seed(...) | Generator.initial_seed() -> int | | Returns the initial seed for generating random numbers. | | Example:: | | >>> g_cpu = torch.Generator() | >>> g_cpu.initial_seed() | 2147483647 | | manual_seed(...) | Generator.manual_seed(seed) -> Generator | | Sets the seed for generating random numbers. Returns a `torch.Generator` object. Any 32-bit integer is a valid seed. | | Arguments: | seed (int): The desired seed. Value must be within the inclusive range | `[-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]`. Otherwise, a RuntimeError | is raised. Negative inputs are remapped to positive values with the formula | `0xffff_ffff_ffff_ffff + seed`. | | Returns: | Generator: An torch.Generator object. | | Example:: | | >>> g_cpu = torch.Generator() | >>> g_cpu.manual_seed(2147483647) | | seed(...) | Generator.seed() -> int | | Gets a non-deterministic random number from std::random_device or the current | time and uses it to seed a Generator. | | Example:: | | >>> g_cpu = torch.Generator() | >>> g_cpu.seed() | 1516516984916 | | set_offset(...) | | set_state(...) | Generator.set_state(new_state) -> void | | Sets the Generator state. | | Arguments: | new_state (torch.ByteTensor): The desired state. | | Example:: | | >>> g_cpu = torch.Generator() | >>> g_cpu_other = torch.Generator() | >>> g_cpu.set_state(g_cpu_other.get_state()) | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | device | Generator.device -> device | | Gets the current device of the generator. | | Example:: | | >>> g_cpu = torch.Generator() | >>> g_cpu.device | device(type='cpu')
torch.deg2rad
Python Library Documentation: built-in function deg2rad in module torch
deg2rad(...)
deg2rad(input, *, out=None) -> Tensor
Returns a new tensor with each of the elements of :attr:`input`
converted from angles in degrees to radians.
Args:
input (Tensor): the input tensor.
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([[180.0, -180.0], [360.0, -360.0], [90.0, -90.0]])
>>> torch.deg2rad(a)
tensor([[ 3.1416, -3.1416],
[ 6.2832, -6.2832],
[ 1.5708, -1.5708]])
torch.deg2rad_
Python Library Documentation: built-in function deg2rad_ in module torch deg2rad_(...)
torch.dequantize
Python Library Documentation: built-in function dequantize in module torch
dequantize(...)
dequantize(tensor) -> Tensor
Returns an fp32 Tensor by dequantizing a quantized Tensor
Args:
tensor (Tensor): A quantized Tensor
.. function:: dequantize(tensors) -> sequence of Tensors
:noindex:
Given a list of quantized Tensors, dequantize them and return a list of fp32 Tensors
Args:
tensors (sequence of Tensors): A list of quantized Tensors
torch.det
Python Library Documentation: built-in function det in module torch
det(...)
det(input) -> Tensor
Alias for :func:`torch.linalg.det`
torch.detach
Python Library Documentation: built-in function detach in module torch detach(...)
torch.detach_
Python Library Documentation: built-in function detach_ in module torch detach_(...)
torch.detach_copy
Python Library Documentation: built-in function detach_copy in module torch
detach_copy(...)
Performs the same operation as :func:`torch.detach`, but all output tensors
are freshly created instead of aliasing the input.
torch.device
Python Library Documentation: class device in module torch class device(builtins.object) | Methods defined here: | | __enter__(...) | | __eq__(self, value, /) | Return self==value. | | __exit__(...) | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __str__(self, /) | Return str(self). | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | index | | type
torch.diag
Python Library Documentation: built-in function diag in module torch
diag(...)
diag(input, diagonal=0, *, out=None) -> Tensor
- If :attr:`input` is a vector (1-D tensor), then returns a 2-D square tensor
with the elements of :attr:`input` as the diagonal.
- If :attr:`input` is a matrix (2-D tensor), then returns a 1-D tensor with
the diagonal elements of :attr:`input`.
The argument :attr:`diagonal` controls which diagonal to consider:
- If :attr:`diagonal` = 0, it is the main diagonal.
- If :attr:`diagonal` > 0, it is above the main diagonal.
- If :attr:`diagonal` < 0, it is below the main diagonal.
Args:
input (Tensor): the input tensor.
diagonal (int, optional): the diagonal to consider
Keyword args:
out (Tensor, optional): the output tensor.
.. seealso::
:func:`torch.diagonal` always returns the diagonal of its input.
:func:`torch.diagflat` always constructs a tensor with diagonal elements
specified by the input.
Examples:
Get the square matrix where the input vector is the diagonal::
>>> a = torch.randn(3)
>>> a
tensor([ 0.5950,-0.0872, 2.3298])
>>> torch.diag(a)
tensor([[ 0.5950, 0.0000, 0.0000],
[ 0.0000,-0.0872, 0.0000],
[ 0.0000, 0.0000, 2.3298]])
>>> torch.diag(a, 1)
tensor([[ 0.0000, 0.5950, 0.0000, 0.0000],
[ 0.0000, 0.0000,-0.0872, 0.0000],
[ 0.0000, 0.0000, 0.0000, 2.3298],
[ 0.0000, 0.0000, 0.0000, 0.0000]])
Get the k-th diagonal of a given matrix::
>>> a = torch.randn(3, 3)
>>> a
tensor([[-0.4264, 0.0255,-0.1064],
[ 0.8795,-0.2429, 0.1374],
[ 0.1029,-0.6482,-1.6300]])
>>> torch.diag(a, 0)
tensor([-0.4264,-0.2429,-1.6300])
>>> torch.diag(a, 1)
tensor([ 0.0255, 0.1374])
torch.diag_embed
Python Library Documentation: built-in function diag_embed in module torch
diag_embed(...)
diag_embed(input, offset=0, dim1=-2, dim2=-1) -> Tensor
Creates a tensor whose diagonals of certain 2D planes (specified by
:attr:`dim1` and :attr:`dim2`) are filled by :attr:`input`.
To facilitate creating batched diagonal matrices, the 2D planes formed by
the last two dimensions of the returned tensor are chosen by default.
The argument :attr:`offset` controls which diagonal to consider:
- If :attr:`offset` = 0, it is the main diagonal.
- If :attr:`offset` > 0, it is above the main diagonal.
- If :attr:`offset` < 0, it is below the main diagonal.
The size of the new matrix will be calculated to make the specified diagonal
of the size of the last input dimension.
Note that for :attr:`offset` other than :math:`0`, the order of :attr:`dim1`
and :attr:`dim2` matters. Exchanging them is equivalent to changing the
sign of :attr:`offset`.
Applying :meth:`torch.diagonal` to the output of this function with
the same arguments yields a matrix identical to input. However,
:meth:`torch.diagonal` has different default dimensions, so those
need to be explicitly specified.
Args:
input (Tensor): the input tensor. Must be at least 1-dimensional.
offset (int, optional): which diagonal to consider. Default: 0
(main diagonal).
dim1 (int, optional): first dimension with respect to which to
take diagonal. Default: -2.
dim2 (int, optional): second dimension with respect to which to
take diagonal. Default: -1.
Example::
>>> a = torch.randn(2, 3)
>>> torch.diag_embed(a)
tensor([[[ 1.5410, 0.0000, 0.0000],
[ 0.0000, -0.2934, 0.0000],
[ 0.0000, 0.0000, -2.1788]],
[[ 0.5684, 0.0000, 0.0000],
[ 0.0000, -1.0845, 0.0000],
[ 0.0000, 0.0000, -1.3986]]])
>>> torch.diag_embed(a, offset=1, dim1=0, dim2=2)
tensor([[[ 0.0000, 1.5410, 0.0000, 0.0000],
[ 0.0000, 0.5684, 0.0000, 0.0000]],
[[ 0.0000, 0.0000, -0.2934, 0.0000],
[ 0.0000, 0.0000, -1.0845, 0.0000]],
[[ 0.0000, 0.0000, 0.0000, -2.1788],
[ 0.0000, 0.0000, 0.0000, -1.3986]],
[[ 0.0000, 0.0000, 0.0000, 0.0000],
[ 0.0000, 0.0000, 0.0000, 0.0000]]])
torch.diagflat
Python Library Documentation: built-in function diagflat in module torch
diagflat(...)
diagflat(input, offset=0) -> Tensor
- If :attr:`input` is a vector (1-D tensor), then returns a 2-D square tensor
with the elements of :attr:`input` as the diagonal.
- If :attr:`input` is a tensor with more than one dimension, then returns a
2-D tensor with diagonal elements equal to a flattened :attr:`input`.
The argument :attr:`offset` controls which diagonal to consider:
- If :attr:`offset` = 0, it is the main diagonal.
- If :attr:`offset` > 0, it is above the main diagonal.
- If :attr:`offset` < 0, it is below the main diagonal.
Args:
input (Tensor): the input tensor.
offset (int, optional): the diagonal to consider. Default: 0 (main
diagonal).
Examples::
>>> a = torch.randn(3)
>>> a
tensor([-0.2956, -0.9068, 0.1695])
>>> torch.diagflat(a)
tensor([[-0.2956, 0.0000, 0.0000],
[ 0.0000, -0.9068, 0.0000],
[ 0.0000, 0.0000, 0.1695]])
>>> torch.diagflat(a, 1)
tensor([[ 0.0000, -0.2956, 0.0000, 0.0000],
[ 0.0000, 0.0000, -0.9068, 0.0000],
[ 0.0000, 0.0000, 0.0000, 0.1695],
[ 0.0000, 0.0000, 0.0000, 0.0000]])
>>> a = torch.randn(2, 2)
>>> a
tensor([[ 0.2094, -0.3018],
[-0.1516, 1.9342]])
>>> torch.diagflat(a)
tensor([[ 0.2094, 0.0000, 0.0000, 0.0000],
[ 0.0000, -0.3018, 0.0000, 0.0000],
[ 0.0000, 0.0000, -0.1516, 0.0000],
[ 0.0000, 0.0000, 0.0000, 1.9342]])
torch.diagonal
Python Library Documentation: built-in function diagonal in module torch
diagonal(...)
diagonal(input, offset=0, dim1=0, dim2=1) -> Tensor
Returns a partial view of :attr:`input` with the its diagonal elements
with respect to :attr:`dim1` and :attr:`dim2` appended as a dimension
at the end of the shape.
The argument :attr:`offset` controls which diagonal to consider:
- If :attr:`offset` = 0, it is the main diagonal.
- If :attr:`offset` > 0, it is above the main diagonal.
- If :attr:`offset` < 0, it is below the main diagonal.
Applying :meth:`torch.diag_embed` to the output of this function with
the same arguments yields a diagonal matrix with the diagonal entries
of the input. However, :meth:`torch.diag_embed` has different default
dimensions, so those need to be explicitly specified.
Args:
input (Tensor): the input tensor. Must be at least 2-dimensional.
offset (int, optional): which diagonal to consider. Default: 0
(main diagonal).
dim1 (int, optional): first dimension with respect to which to
take diagonal. Default: 0.
dim2 (int, optional): second dimension with respect to which to
take diagonal. Default: 1.
.. note:: To take a batch diagonal, pass in dim1=-2, dim2=-1.
Examples::
>>> a = torch.randn(3, 3)
>>> a
tensor([[-1.0854, 1.1431, -0.1752],
[ 0.8536, -0.0905, 0.0360],
[ 0.6927, -0.3735, -0.4945]])
>>> torch.diagonal(a)
tensor([-1.0854, -0.0905, -0.4945])
>>> torch.diagonal(a, 1)
tensor([ 1.1431, 0.0360])
>>> b = torch.randn(2, 5)
>>> b
tensor([[-1.7948, -1.2731, -0.3181, 2.0200, -1.6745],
[ 1.8262, -1.5049, 0.4114, 1.0704, -1.2607]])
>>> torch.diagonal(b, 1, 1, 0)
tensor([1.8262])
>>> x = torch.randn(2, 5, 4, 2)
>>> torch.diagonal(x, offset=-1, dim1=1, dim2=2)
tensor([[[-1.2631, 0.3755, -1.5977, -1.8172],
[-1.1065, 1.0401, -0.2235, -0.7938]],
[[-1.7325, -0.3081, 0.6166, 0.2335],
[ 1.0500, 0.7336, -0.3836, -1.1015]]])
torch.diagonal_copy
Python Library Documentation: built-in function diagonal_copy in module torch
diagonal_copy(...)
Performs the same operation as :func:`torch.diagonal`, but all output tensors
are freshly created instead of aliasing the input.
torch.diagonal_scatter
Python Library Documentation: built-in function diagonal_scatter in module torch
diagonal_scatter(...)
diagonal_scatter(input, src, offset=0, dim1=0, dim2=1) -> Tensor
Embeds the values of the :attr:`src` tensor into :attr:`input` along
the diagonal elements of :attr:`input`, with respect to :attr:`dim1`
and :attr:`dim2`.
This function returns a tensor with fresh storage; it does not
return a view.
The argument :attr:`offset` controls which diagonal to consider:
- If :attr:`offset` = 0, it is the main diagonal.
- If :attr:`offset` > 0, it is above the main diagonal.
- If :attr:`offset` < 0, it is below the main diagonal.
Args:
input (Tensor): the input tensor. Must be at least 2-dimensional.
src (Tensor): the tensor to embed into :attr:`input`.
offset (int, optional): which diagonal to consider. Default: 0
(main diagonal).
dim1 (int, optional): first dimension with respect to which to
take diagonal. Default: 0.
dim2 (int, optional): second dimension with respect to which to
take diagonal. Default: 1.
.. note::
:attr:`src` must be of the proper size in order to be embedded
into :attr:`input`. Specifically, it should have the same shape as
``torch.diagonal(input, offset, dim1, dim2)``
Examples::
>>> a = torch.zeros(3, 3)
>>> a
tensor([[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]])
>>> torch.diagonal_scatter(a, torch.ones(3), 0)
tensor([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])
>>> torch.diagonal_scatter(a, torch.ones(2), 1)
tensor([[0., 1., 0.],
[0., 0., 1.],
[0., 0., 0.]])
torch.diff
Python Library Documentation: built-in function diff in module torch
diff(...)
diff(input, n=1, dim=-1, prepend=None, append=None) -> Tensor
Computes the n-th forward difference along the given dimension.
The first-order differences are given by `out[i] = input[i + 1] - input[i]`. Higher-order
differences are calculated by using :func:`torch.diff` recursively.
Args:
input (Tensor): the tensor to compute the differences on
n (int, optional): the number of times to recursively compute the difference
dim (int, optional): the dimension to compute the difference along.
Default is the last dimension.
prepend, append (Tensor, optional): values to prepend or append to
:attr:`input` along :attr:`dim` before computing the difference.
Their dimensions must be equivalent to that of input, and their shapes
must match input's shape except on :attr:`dim`.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([1, 3, 2])
>>> torch.diff(a)
tensor([ 2, -1])
>>> b = torch.tensor([4, 5])
>>> torch.diff(a, append=b)
tensor([ 2, -1, 2, 1])
>>> c = torch.tensor([[1, 2, 3], [3, 4, 5]])
>>> torch.diff(c, dim=0)
tensor([[2, 2, 2]])
>>> torch.diff(c, dim=1)
tensor([[1, 1],
[1, 1]])
torch.digamma
Python Library Documentation: built-in function digamma in module torch
digamma(...)
digamma(input, *, out=None) -> Tensor
Alias for :func:`torch.special.digamma`.
torch.dist
Python Library Documentation: built-in function dist in module torch
dist(...)
dist(input, other, p=2) -> Tensor
Returns the p-norm of (:attr:`input` - :attr:`other`)
The shapes of :attr:`input` and :attr:`other` must be
:ref:`broadcastable <broadcasting-semantics>`.
Args:
input (Tensor): the input tensor.
other (Tensor): the Right-hand-side input tensor
p (float, optional): the norm to be computed
Example::
>>> x = torch.randn(4)
>>> x
tensor([-1.5393, -0.8675, 0.5916, 1.6321])
>>> y = torch.randn(4)
>>> y
tensor([ 0.0967, -1.0511, 0.6295, 0.8360])
>>> torch.dist(x, y, 3.5)
tensor(1.6727)
>>> torch.dist(x, y, 3)
tensor(1.6973)
>>> torch.dist(x, y, 0)
tensor(4.)
>>> torch.dist(x, y, 1)
tensor(2.6537)
torch.distributed
Python Library Documentation: package torch.distributed in torch
NAME
torch.distributed - # mypy: allow-untyped-defs
PACKAGE CONTENTS
_checkpointable
_composable (package)
_composable_state
_dist2
_functional_collectives
_functional_collectives_impl
_local_tensor (package)
_mesh_layout
_meta_registrations
_ops (package)
_pycute (package)
_serialization
_shard (package)
_sharded_tensor (package)
_sharding_spec (package)
_state_dict_utils
_symmetric_memory (package)
_tensor (package)
_tools (package)
algorithms (package)
argparse_util
autograd (package)
c10d_logger
checkpoint (package)
collective_utils
config
constants
debug (package)
device_mesh
distributed_c10d
elastic (package)
flight_recorder (package)
fsdp (package)
launch
launcher (package)
logging_handlers
nn (package)
optim (package)
pipelining (package)
remote_device
rendezvous
rpc (package)
run
tensor (package)
utils
CLASSES
builtins.RuntimeError(builtins.Exception)
DistError
DistBackendError
DistNetworkError
DistStoreError
QueueEmptyError
class DistBackendError(DistError)
| Exception raised when a backend error occurs in distributed
|
| Method resolution order:
| DistBackendError
| DistError
| builtins.RuntimeError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from DistError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.RuntimeError:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.RuntimeError:
|
| __new__(*args, **kwargs) class method of builtins.RuntimeError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class DistError(builtins.RuntimeError)
| Exception raised when an error occurs in the distributed library
|
| Method resolution order:
| DistError
| builtins.RuntimeError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.RuntimeError:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.RuntimeError:
|
| __new__(*args, **kwargs) class method of builtins.RuntimeError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class DistNetworkError(DistError)
| Exception raised when a network error occurs in distributed
|
| Method resolution order:
| DistNetworkError
| DistError
| builtins.RuntimeError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from DistError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.RuntimeError:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.RuntimeError:
|
| __new__(*args, **kwargs) class method of builtins.RuntimeError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class DistStoreError(DistError)
| Exception raised when an error occurs in the distributed store
|
| Method resolution order:
| DistStoreError
| DistError
| builtins.RuntimeError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from DistError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.RuntimeError:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.RuntimeError:
|
| __new__(*args, **kwargs) class method of builtins.RuntimeError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class QueueEmptyError(DistStoreError)
| Exception raised when an error occurs in the distributed store
|
| Method resolution order:
| QueueEmptyError
| DistStoreError
| DistError
| builtins.RuntimeError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from DistError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.RuntimeError:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.RuntimeError:
|
| __new__(*args, **kwargs) class method of builtins.RuntimeError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
FUNCTIONS
breakpoint(rank: int = 0, skip: int = 0, timeout_s=3600)
Set a breakpoint, but only on a single rank. All other ranks will wait for you to be
done with the breakpoint before continuing.
Args:
rank (int): Which rank to break on. Default: ``0``
skip (int): Skip the first ``skip`` calls to this breakpoint. Default: ``0``.
get_debug_level(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
get_debug_level() -> torch._C._distributed_c10d.DebugLevel
Gets the debug level of the torch.distributed package.
is_available() -> bool
Return ``True`` if the distributed package is available.
Otherwise,
``torch.distributed`` does not expose any other APIs. Currently,
``torch.distributed`` is available on Linux, MacOS and Windows. Set
``USE_DISTRIBUTED=1`` to enable it when building PyTorch from source.
Currently, the default value is ``USE_DISTRIBUTED=1`` for Linux and Windows,
``USE_DISTRIBUTED=0`` for MacOS.
set_debug_level(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
set_debug_level(arg0: torch._C._distributed_c10d.DebugLevel) -> None
Sets the debug level of the torch.distributed package.
set_debug_level_from_env(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
set_debug_level_from_env() -> None
Sets the debug level of the torch.distributed package from the
``TORCH_DISTRIBUTED_DEBUG`` environment variable.
DATA
GroupName = torch.distributed.distributed_c10d.GroupName
RankType = int | torch.SymInt
__annotations__ = {'_breakpoint_cache': dict[int, typing.Any]}
default_pg_timeout = datetime.timedelta(seconds=1800)
log = <Logger torch.distributed (WARNING)>
reduce_op = <torch.distributed.distributed_c10d._reduce_op object>
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\distributed\__init__.py
torch.distributions
Python Library Documentation: package torch.distributions in torch
NAME
torch.distributions
DESCRIPTION
The ``distributions`` package contains parameterizable probability distributions
and sampling functions. This allows the construction of stochastic computation
graphs and stochastic gradient estimators for optimization. This package
generally follows the design of the `TensorFlow Distributions`_ package.
.. _`TensorFlow Distributions`:
https://arxiv.org/abs/1711.10604
It is not possible to directly backpropagate through random samples. However,
there are two main methods for creating surrogate functions that can be
backpropagated through. These are the score function estimator/likelihood ratio
estimator/REINFORCE and the pathwise derivative estimator. REINFORCE is commonly
seen as the basis for policy gradient methods in reinforcement learning, and the
pathwise derivative estimator is commonly seen in the reparameterization trick
in variational autoencoders. Whilst the score function only requires the value
of samples :math:`f(x)`, the pathwise derivative requires the derivative
:math:`f'(x)`. The next sections discuss these two in a reinforcement learning
example. For more details see
`Gradient Estimation Using Stochastic Computation Graphs`_ .
.. _`Gradient Estimation Using Stochastic Computation Graphs`:
https://arxiv.org/abs/1506.05254
Score function
^^^^^^^^^^^^^^
When the probability density function is differentiable with respect to its
parameters, we only need :meth:`~torch.distributions.Distribution.sample` and
:meth:`~torch.distributions.Distribution.log_prob` to implement REINFORCE:
.. math::
\Delta\theta = \alpha r \nabla_\theta \log \pi_\theta(a \mid s)
where :math:`\theta` are the parameters, :math:`\alpha` is the learning rate,
:math:`r` is the reward and :math:`\pi_\theta(a \mid s)` is the probability of
taking action :math:`a` in state :math:`s` given policy :math:`\pi_\theta`.
In practice we would sample an action from the output of a network, apply this
action in an environment, and then use ``log_prob`` to construct an equivalent
loss function. Note that we use a negative because optimizers use gradient
descent, whilst the rule above assumes gradient ascent. With a categorical
policy, the code for implementing REINFORCE would be as follows::
probs = policy_network(state)
# Note that this is equivalent to what used to be called multinomial
m = Categorical(probs)
action = m.sample()
next_state, reward = env.step(action)
loss = -m.log_prob(action) * reward
loss.backward()
Pathwise derivative
^^^^^^^^^^^^^^^^^^^
The other way to implement these stochastic/policy gradients would be to use the
reparameterization trick from the
:meth:`~torch.distributions.Distribution.rsample` method, where the
parameterized random variable can be constructed via a parameterized
deterministic function of a parameter-free random variable. The reparameterized
sample therefore becomes differentiable. The code for implementing the pathwise
derivative would be as follows::
params = policy_network(state)
m = Normal(*params)
# Any distribution with .has_rsample == True could work based on the application
action = m.rsample()
next_state, reward = env.step(action) # Assuming that reward is differentiable
loss = -reward
loss.backward()
PACKAGE CONTENTS
bernoulli
beta
binomial
categorical
cauchy
chi2
constraint_registry
constraints
continuous_bernoulli
dirichlet
distribution
exp_family
exponential
fishersnedecor
gamma
generalized_pareto
geometric
gumbel
half_cauchy
half_normal
independent
inverse_gamma
kl
kumaraswamy
laplace
lkj_cholesky
log_normal
logistic_normal
lowrank_multivariate_normal
mixture_same_family
multinomial
multivariate_normal
negative_binomial
normal
one_hot_categorical
pareto
poisson
relaxed_bernoulli
relaxed_categorical
studentT
transformed_distribution
transforms
uniform
utils
von_mises
weibull
wishart
CLASSES
builtins.object
torch.distributions.distribution.Distribution
torch.distributions.binomial.Binomial
torch.distributions.categorical.Categorical
torch.distributions.cauchy.Cauchy
torch.distributions.exp_family.ExponentialFamily
torch.distributions.bernoulli.Bernoulli
torch.distributions.beta.Beta
torch.distributions.continuous_bernoulli.ContinuousBernoulli
torch.distributions.dirichlet.Dirichlet
torch.distributions.exponential.Exponential
torch.distributions.gamma.Gamma
torch.distributions.chi2.Chi2
torch.distributions.normal.Normal
torch.distributions.poisson.Poisson
torch.distributions.wishart.Wishart
torch.distributions.fishersnedecor.FisherSnedecor
torch.distributions.generalized_pareto.GeneralizedPareto
torch.distributions.geometric.Geometric
torch.distributions.independent.Independent(torch.distributions.distribution.Distribution, typing.Generic)
torch.distributions.laplace.Laplace
torch.distributions.lkj_cholesky.LKJCholesky
torch.distributions.lowrank_multivariate_normal.LowRankMultivariateNormal
torch.distributions.mixture_same_family.MixtureSameFamily
torch.distributions.multinomial.Multinomial
torch.distributions.multivariate_normal.MultivariateNormal
torch.distributions.negative_binomial.NegativeBinomial
torch.distributions.one_hot_categorical.OneHotCategorical
torch.distributions.one_hot_categorical.OneHotCategoricalStraightThrough
torch.distributions.studentT.StudentT
torch.distributions.transformed_distribution.TransformedDistribution
torch.distributions.gumbel.Gumbel
torch.distributions.half_cauchy.HalfCauchy
torch.distributions.half_normal.HalfNormal
torch.distributions.inverse_gamma.InverseGamma
torch.distributions.kumaraswamy.Kumaraswamy
torch.distributions.log_normal.LogNormal
torch.distributions.logistic_normal.LogisticNormal
torch.distributions.pareto.Pareto
torch.distributions.relaxed_bernoulli.RelaxedBernoulli
torch.distributions.relaxed_categorical.RelaxedOneHotCategorical
torch.distributions.weibull.Weibull
torch.distributions.uniform.Uniform
torch.distributions.von_mises.VonMises
torch.distributions.transforms.Transform
torch.distributions.transforms.AbsTransform
torch.distributions.transforms.AffineTransform
torch.distributions.transforms.CatTransform
torch.distributions.transforms.ComposeTransform
torch.distributions.transforms.CorrCholeskyTransform
torch.distributions.transforms.CumulativeDistributionTransform
torch.distributions.transforms.ExpTransform
torch.distributions.transforms.IndependentTransform
torch.distributions.transforms.LowerCholeskyTransform
torch.distributions.transforms.PositiveDefiniteTransform
torch.distributions.transforms.PowerTransform
torch.distributions.transforms.ReshapeTransform
torch.distributions.transforms.SigmoidTransform
torch.distributions.transforms.SoftmaxTransform
torch.distributions.transforms.SoftplusTransform
torch.distributions.transforms.StackTransform
torch.distributions.transforms.StickBreakingTransform
torch.distributions.transforms.TanhTransform
class AbsTransform(Transform)
| AbsTransform(cache_size: int = 0) -> None
|
| Transform via the mapping :math:`y = |x|`.
|
| Method resolution order:
| AbsTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| codomain = GreaterThan(lower_bound=0.0)
|
| domain = Real()
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __getstate__(self)
| Helper for pickle.
|
| __init__(self, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| sign
| Returns the sign of the determinant of the Jacobian, if applicable.
| In general this only makes sense for bijective transforms.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Transform:
|
| bijective = False
class AffineTransform(Transform)
| AffineTransform(loc: torch.Tensor | float, scale: torch.Tensor | float, event_dim: int = 0, cache_size: int = 0) -> None
|
| Transform via the pointwise affine mapping :math:`y = \text{loc} + \text{scale} \times x`.
|
| Args:
| loc (Tensor or float): Location parameter.
| scale (Tensor or float): Scale parameter.
| event_dim (int): Optional size of `event_shape`. This should be zero
| for univariate random variables, 1 for distributions over vectors,
| 2 for distributions over matrices, etc.
|
| Method resolution order:
| AffineTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, loc: torch.Tensor | float, scale: torch.Tensor | float, event_dim: int = 0, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| codomain
|
| domain
|
| event_dim
|
| sign
| Returns the sign of the determinant of the Jacobian, if applicable.
| In general this only makes sense for bijective transforms.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| bijective = True
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __getstate__(self)
| Helper for pickle.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Bernoulli(torch.distributions.exp_family.ExponentialFamily)
| Bernoulli(probs: torch.Tensor | int | float | bool | None = None, logits: torch.Tensor | int | float | bool | None = None, validate_args: bool | None = None) -> None
|
| Creates a Bernoulli distribution parameterized by :attr:`probs`
| or :attr:`logits` (but not both).
|
| Samples are binary (0 or 1). They take the value `1` with probability `p`
| and `0` with probability `1 - p`.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Bernoulli(torch.tensor([0.3]))
| >>> m.sample() # 30% chance 1; 70% chance 0
| tensor([ 0.])
|
| Args:
| probs (Number, Tensor): the probability of sampling `1`
| logits (Number, Tensor): the log-odds of sampling `1`
| validate_args (bool, optional): whether to validate arguments, None by default
|
| Method resolution order:
| Bernoulli
| torch.distributions.exp_family.ExponentialFamily
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, probs: torch.Tensor | int | float | bool | None = None, logits: torch.Tensor | int | float | bool | None = None, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Method to compute the entropy using Bregman divergence of the log normalizer.
|
| enumerate_support(self, expand=True)
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| logits
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| param_shape
|
| probs
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'logits': Real(), 'probs': Interval(lower_bound=0.0...
|
| has_enumerate_support = True
|
| support = Boolean()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_rsample = False
class Beta(torch.distributions.exp_family.ExponentialFamily)
| Beta(concentration1: torch.Tensor | float, concentration0: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Beta distribution parameterized by :attr:`concentration1` and :attr:`concentration0`.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Beta(torch.tensor([0.5]), torch.tensor([0.5]))
| >>> m.sample() # Beta distributed with concentration concentration1 and concentration0
| tensor([ 0.1046])
|
| Args:
| concentration1 (float or Tensor): 1st concentration parameter of the distribution
| (often referred to as alpha)
| concentration0 (float or Tensor): 2nd concentration parameter of the distribution
| (often referred to as beta)
|
| Method resolution order:
| Beta
| torch.distributions.exp_family.ExponentialFamily
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, concentration1: torch.Tensor | float, concentration0: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Method to compute the entropy using Bregman divergence of the log normalizer.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = ()) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| concentration0
|
| concentration1
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'concentration0': GreaterThan(lower_bound=0.0), 'co...
|
| has_rsample = True
|
| support = Interval(lower_bound=0.0, upper_bound=1.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class Binomial(torch.distributions.distribution.Distribution)
| Binomial(total_count: torch.Tensor | int = 1, probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
|
| Creates a Binomial distribution parameterized by :attr:`total_count` and
| either :attr:`probs` or :attr:`logits` (but not both). :attr:`total_count` must be
| broadcastable with :attr:`probs`/:attr:`logits`.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Binomial(100, torch.tensor([0 , .2, .8, 1]))
| >>> x = m.sample()
| tensor([ 0., 22., 71., 100.])
|
| >>> m = Binomial(torch.tensor([[5.], [10.]]), torch.tensor([0.5, 0.8]))
| >>> x = m.sample()
| tensor([[ 4., 5.],
| [ 7., 6.]])
|
| Args:
| total_count (int or Tensor): number of Bernoulli trials
| probs (Tensor): Event probabilities
| logits (Tensor): Event log-odds
|
| Method resolution order:
| Binomial
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, total_count: torch.Tensor | int = 1, probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand=True)
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| logits
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| param_shape
|
| probs
|
| support
| Returns a :class:`~torch.distributions.constraints.Constraint` object
| representing this distribution's support.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'logits': Real(), 'probs': Interval(lower_bound=0.0...
|
| has_enumerate_support = True
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_rsample = False
class CatTransform(Transform)
| CatTransform(tseq: collections.abc.Sequence[torch.distributions.transforms.Transform], dim: int = 0, lengths: collections.abc.Sequence[int] | None = None, cache_size: int = 0) -> None
|
| Transform functor that applies a sequence of transforms `tseq`
| component-wise to each submatrix at `dim`, of length `lengths[dim]`,
| in a way compatible with :func:`torch.cat`.
|
| Example::
|
| x0 = torch.cat([torch.range(1, 10), torch.range(1, 10)], dim=0)
| x = torch.cat([x0, x0], dim=0)
| t0 = CatTransform([ExpTransform(), identity_transform], dim=0, lengths=[10, 10])
| t = CatTransform([t0, t0], dim=0, lengths=[20, 20])
| y = t(x)
|
| Method resolution order:
| CatTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __init__(self, tseq: collections.abc.Sequence[torch.distributions.transforms.Transform], dim: int = 0, lengths: collections.abc.Sequence[int] | None = None, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| bijective
|
| codomain
|
| domain
|
| event_dim
|
| length
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'transforms': list[torch.distributions.transforms.T...
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __eq__(self, other)
| Return self==value.
|
| __getstate__(self)
| Helper for pickle.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| sign
| Returns the sign of the determinant of the Jacobian, if applicable.
| In general this only makes sense for bijective transforms.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Transform:
|
| __hash__ = None
class Categorical(torch.distributions.distribution.Distribution)
| Categorical(probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
|
| Creates a categorical distribution parameterized by either :attr:`probs` or
| :attr:`logits` (but not both).
|
| .. note::
| It is equivalent to the distribution that :func:`torch.multinomial`
| samples from.
|
| Samples are integers from :math:`\{0, \ldots, K-1\}` where `K` is ``probs.size(-1)``.
|
| If `probs` is 1-dimensional with length-`K`, each element is the relative probability
| of sampling the class at that index.
|
| If `probs` is N-dimensional, the first N-1 dimensions are treated as a batch of
| relative probability vectors.
|
| .. note:: The `probs` argument must be non-negative, finite and have a non-zero sum,
| and it will be normalized to sum to 1 along the last dimension. :attr:`probs`
| will return this normalized value.
| The `logits` argument will be interpreted as unnormalized log probabilities
| and can therefore be any real number. It will likewise be normalized so that
| the resulting probabilities sum to 1 along the last dimension. :attr:`logits`
| will return this normalized value.
|
| See also: :func:`torch.multinomial`
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Categorical(torch.tensor([ 0.25, 0.25, 0.25, 0.25 ]))
| >>> m.sample() # equal probability of 0, 1, 2, 3
| tensor(3)
|
| Args:
| probs (Tensor): event probabilities
| logits (Tensor): event log probabilities (unnormalized)
|
| Method resolution order:
| Categorical
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand=True)
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| logits
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| param_shape
|
| probs
|
| support
| Returns a :class:`~torch.distributions.constraints.Constraint` object
| representing this distribution's support.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'logits': IndependentConstraint(Real(), 1), 'probs'...
|
| has_enumerate_support = True
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_rsample = False
class Cauchy(torch.distributions.distribution.Distribution)
| Cauchy(loc: torch.Tensor | float, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Samples from a Cauchy (Lorentz) distribution. The distribution of the ratio of
| independent normally distributed random variables with means `0` follows a
| Cauchy distribution.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Cauchy(torch.tensor([0.0]), torch.tensor([1.0]))
| >>> m.sample() # sample from a Cauchy distribution with loc=0 and scale=1
| tensor([ 2.3214])
|
| Args:
| loc (float or Tensor): mode or median of the distribution.
| scale (float or Tensor): half width at half maximum.
|
| Method resolution order:
| Cauchy
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, loc: torch.Tensor | float, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| cdf(self, value)
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| icdf(self, value)
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'loc': Real(), 'scale': GreaterThan(lower_bound=0.0...
|
| has_rsample = True
|
| support = Real()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class Chi2(torch.distributions.gamma.Gamma)
| Chi2(df: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Creates a Chi-squared distribution parameterized by shape parameter :attr:`df`.
| This is exactly equivalent to ``Gamma(alpha=0.5*df, beta=0.5)``
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Chi2(torch.tensor([1.0]))
| >>> m.sample() # Chi2 distributed with shape df=1
| tensor([ 0.1046])
|
| Args:
| df (float or Tensor): shape parameter of the distribution
|
| Method resolution order:
| Chi2
| torch.distributions.gamma.Gamma
| torch.distributions.exp_family.ExponentialFamily
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, df: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| df
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'df': GreaterThan(lower_bound=0.0)}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.gamma.Gamma:
|
| cdf(self, value)
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self)
| Method to compute the entropy using Bregman divergence of the log normalizer.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.gamma.Gamma:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.gamma.Gamma:
|
| has_rsample = True
|
| support = GreaterThanEq(lower_bound=0.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class ComposeTransform(Transform)
| ComposeTransform(parts: list[torch.distributions.transforms.Transform], cache_size: int = 0) -> None
|
| Composes multiple transforms in a chain.
| The transforms being composed are responsible for caching.
|
| Args:
| parts (list of :class:`Transform`): A list of transforms to compose.
| cache_size (int): Size of cache. If zero, no caching is done. If one,
| the latest single value is cached. Only 0 and 1 are supported.
|
| Method resolution order:
| ComposeTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, parts: list[torch.distributions.transforms.Transform], cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| bijective
|
| codomain
|
| domain
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| sign
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __getstate__(self)
| Helper for pickle.
|
| __ne__(self, other)
| Return self!=value.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class ContinuousBernoulli(torch.distributions.exp_family.ExponentialFamily)
| ContinuousBernoulli(probs: torch.Tensor | int | float | bool | None = None, logits: torch.Tensor | int | float | bool | None = None, lims: tuple[float, float] = (0.499, 0.501), validate_args: bool | None = None) -> None
|
| Creates a continuous Bernoulli distribution parameterized by :attr:`probs`
| or :attr:`logits` (but not both).
|
| The distribution is supported in [0, 1] and parameterized by 'probs' (in
| (0,1)) or 'logits' (real-valued). Note that, unlike the Bernoulli, 'probs'
| does not correspond to a probability and 'logits' does not correspond to
| log-odds, but the same names are used due to the similarity with the
| Bernoulli. See [1] for more details.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = ContinuousBernoulli(torch.tensor([0.3]))
| >>> m.sample()
| tensor([ 0.2538])
|
| Args:
| probs (Number, Tensor): (0,1) valued parameters
| logits (Number, Tensor): real valued parameters whose sigmoid matches 'probs'
|
| [1] The continuous Bernoulli: fixing a pervasive error in variational
| autoencoders, Loaiza-Ganem G and Cunningham JP, NeurIPS 2019.
| https://arxiv.org/abs/1907.06845
|
| Method resolution order:
| ContinuousBernoulli
| torch.distributions.exp_family.ExponentialFamily
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, probs: torch.Tensor | int | float | bool | None = None, logits: torch.Tensor | int | float | bool | None = None, lims: tuple[float, float] = (0.499, 0.501), validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| cdf(self, value)
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self)
| Method to compute the entropy using Bregman divergence of the log normalizer.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| icdf(self, value)
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| logits
|
| mean
| Returns the mean of the distribution.
|
| param_shape
|
| probs
|
| stddev
| Returns the standard deviation of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'logits': Real(), 'probs': Interval(lower_bound=0.0...
|
| has_rsample = True
|
| support = Interval(lower_bound=0.0, upper_bound=1.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| mode
| Returns the mode of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class CorrCholeskyTransform(Transform)
| CorrCholeskyTransform(cache_size: int = 0) -> None
|
| Transforms an unconstrained real vector :math:`x` with length :math:`D*(D-1)/2` into the
| Cholesky factor of a D-dimension correlation matrix. This Cholesky factor is a lower
| triangular matrix with positive diagonals and unit Euclidean norm for each row.
| The transform is processed as follows:
|
| 1. First we convert x into a lower triangular matrix in row order.
| 2. For each row :math:`X_i` of the lower triangular part, we apply a *signed* version of
| class :class:`StickBreakingTransform` to transform :math:`X_i` into a
| unit Euclidean length vector using the following steps:
| - Scales into the interval :math:`(-1, 1)` domain: :math:`r_i = \tanh(X_i)`.
| - Transforms into an unsigned domain: :math:`z_i = r_i^2`.
| - Applies :math:`s_i = StickBreakingTransform(z_i)`.
| - Transforms back into signed domain: :math:`y_i = sign(r_i) * \sqrt{s_i}`.
|
| Method resolution order:
| CorrCholeskyTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| log_abs_det_jacobian(self, x, y, intermediates=None)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| bijective = True
|
| codomain = CorrCholesky()
|
| domain = IndependentConstraint(Real(), 1)
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __eq__(self, other)
| Return self==value.
|
| __getstate__(self)
| Helper for pickle.
|
| __init__(self, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| sign
| Returns the sign of the determinant of the Jacobian, if applicable.
| In general this only makes sense for bijective transforms.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Transform:
|
| __hash__ = None
class CumulativeDistributionTransform(Transform)
| CumulativeDistributionTransform(distribution: torch.distributions.distribution.Distribution, cache_size: int = 0) -> None
|
| Transform via the cumulative distribution function of a probability distribution.
|
| Args:
| distribution (Distribution): Distribution whose cumulative distribution function to use for
| the transformation.
|
| Example::
|
| # Construct a Gaussian copula from a multivariate normal.
| base_dist = MultivariateNormal(
| loc=torch.zeros(2),
| scale_tril=LKJCholesky(2).sample(),
| )
| transform = CumulativeDistributionTransform(Normal(0, 1))
| copula = TransformedDistribution(base_dist, [transform])
|
| Method resolution order:
| CumulativeDistributionTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __init__(self, distribution: torch.distributions.distribution.Distribution, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| domain
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| bijective = True
|
| codomain = Interval(lower_bound=0.0, upper_bound=1.0)
|
| sign = 1
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __eq__(self, other)
| Return self==value.
|
| __getstate__(self)
| Helper for pickle.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Transform:
|
| __hash__ = None
class Dirichlet(torch.distributions.exp_family.ExponentialFamily)
| Dirichlet(concentration: torch.Tensor, validate_args: bool | None = None) -> None
|
| Creates a Dirichlet distribution parameterized by concentration :attr:`concentration`.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Dirichlet(torch.tensor([0.5, 0.5]))
| >>> m.sample() # Dirichlet distributed with concentration [0.5, 0.5]
| tensor([ 0.1046, 0.8954])
|
| Args:
| concentration (Tensor): concentration parameter of the distribution
| (often referred to as alpha)
|
| Method resolution order:
| Dirichlet
| torch.distributions.exp_family.ExponentialFamily
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, concentration: torch.Tensor, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Method to compute the entropy using Bregman divergence of the log normalizer.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = ()) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'concentration': IndependentConstraint(GreaterThan(...
|
| has_rsample = True
|
| support = Simplex()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class Distribution(builtins.object)
| Distribution(batch_shape: torch.Size = torch.Size([]), event_shape: torch.Size = torch.Size([]), validate_args: bool | None = None) -> None
|
| Distribution is the abstract base class for probability distributions.
|
| Args:
| batch_shape (torch.Size): The shape over which parameters are batched.
| event_shape (torch.Size): The shape of a single sample (without batching).
| validate_args (bool, optional): Whether to validate arguments. Default: None.
|
| Methods defined here:
|
| __init__(self, batch_shape: torch.Size = torch.Size([]), event_shape: torch.Size = torch.Size([]), validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self) -> torch.Tensor
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| expand(self, batch_shape: torch.Size | list[int] | tuple[int, ...], _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| log_prob(self, value: torch.Tensor) -> torch.Tensor
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| arg_constraints
| Returns a dictionary from argument names to
| :class:`~torch.distributions.constraints.Constraint` objects that
| should be satisfied by each argument of this distribution. Args that
| are not tensors need not appear in this dict.
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| support
| Returns a :class:`~torch.distributions.constraints.Constraint` object
| representing this distribution's support.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| has_enumerate_support = False
|
| has_rsample = False
class ExpTransform(Transform)
| ExpTransform(cache_size: int = 0) -> None
|
| Transform via the mapping :math:`y = \exp(x)`.
|
| Method resolution order:
| ExpTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| bijective = True
|
| codomain = GreaterThan(lower_bound=0.0)
|
| domain = Real()
|
| sign = 1
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __getstate__(self)
| Helper for pickle.
|
| __init__(self, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Exponential(torch.distributions.exp_family.ExponentialFamily)
| Exponential(rate: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Creates a Exponential distribution parameterized by :attr:`rate`.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Exponential(torch.tensor([1.0]))
| >>> m.sample() # Exponential distributed with rate=1
| tensor([ 0.1046])
|
| Args:
| rate (float or Tensor): rate = 1 / scale of the distribution
|
| Method resolution order:
| Exponential
| torch.distributions.exp_family.ExponentialFamily
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, rate: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| cdf(self, value)
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self)
| Method to compute the entropy using Bregman divergence of the log normalizer.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| icdf(self, value)
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'rate': GreaterThan(lower_bound=0.0)}
|
| has_rsample = True
|
| support = GreaterThanEq(lower_bound=0.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class ExponentialFamily(torch.distributions.distribution.Distribution)
| ExponentialFamily(batch_shape: torch.Size = torch.Size([]), event_shape: torch.Size = torch.Size([]), validate_args: bool | None = None) -> None
|
| ExponentialFamily is the abstract base class for probability distributions belonging to an
| exponential family, whose probability mass/density function has the form is defined below
|
| .. math::
|
| p_{F}(x; \theta) = \exp(\langle t(x), \theta\rangle - F(\theta) + k(x))
|
| where :math:`\theta` denotes the natural parameters, :math:`t(x)` denotes the sufficient statistic,
| :math:`F(\theta)` is the log normalizer function for a given family and :math:`k(x)` is the carrier
| measure.
|
| Note:
| This class is an intermediary between the `Distribution` class and distributions which belong
| to an exponential family mainly to check the correctness of the `.entropy()` and analytic KL
| divergence methods. We use this class to compute the entropy and KL divergence using the AD
| framework and Bregman divergences (courtesy of: Frank Nielsen and Richard Nock, Entropies and
| Cross-entropies of Exponential Families).
|
| Method resolution order:
| ExponentialFamily
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| entropy(self)
| Method to compute the entropy using Bregman divergence of the log normalizer.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __init__(self, batch_shape: torch.Size = torch.Size([]), event_shape: torch.Size = torch.Size([]), validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| expand(self, batch_shape: torch.Size | list[int] | tuple[int, ...], _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| log_prob(self, value: torch.Tensor) -> torch.Tensor
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| arg_constraints
| Returns a dictionary from argument names to
| :class:`~torch.distributions.constraints.Constraint` objects that
| should be satisfied by each argument of this distribution. Args that
| are not tensors need not appear in this dict.
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| support
| Returns a :class:`~torch.distributions.constraints.Constraint` object
| representing this distribution's support.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
|
| has_rsample = False
class FisherSnedecor(torch.distributions.distribution.Distribution)
| FisherSnedecor(df1: torch.Tensor | float, df2: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Creates a Fisher-Snedecor distribution parameterized by :attr:`df1` and :attr:`df2`.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = FisherSnedecor(torch.tensor([1.0]), torch.tensor([2.0]))
| >>> m.sample() # Fisher-Snedecor-distributed with df1=1 and df2=2
| tensor([ 0.2453])
|
| Args:
| df1 (float or Tensor): degrees of freedom parameter 1
| df2 (float or Tensor): degrees of freedom parameter 2
|
| Method resolution order:
| FisherSnedecor
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, df1: torch.Tensor | float, df2: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'df1': GreaterThan(lower_bound=0.0), 'df2': Greater...
|
| has_rsample = True
|
| support = GreaterThan(lower_bound=0.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self) -> torch.Tensor
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class Gamma(torch.distributions.exp_family.ExponentialFamily)
| Gamma(concentration: torch.Tensor | float, rate: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Creates a Gamma distribution parameterized by shape :attr:`concentration` and :attr:`rate`.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Gamma(torch.tensor([1.0]), torch.tensor([1.0]))
| >>> m.sample() # Gamma distributed with concentration=1 and rate=1
| tensor([ 0.1046])
|
| Args:
| concentration (float or Tensor): shape parameter of the distribution
| (often referred to as alpha)
| rate (float or Tensor): rate parameter of the distribution
| (often referred to as beta), rate = 1 / scale
|
| Method resolution order:
| Gamma
| torch.distributions.exp_family.ExponentialFamily
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, concentration: torch.Tensor | float, rate: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| cdf(self, value)
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self)
| Method to compute the entropy using Bregman divergence of the log normalizer.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'concentration': GreaterThan(lower_bound=0.0), 'rat...
|
| has_rsample = True
|
| support = GreaterThanEq(lower_bound=0.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class GeneralizedPareto(torch.distributions.distribution.Distribution)
| GeneralizedPareto(loc, scale, concentration, validate_args=None)
|
| Creates a Generalized Pareto distribution parameterized by :attr:`loc`, :attr:`scale`, and :attr:`concentration`.
|
| The Generalized Pareto distribution is a family of continuous probability distributions on the real line.
| Special cases include Exponential (when :attr:`loc` = 0, :attr:`concentration` = 0), Pareto (when :attr:`concentration` > 0,
| :attr:`loc` = :attr:`scale` / :attr:`concentration`), and Uniform (when :attr:`concentration` = -1).
|
| This distribution is often used to model the tails of other distributions. This implementation is based on the
| implementation in TensorFlow Probability.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = GeneralizedPareto(torch.tensor([0.1]), torch.tensor([2.0]), torch.tensor([0.4]))
| >>> m.sample() # sample from a Generalized Pareto distribution with loc=0.1, scale=2.0, and concentration=0.4
| tensor([ 1.5623])
|
| Args:
| loc (float or Tensor): Location parameter of the distribution
| scale (float or Tensor): Scale parameter of the distribution
| concentration (float or Tensor): Concentration parameter of the distribution
|
| Method resolution order:
| GeneralizedPareto
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, loc, scale, concentration, validate_args=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| cdf(self, value)
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| icdf(self, value)
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| log_cdf(self, value)
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| log_survival_function(self, value)
|
| rsample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| support
| Returns a :class:`~torch.distributions.constraints.Constraint` object
| representing this distribution's support.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'concentration': Real(), 'loc': Real(), 'scale': Gr...
|
| has_rsample = True
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class Geometric(torch.distributions.distribution.Distribution)
| Geometric(probs: torch.Tensor | int | float | bool | None = None, logits: torch.Tensor | int | float | bool | None = None, validate_args: bool | None = None) -> None
|
| Creates a Geometric distribution parameterized by :attr:`probs`,
| where :attr:`probs` is the probability of success of Bernoulli trials.
|
| .. math::
|
| P(X=k) = (1-p)^{k} p, k = 0, 1, ...
|
| .. note::
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`, whereas
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Geometric(torch.tensor([0.3]))
| >>> m.sample() # underlying Bernoulli has 30% chance 1; 70% chance 0
| tensor([ 2.])
|
| Args:
| probs (Number, Tensor): the probability of sampling `1`. Must be in range (0, 1]
| logits (Number, Tensor): the log-odds of sampling `1`.
|
| Method resolution order:
| Geometric
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, probs: torch.Tensor | int | float | bool | None = None, logits: torch.Tensor | int | float | bool | None = None, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| logits
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| probs
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| arg_constraints = {'logits': Real(), 'probs': Interval(lower_bound=0.0...
|
| support = IntegerGreaterThan(lower_bound=0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
|
| has_rsample = False
class Gumbel(torch.distributions.transformed_distribution.TransformedDistribution)
| Gumbel(loc: torch.Tensor | float, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Samples from a Gumbel Distribution.
|
| Examples::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Gumbel(torch.tensor([1.0]), torch.tensor([2.0]))
| >>> m.sample() # sample from Gumbel distribution with loc=1, scale=2
| tensor([ 1.0124])
|
| Args:
| loc (float or Tensor): Location parameter of the distribution
| scale (float or Tensor): Scale parameter of the distribution
|
| Method resolution order:
| Gumbel
| torch.distributions.transformed_distribution.TransformedDistribution
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, loc: torch.Tensor | float, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Scores the sample by inverting the transform(s) and computing the score
| using the score of the base distribution and the log abs det jacobian.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'loc': Real(), 'scale': GreaterThan(lower_bound=0.0...
|
| support = Real()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| cdf(self, value)
| Computes the cumulative distribution function by inverting the
| transform(s) and computing the score of the base distribution.
|
| icdf(self, value)
| Computes the inverse cumulative distribution function using
| transform(s) and computing the score of the base distribution.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched. Samples first from base distribution and applies
| `transform()` for every transform in the list.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched. Samples first from
| base distribution and applies `transform()` for every transform in the
| list.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| has_rsample
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class HalfCauchy(torch.distributions.transformed_distribution.TransformedDistribution)
| HalfCauchy(scale: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Creates a half-Cauchy distribution parameterized by `scale` where::
|
| X ~ Cauchy(0, scale)
| Y = |X| ~ HalfCauchy(scale)
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = HalfCauchy(torch.tensor([1.0]))
| >>> m.sample() # half-cauchy distributed with scale=1
| tensor([ 2.3214])
|
| Args:
| scale (float or Tensor): scale of the full Cauchy distribution
|
| Method resolution order:
| HalfCauchy
| torch.distributions.transformed_distribution.TransformedDistribution
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| cdf(self, value)
| Computes the cumulative distribution function by inverting the
| transform(s) and computing the score of the base distribution.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| icdf(self, prob)
| Computes the inverse cumulative distribution function using
| transform(s) and computing the score of the base distribution.
|
| log_prob(self, value)
| Scores the sample by inverting the transform(s) and computing the score
| using the score of the base distribution and the log abs det jacobian.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| scale
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'base_dist': <class 'torch.distributions.cauchy.Cau...
|
| arg_constraints = {'scale': GreaterThan(lower_bound=0.0)}
|
| has_rsample = True
|
| support = GreaterThanEq(lower_bound=0.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched. Samples first from base distribution and applies
| `transform()` for every transform in the list.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched. Samples first from
| base distribution and applies `transform()` for every transform in the
| list.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class HalfNormal(torch.distributions.transformed_distribution.TransformedDistribution)
| HalfNormal(scale: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Creates a half-normal distribution parameterized by `scale` where::
|
| X ~ Normal(0, scale)
| Y = |X| ~ HalfNormal(scale)
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = HalfNormal(torch.tensor([1.0]))
| >>> m.sample() # half-normal distributed with scale=1
| tensor([ 0.1046])
|
| Args:
| scale (float or Tensor): scale of the full Normal distribution
|
| Method resolution order:
| HalfNormal
| torch.distributions.transformed_distribution.TransformedDistribution
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| cdf(self, value)
| Computes the cumulative distribution function by inverting the
| transform(s) and computing the score of the base distribution.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| icdf(self, prob)
| Computes the inverse cumulative distribution function using
| transform(s) and computing the score of the base distribution.
|
| log_prob(self, value)
| Scores the sample by inverting the transform(s) and computing the score
| using the score of the base distribution and the log abs det jacobian.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| scale
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'base_dist': <class 'torch.distributions.normal.Nor...
|
| arg_constraints = {'scale': GreaterThan(lower_bound=0.0)}
|
| has_rsample = True
|
| support = GreaterThanEq(lower_bound=0.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched. Samples first from base distribution and applies
| `transform()` for every transform in the list.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched. Samples first from
| base distribution and applies `transform()` for every transform in the
| list.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class Independent(torch.distributions.distribution.Distribution, typing.Generic)
| Independent(base_distribution: ~D, reinterpreted_batch_ndims: int, validate_args: bool | None = None) -> None
|
| Reinterprets some of the batch dims of a distribution as event dims.
|
| This is mainly useful for changing the shape of the result of
| :meth:`log_prob`. For example to create a diagonal Normal distribution with
| the same shape as a Multivariate Normal distribution (so they are
| interchangeable), you can::
|
| >>> from torch.distributions.multivariate_normal import MultivariateNormal
| >>> from torch.distributions.normal import Normal
| >>> loc = torch.zeros(3)
| >>> scale = torch.ones(3)
| >>> mvn = MultivariateNormal(loc, scale_tril=torch.diag(scale))
| >>> [mvn.batch_shape, mvn.event_shape]
| [torch.Size([]), torch.Size([3])]
| >>> normal = Normal(loc, scale)
| >>> [normal.batch_shape, normal.event_shape]
| [torch.Size([3]), torch.Size([])]
| >>> diagn = Independent(normal, 1)
| >>> [diagn.batch_shape, diagn.event_shape]
| [torch.Size([]), torch.Size([3])]
|
| Args:
| base_distribution (torch.distributions.distribution.Distribution): a
| base distribution
| reinterpreted_batch_ndims (int): the number of batch dims to
| reinterpret as event dims
|
| Method resolution order:
| Independent
| torch.distributions.distribution.Distribution
| typing.Generic
| builtins.object
|
| Methods defined here:
|
| __init__(self, base_distribution: ~D, reinterpreted_batch_ndims: int, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand=True)
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample(self, sample_shape=torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| has_enumerate_support
|
| has_rsample
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| support
| Returns a :class:`~torch.distributions.constraints.Constraint` object
| representing this distribution's support.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'arg_constraints': dict[str, torch.distributions.co...
|
| __orig_bases__ = (<class 'torch.distributions.distribution.Distributio...
|
| __parameters__ = (~D,)
|
| arg_constraints = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Class methods inherited from typing.Generic:
|
| __class_getitem__(...)
| Parameterizes a generic class.
|
| At least, parameterizing a generic class is the *main* thing this
| method does. For example, for some generic class `Foo`, this is called
| when we do `Foo[int]` - there, with `cls=Foo` and `params=int`.
|
| However, note that this method is also called when defining generic
| classes in the first place with `class Foo[T]: ...`.
|
| __init_subclass__(...)
| Function to initialize subclasses.
class IndependentTransform(Transform)
| IndependentTransform(base_transform: torch.distributions.transforms.Transform, reinterpreted_batch_ndims: int, cache_size: int = 0) -> None
|
| Wrapper around another transform to treat
| ``reinterpreted_batch_ndims``-many extra of the right most dimensions as
| dependent. This has no effect on the forward or backward transforms, but
| does sum out ``reinterpreted_batch_ndims``-many of the rightmost dimensions
| in :meth:`log_abs_det_jacobian`.
|
| Args:
| base_transform (:class:`Transform`): A base transform.
| reinterpreted_batch_ndims (int): The number of extra rightmost
| dimensions to treat as dependent.
|
| Method resolution order:
| IndependentTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __init__(self, base_transform: torch.distributions.transforms.Transform, reinterpreted_batch_ndims: int, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| bijective
|
| codomain
|
| domain
|
| sign
| Returns the sign of the determinant of the Jacobian, if applicable.
| In general this only makes sense for bijective transforms.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __eq__(self, other)
| Return self==value.
|
| __getstate__(self)
| Helper for pickle.
|
| __ne__(self, other)
| Return self!=value.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Transform:
|
| __hash__ = None
class InverseGamma(torch.distributions.transformed_distribution.TransformedDistribution)
| InverseGamma(concentration: torch.Tensor | float, rate: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Creates an inverse gamma distribution parameterized by :attr:`concentration` and :attr:`rate`
| where::
|
| X ~ Gamma(concentration, rate)
| Y = 1 / X ~ InverseGamma(concentration, rate)
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterinistic")
| >>> m = InverseGamma(torch.tensor([2.0]), torch.tensor([3.0]))
| >>> m.sample()
| tensor([ 1.2953])
|
| Args:
| concentration (float or Tensor): shape parameter of the distribution
| (often referred to as alpha)
| rate (float or Tensor): rate = 1 / scale of the distribution
| (often referred to as beta)
|
| Method resolution order:
| InverseGamma
| torch.distributions.transformed_distribution.TransformedDistribution
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, concentration: torch.Tensor | float, rate: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| concentration
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| rate
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'base_dist': <class 'torch.distributions.gamma.Gamm...
|
| arg_constraints = {'concentration': GreaterThan(lower_bound=0.0), 'rat...
|
| has_rsample = True
|
| support = GreaterThan(lower_bound=0.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| cdf(self, value)
| Computes the cumulative distribution function by inverting the
| transform(s) and computing the score of the base distribution.
|
| icdf(self, value)
| Computes the inverse cumulative distribution function using
| transform(s) and computing the score of the base distribution.
|
| log_prob(self, value)
| Scores the sample by inverting the transform(s) and computing the score
| using the score of the base distribution and the log abs det jacobian.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched. Samples first from base distribution and applies
| `transform()` for every transform in the list.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched. Samples first from
| base distribution and applies `transform()` for every transform in the
| list.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class Kumaraswamy(torch.distributions.transformed_distribution.TransformedDistribution)
| Kumaraswamy(concentration1: torch.Tensor | float, concentration0: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Samples from a Kumaraswamy distribution.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Kumaraswamy(torch.tensor([1.0]), torch.tensor([1.0]))
| >>> m.sample() # sample from a Kumaraswamy distribution with concentration alpha=1 and beta=1
| tensor([ 0.1729])
|
| Args:
| concentration1 (float or Tensor): 1st concentration parameter of the distribution
| (often referred to as alpha)
| concentration0 (float or Tensor): 2nd concentration parameter of the distribution
| (often referred to as beta)
|
| Method resolution order:
| Kumaraswamy
| torch.distributions.transformed_distribution.TransformedDistribution
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, concentration1: torch.Tensor | float, concentration0: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'concentration0': GreaterThan(lower_bound=0.0), 'co...
|
| has_rsample = True
|
| support = Interval(lower_bound=0.0, upper_bound=1.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| cdf(self, value)
| Computes the cumulative distribution function by inverting the
| transform(s) and computing the score of the base distribution.
|
| icdf(self, value)
| Computes the inverse cumulative distribution function using
| transform(s) and computing the score of the base distribution.
|
| log_prob(self, value)
| Scores the sample by inverting the transform(s) and computing the score
| using the score of the base distribution and the log abs det jacobian.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched. Samples first from base distribution and applies
| `transform()` for every transform in the list.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched. Samples first from
| base distribution and applies `transform()` for every transform in the
| list.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class LKJCholesky(torch.distributions.distribution.Distribution)
| LKJCholesky(dim: int, concentration: torch.Tensor | float = 1.0, validate_args: bool | None = None) -> None
|
| LKJ distribution for lower Cholesky factor of correlation matrices.
| The distribution is controlled by ``concentration`` parameter :math:`\eta`
| to make the probability of the correlation matrix :math:`M` generated from
| a Cholesky factor proportional to :math:`\det(M)^{\eta - 1}`. Because of that,
| when ``concentration == 1``, we have a uniform distribution over Cholesky
| factors of correlation matrices::
|
| L ~ LKJCholesky(dim, concentration)
| X = L @ L' ~ LKJCorr(dim, concentration)
|
| Note that this distribution samples the
| Cholesky factor of correlation matrices and not the correlation matrices
| themselves and thereby differs slightly from the derivations in [1] for
| the `LKJCorr` distribution. For sampling, this uses the Onion method from
| [1] Section 3.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> l = LKJCholesky(3, 0.5)
| >>> l.sample() # l @ l.T is a sample of a correlation 3x3 matrix
| tensor([[ 1.0000, 0.0000, 0.0000],
| [ 0.3516, 0.9361, 0.0000],
| [-0.1899, 0.4748, 0.8593]])
|
| Args:
| dimension (dim): dimension of the matrices
| concentration (float or Tensor): concentration/shape parameter of the
| distribution (often referred to as eta)
|
| **References**
|
| [1] `Generating random correlation matrices based on vines and extended onion method` (2009),
| Daniel Lewandowski, Dorota Kurowicka, Harry Joe.
| Journal of Multivariate Analysis. 100. 10.1016/j.jmva.2009.04.008
|
| Method resolution order:
| LKJCholesky
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, dim: int, concentration: torch.Tensor | float = 1.0, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'concentration': GreaterThan(lower_bound=0.0)}
|
| support = CorrCholesky()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self) -> torch.Tensor
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
|
| has_rsample = False
class Laplace(torch.distributions.distribution.Distribution)
| Laplace(loc: torch.Tensor | float, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Creates a Laplace distribution parameterized by :attr:`loc` and :attr:`scale`.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Laplace(torch.tensor([0.0]), torch.tensor([1.0]))
| >>> m.sample() # Laplace distributed with loc=0, scale=1
| tensor([ 0.1046])
|
| Args:
| loc (float or Tensor): mean of the distribution
| scale (float or Tensor): scale of the distribution
|
| Method resolution order:
| Laplace
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, loc: torch.Tensor | float, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| cdf(self, value)
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| icdf(self, value)
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'loc': Real(), 'scale': GreaterThan(lower_bound=0.0...
|
| has_rsample = True
|
| support = Real()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class LogNormal(torch.distributions.transformed_distribution.TransformedDistribution)
| LogNormal(loc: torch.Tensor | float, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Creates a log-normal distribution parameterized by
| :attr:`loc` and :attr:`scale` where::
|
| X ~ Normal(loc, scale)
| Y = exp(X) ~ LogNormal(loc, scale)
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = LogNormal(torch.tensor([0.0]), torch.tensor([1.0]))
| >>> m.sample() # log-normal distributed with mean=0 and stddev=1
| tensor([ 0.1046])
|
| Args:
| loc (float or Tensor): mean of log of distribution
| scale (float or Tensor): standard deviation of log of the distribution
|
| Method resolution order:
| LogNormal
| torch.distributions.transformed_distribution.TransformedDistribution
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, loc: torch.Tensor | float, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| loc
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| scale
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'base_dist': <class 'torch.distributions.normal.Nor...
|
| arg_constraints = {'loc': Real(), 'scale': GreaterThan(lower_bound=0.0...
|
| has_rsample = True
|
| support = GreaterThan(lower_bound=0.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| cdf(self, value)
| Computes the cumulative distribution function by inverting the
| transform(s) and computing the score of the base distribution.
|
| icdf(self, value)
| Computes the inverse cumulative distribution function using
| transform(s) and computing the score of the base distribution.
|
| log_prob(self, value)
| Scores the sample by inverting the transform(s) and computing the score
| using the score of the base distribution and the log abs det jacobian.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched. Samples first from base distribution and applies
| `transform()` for every transform in the list.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched. Samples first from
| base distribution and applies `transform()` for every transform in the
| list.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class LogisticNormal(torch.distributions.transformed_distribution.TransformedDistribution)
| LogisticNormal(loc: torch.Tensor | float, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Creates a logistic-normal distribution parameterized by :attr:`loc` and :attr:`scale`
| that define the base `Normal` distribution transformed with the
| `StickBreakingTransform` such that::
|
| X ~ LogisticNormal(loc, scale)
| Y = log(X / (1 - X.cumsum(-1)))[..., :-1] ~ Normal(loc, scale)
|
| Args:
| loc (float or Tensor): mean of the base distribution
| scale (float or Tensor): standard deviation of the base distribution
|
| Example::
|
| >>> # logistic-normal distributed with mean=(0, 0, 0) and stddev=(1, 1, 1)
| >>> # of the base Normal distribution
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = LogisticNormal(torch.tensor([0.0] * 3), torch.tensor([1.0] * 3))
| >>> m.sample()
| tensor([ 0.7653, 0.0341, 0.0579, 0.1427])
|
| Method resolution order:
| LogisticNormal
| torch.distributions.transformed_distribution.TransformedDistribution
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, loc: torch.Tensor | float, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| loc
|
| scale
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'base_dist': torch.distributions.independent.Indepe...
|
| arg_constraints = {'loc': Real(), 'scale': GreaterThan(lower_bound=0.0...
|
| has_rsample = True
|
| support = Simplex()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| cdf(self, value)
| Computes the cumulative distribution function by inverting the
| transform(s) and computing the score of the base distribution.
|
| icdf(self, value)
| Computes the inverse cumulative distribution function using
| transform(s) and computing the score of the base distribution.
|
| log_prob(self, value)
| Scores the sample by inverting the transform(s) and computing the score
| using the score of the base distribution and the log abs det jacobian.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched. Samples first from base distribution and applies
| `transform()` for every transform in the list.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched. Samples first from
| base distribution and applies `transform()` for every transform in the
| list.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| entropy(self) -> torch.Tensor
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class LowRankMultivariateNormal(torch.distributions.distribution.Distribution)
| LowRankMultivariateNormal(loc: torch.Tensor, cov_factor: torch.Tensor, cov_diag: torch.Tensor, validate_args: bool | None = None) -> None
|
| Creates a multivariate normal distribution with covariance matrix having a low-rank form
| parameterized by :attr:`cov_factor` and :attr:`cov_diag`::
|
| covariance_matrix = cov_factor @ cov_factor.T + cov_diag
|
| Example:
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_LAPACK)
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = LowRankMultivariateNormal(
| ... torch.zeros(2), torch.tensor([[1.0], [0.0]]), torch.ones(2)
| ... )
| >>> m.sample() # normally distributed with mean=`[0,0]`, cov_factor=`[[1],[0]]`, cov_diag=`[1,1]`
| tensor([-0.2102, -0.5429])
|
| Args:
| loc (Tensor): mean of the distribution with shape `batch_shape + event_shape`
| cov_factor (Tensor): factor part of low-rank form of covariance matrix with shape
| `batch_shape + event_shape + (rank,)`
| cov_diag (Tensor): diagonal part of low-rank form of covariance matrix with shape
| `batch_shape + event_shape`
|
| Note:
| The computation for determinant and inverse of covariance matrix is avoided when
| `cov_factor.shape[1] << cov_factor.shape[0]` thanks to `Woodbury matrix identity
| <https://en.wikipedia.org/wiki/Woodbury_matrix_identity>`_ and
| `matrix determinant lemma <https://en.wikipedia.org/wiki/Matrix_determinant_lemma>`_.
| Thanks to these formulas, we just need to compute the determinant and inverse of
| the small size "capacitance" matrix::
|
| capacitance = I + cov_factor.T @ inv(cov_diag) @ cov_factor
|
| Method resolution order:
| LowRankMultivariateNormal
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, loc: torch.Tensor, cov_factor: torch.Tensor, cov_diag: torch.Tensor, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| covariance_matrix
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| precision_matrix
|
| scale_tril
|
| variance
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'cov_diag': IndependentConstraint(GreaterThan(lower...
|
| has_rsample = True
|
| support = IndependentConstraint(Real(), 1)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class LowerCholeskyTransform(Transform)
| LowerCholeskyTransform(cache_size: int = 0) -> None
|
| Transform from unconstrained matrices to lower-triangular matrices with
| nonnegative diagonal entries.
|
| This is useful for parameterizing positive definite matrices in terms of
| their Cholesky factorization.
|
| Method resolution order:
| LowerCholeskyTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| codomain = LowerCholesky()
|
| domain = IndependentConstraint(Real(), 2)
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __getstate__(self)
| Helper for pickle.
|
| __init__(self, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| sign
| Returns the sign of the determinant of the Jacobian, if applicable.
| In general this only makes sense for bijective transforms.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Transform:
|
| bijective = False
class MixtureSameFamily(torch.distributions.distribution.Distribution)
| MixtureSameFamily(mixture_distribution: torch.distributions.categorical.Categorical, component_distribution: torch.distributions.distribution.Distribution, validate_args: bool | None = None) -> None
|
| The `MixtureSameFamily` distribution implements a (batch of) mixture
| distribution where all components are from different parameterizations of
| the same distribution type. It is parameterized by a `Categorical`
| "selecting distribution" (over `k` components) and a component
| distribution, i.e., a `Distribution` with a rightmost batch shape
| (equal to `[k]`) which indexes each (batch of) component.
|
| Examples::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> # Construct Gaussian Mixture Model in 1D consisting of 5 equally
| >>> # weighted normal distributions
| >>> mix = D.Categorical(torch.ones(5,))
| >>> comp = D.Normal(torch.randn(5,), torch.rand(5,))
| >>> gmm = MixtureSameFamily(mix, comp)
|
| >>> # Construct Gaussian Mixture Model in 2D consisting of 5 equally
| >>> # weighted bivariate normal distributions
| >>> mix = D.Categorical(torch.ones(5,))
| >>> comp = D.Independent(D.Normal(
| ... torch.randn(5,2), torch.rand(5,2)), 1)
| >>> gmm = MixtureSameFamily(mix, comp)
|
| >>> # Construct a batch of 3 Gaussian Mixture Models in 2D each
| >>> # consisting of 5 random weighted bivariate normal distributions
| >>> mix = D.Categorical(torch.rand(3,5))
| >>> comp = D.Independent(D.Normal(
| ... torch.randn(3,5,2), torch.rand(3,5,2)), 1)
| >>> gmm = MixtureSameFamily(mix, comp)
|
| Args:
| mixture_distribution: `torch.distributions.Categorical`-like
| instance. Manages the probability of selecting components.
| The number of categories must match the rightmost batch
| dimension of the `component_distribution`. Must have either
| scalar `batch_shape` or `batch_shape` matching
| `component_distribution.batch_shape[:-1]`
| component_distribution: `torch.distributions.Distribution`-like
| instance. Right-most batch dimension indexes component.
|
| Method resolution order:
| MixtureSameFamily
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, mixture_distribution: torch.distributions.categorical.Categorical, component_distribution: torch.distributions.distribution.Distribution, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| cdf(self, x)
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, x)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| component_distribution
|
| mean
| Returns the mean of the distribution.
|
| mixture_distribution
|
| support
| Returns a :class:`~torch.distributions.constraints.Constraint` object
| representing this distribution's support.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'arg_constraints': dict[str, torch.distributions.co...
|
| arg_constraints = {}
|
| has_rsample = False
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| entropy(self) -> torch.Tensor
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class Multinomial(torch.distributions.distribution.Distribution)
| Multinomial(total_count: int = 1, probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
|
| Creates a Multinomial distribution parameterized by :attr:`total_count` and
| either :attr:`probs` or :attr:`logits` (but not both). The innermost dimension of
| :attr:`probs` indexes over categories. All other dimensions index over batches.
|
| Note that :attr:`total_count` need not be specified if only :meth:`log_prob` is
| called (see example below)
|
| .. note:: The `probs` argument must be non-negative, finite and have a non-zero sum,
| and it will be normalized to sum to 1 along the last dimension. :attr:`probs`
| will return this normalized value.
| The `logits` argument will be interpreted as unnormalized log probabilities
| and can therefore be any real number. It will likewise be normalized so that
| the resulting probabilities sum to 1 along the last dimension. :attr:`logits`
| will return this normalized value.
|
| - :meth:`sample` requires a single shared `total_count` for all
| parameters and samples.
| - :meth:`log_prob` allows different `total_count` for each parameter and
| sample.
|
| Example::
|
| >>> # xdoctest: +SKIP("FIXME: found invalid values")
| >>> m = Multinomial(100, torch.tensor([ 1., 1., 1., 1.]))
| >>> x = m.sample() # equal probability of 0, 1, 2, 3
| tensor([ 21., 24., 30., 25.])
|
| >>> Multinomial(probs=torch.tensor([1., 1., 1., 1.])).log_prob(x)
| tensor([-4.1338])
|
| Args:
| total_count (int): number of trials
| probs (Tensor): event probabilities
| logits (Tensor): event log probabilities (unnormalized)
|
| Method resolution order:
| Multinomial
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, total_count: int = 1, probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| logits
|
| mean
| Returns the mean of the distribution.
|
| param_shape
|
| probs
|
| support
| Returns a :class:`~torch.distributions.constraints.Constraint` object
| representing this distribution's support.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'total_count': <class 'int'>}
|
| arg_constraints = {'logits': IndependentConstraint(Real(), 1), 'probs'...
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
|
| has_rsample = False
class MultivariateNormal(torch.distributions.distribution.Distribution)
| MultivariateNormal(loc: torch.Tensor, covariance_matrix: torch.Tensor | None = None, precision_matrix: torch.Tensor | None = None, scale_tril: torch.Tensor | None = None, validate_args: bool | None = None) -> None
|
| Creates a multivariate normal (also called Gaussian) distribution
| parameterized by a mean vector and a covariance matrix.
|
| The multivariate normal distribution can be parameterized either
| in terms of a positive definite covariance matrix :math:`\mathbf{\Sigma}`
| or a positive definite precision matrix :math:`\mathbf{\Sigma}^{-1}`
| or a lower-triangular matrix :math:`\mathbf{L}` with positive-valued
| diagonal entries, such that
| :math:`\mathbf{\Sigma} = \mathbf{L}\mathbf{L}^\top`. This triangular matrix
| can be obtained via e.g. Cholesky decomposition of the covariance.
|
| Example:
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_LAPACK)
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = MultivariateNormal(torch.zeros(2), torch.eye(2))
| >>> m.sample() # normally distributed with mean=`[0,0]` and covariance_matrix=`I`
| tensor([-0.2102, -0.5429])
|
| Args:
| loc (Tensor): mean of the distribution
| covariance_matrix (Tensor): positive-definite covariance matrix
| precision_matrix (Tensor): positive-definite precision matrix
| scale_tril (Tensor): lower-triangular factor of covariance, with positive-valued diagonal
|
| Note:
| Only one of :attr:`covariance_matrix` or :attr:`precision_matrix` or
| :attr:`scale_tril` can be specified.
|
| Using :attr:`scale_tril` will be more efficient: all computations internally
| are based on :attr:`scale_tril`. If :attr:`covariance_matrix` or
| :attr:`precision_matrix` is passed instead, it is only used to compute
| the corresponding lower triangular matrices using a Cholesky decomposition.
|
| Method resolution order:
| MultivariateNormal
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, loc: torch.Tensor, covariance_matrix: torch.Tensor | None = None, precision_matrix: torch.Tensor | None = None, scale_tril: torch.Tensor | None = None, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| covariance_matrix
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| precision_matrix
|
| scale_tril
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'covariance_matrix': PositiveDefinite(), 'loc': Ind...
|
| has_rsample = True
|
| support = IndependentConstraint(Real(), 1)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class NegativeBinomial(torch.distributions.distribution.Distribution)
| NegativeBinomial(total_count: torch.Tensor | float, probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
|
| Creates a Negative Binomial distribution, i.e. distribution
| of the number of successful independent and identical Bernoulli trials
| before :attr:`total_count` failures are achieved. The probability
| of success of each Bernoulli trial is :attr:`probs`.
|
| Args:
| total_count (float or Tensor): non-negative number of negative Bernoulli
| trials to stop, although the distribution is still valid for real
| valued count
| probs (Tensor): Event probabilities of success in the half open interval [0, 1)
| logits (Tensor): Event log-odds for probabilities of success
|
| Method resolution order:
| NegativeBinomial
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, total_count: torch.Tensor | float, probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| logits
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| param_shape
|
| probs
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'logits': Real(), 'probs': HalfOpenInterval(lower_b...
|
| support = IntegerGreaterThan(lower_bound=0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self) -> torch.Tensor
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
|
| has_rsample = False
class Normal(torch.distributions.exp_family.ExponentialFamily)
| Normal(loc: torch.Tensor | float, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Creates a normal (also called Gaussian) distribution parameterized by
| :attr:`loc` and :attr:`scale`.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Normal(torch.tensor([0.0]), torch.tensor([1.0]))
| >>> m.sample() # normally distributed with loc=0 and scale=1
| tensor([ 0.1046])
|
| Args:
| loc (float or Tensor): mean of the distribution (often referred to as mu)
| scale (float or Tensor): standard deviation of the distribution
| (often referred to as sigma)
|
| Method resolution order:
| Normal
| torch.distributions.exp_family.ExponentialFamily
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, loc: torch.Tensor | float, scale: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| cdf(self, value)
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self)
| Method to compute the entropy using Bregman divergence of the log normalizer.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| icdf(self, value)
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'loc': Real(), 'scale': GreaterThan(lower_bound=0.0...
|
| has_rsample = True
|
| support = Real()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class OneHotCategorical(torch.distributions.distribution.Distribution)
| OneHotCategorical(probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
|
| Creates a one-hot categorical distribution parameterized by :attr:`probs` or
| :attr:`logits`.
|
| Samples are one-hot coded vectors of size ``probs.size(-1)``.
|
| .. note:: The `probs` argument must be non-negative, finite and have a non-zero sum,
| and it will be normalized to sum to 1 along the last dimension. :attr:`probs`
| will return this normalized value.
| The `logits` argument will be interpreted as unnormalized log probabilities
| and can therefore be any real number. It will likewise be normalized so that
| the resulting probabilities sum to 1 along the last dimension. :attr:`logits`
| will return this normalized value.
|
| See also: :func:`torch.distributions.Categorical` for specifications of
| :attr:`probs` and :attr:`logits`.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = OneHotCategorical(torch.tensor([ 0.25, 0.25, 0.25, 0.25 ]))
| >>> m.sample() # equal probability of 0, 1, 2, 3
| tensor([ 0., 0., 0., 1.])
|
| Args:
| probs (Tensor): event probabilities
| logits (Tensor): event log probabilities (unnormalized)
|
| Method resolution order:
| OneHotCategorical
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand=True)
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| logits
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| param_shape
|
| probs
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'logits': IndependentConstraint(Real(), 1), 'probs'...
|
| has_enumerate_support = True
|
| support = OneHot()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_rsample = False
class OneHotCategoricalStraightThrough(OneHotCategorical)
| OneHotCategoricalStraightThrough(probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
|
| Creates a reparameterizable :class:`OneHotCategorical` distribution based on the straight-
| through gradient estimator from [1].
|
| [1] Estimating or Propagating Gradients Through Stochastic Neurons for Conditional Computation
| (Bengio et al., 2013)
|
| Method resolution order:
| OneHotCategoricalStraightThrough
| OneHotCategorical
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| has_rsample = True
|
| ----------------------------------------------------------------------
| Methods inherited from OneHotCategorical:
|
| __init__(self, probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand=True)
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from OneHotCategorical:
|
| logits
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| param_shape
|
| probs
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from OneHotCategorical:
|
| arg_constraints = {'logits': IndependentConstraint(Real(), 1), 'probs'...
|
| has_enumerate_support = True
|
| support = OneHot()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Pareto(torch.distributions.transformed_distribution.TransformedDistribution)
| Pareto(scale: torch.Tensor | float, alpha: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Samples from a Pareto Type 1 distribution.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Pareto(torch.tensor([1.0]), torch.tensor([1.0]))
| >>> m.sample() # sample from a Pareto distribution with scale=1 and alpha=1
| tensor([ 1.5623])
|
| Args:
| scale (float or Tensor): Scale parameter of the distribution
| alpha (float or Tensor): Shape parameter of the distribution
|
| Method resolution order:
| Pareto
| torch.distributions.transformed_distribution.TransformedDistribution
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, scale: torch.Tensor | float, alpha: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self) -> torch.Tensor
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape: torch.Size | list[int] | tuple[int, ...], _instance: Optional[ForwardRef('Pareto')] = None) -> 'Pareto'
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| support
| Returns a :class:`~torch.distributions.constraints.Constraint` object
| representing this distribution's support.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'alpha': GreaterThan(lower_bound=0.0), 'scale': Gre...
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| cdf(self, value)
| Computes the cumulative distribution function by inverting the
| transform(s) and computing the score of the base distribution.
|
| icdf(self, value)
| Computes the inverse cumulative distribution function using
| transform(s) and computing the score of the base distribution.
|
| log_prob(self, value)
| Scores the sample by inverting the transform(s) and computing the score
| using the score of the base distribution and the log abs det jacobian.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched. Samples first from base distribution and applies
| `transform()` for every transform in the list.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched. Samples first from
| base distribution and applies `transform()` for every transform in the
| list.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| has_rsample
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class Poisson(torch.distributions.exp_family.ExponentialFamily)
| Poisson(rate: torch.Tensor | int | float | bool, validate_args: bool | None = None) -> None
|
| Creates a Poisson distribution parameterized by :attr:`rate`, the rate parameter.
|
| Samples are nonnegative integers, with a pmf given by
|
| .. math::
| \mathrm{rate}^k \frac{e^{-\mathrm{rate}}}{k!}
|
| Example::
|
| >>> # xdoctest: +SKIP("poisson_cpu not implemented for 'Long'")
| >>> m = Poisson(torch.tensor([4]))
| >>> m.sample()
| tensor([ 3.])
|
| Args:
| rate (Number, Tensor): the rate parameter
|
| Method resolution order:
| Poisson
| torch.distributions.exp_family.ExponentialFamily
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, rate: torch.Tensor | int | float | bool, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'rate': GreaterThanEq(lower_bound=0.0)}
|
| support = IntegerGreaterThan(lower_bound=0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.exp_family.ExponentialFamily:
|
| entropy(self)
| Method to compute the entropy using Bregman divergence of the log normalizer.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
|
| has_rsample = False
class PositiveDefiniteTransform(Transform)
| PositiveDefiniteTransform(cache_size: int = 0) -> None
|
| Transform from unconstrained matrices to positive-definite matrices.
|
| Method resolution order:
| PositiveDefiniteTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| codomain = PositiveDefinite()
|
| domain = IndependentConstraint(Real(), 2)
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __getstate__(self)
| Helper for pickle.
|
| __init__(self, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| sign
| Returns the sign of the determinant of the Jacobian, if applicable.
| In general this only makes sense for bijective transforms.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Transform:
|
| bijective = False
class PowerTransform(Transform)
| PowerTransform(exponent: torch.Tensor, cache_size: int = 0) -> None
|
| Transform via the mapping :math:`y = x^{\text{exponent}}`.
|
| Method resolution order:
| PowerTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, exponent: torch.Tensor, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| sign
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| bijective = True
|
| codomain = GreaterThan(lower_bound=0.0)
|
| domain = GreaterThan(lower_bound=0.0)
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __getstate__(self)
| Helper for pickle.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class RelaxedBernoulli(torch.distributions.transformed_distribution.TransformedDistribution)
| RelaxedBernoulli(temperature: torch.Tensor, probs: torch.Tensor | int | float | bool | None = None, logits: torch.Tensor | int | float | bool | None = None, validate_args: bool | None = None) -> None
|
| Creates a RelaxedBernoulli distribution, parametrized by
| :attr:`temperature`, and either :attr:`probs` or :attr:`logits`
| (but not both). This is a relaxed version of the `Bernoulli` distribution,
| so the values are in (0, 1), and has reparametrizable samples.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = RelaxedBernoulli(torch.tensor([2.2]),
| ... torch.tensor([0.1, 0.2, 0.3, 0.99]))
| >>> m.sample()
| tensor([ 0.2951, 0.3442, 0.8918, 0.9021])
|
| Args:
| temperature (Tensor): relaxation temperature
| probs (Number, Tensor): the probability of sampling `1`
| logits (Number, Tensor): the log-odds of sampling `1`
|
| Method resolution order:
| RelaxedBernoulli
| torch.distributions.transformed_distribution.TransformedDistribution
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, temperature: torch.Tensor, probs: torch.Tensor | int | float | bool | None = None, logits: torch.Tensor | int | float | bool | None = None, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| logits
|
| probs
|
| temperature
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'base_dist': <class 'torch.distributions.relaxed_be...
|
| arg_constraints = {'logits': Real(), 'probs': Interval(lower_bound=0.0...
|
| has_rsample = True
|
| support = Interval(lower_bound=0.0, upper_bound=1.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| cdf(self, value)
| Computes the cumulative distribution function by inverting the
| transform(s) and computing the score of the base distribution.
|
| icdf(self, value)
| Computes the inverse cumulative distribution function using
| transform(s) and computing the score of the base distribution.
|
| log_prob(self, value)
| Scores the sample by inverting the transform(s) and computing the score
| using the score of the base distribution and the log abs det jacobian.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched. Samples first from base distribution and applies
| `transform()` for every transform in the list.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched. Samples first from
| base distribution and applies `transform()` for every transform in the
| list.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| entropy(self) -> torch.Tensor
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class RelaxedOneHotCategorical(torch.distributions.transformed_distribution.TransformedDistribution)
| RelaxedOneHotCategorical(temperature: torch.Tensor, probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
|
| Creates a RelaxedOneHotCategorical distribution parametrized by
| :attr:`temperature`, and either :attr:`probs` or :attr:`logits`.
| This is a relaxed version of the :class:`OneHotCategorical` distribution, so
| its samples are on simplex, and are reparametrizable.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = RelaxedOneHotCategorical(torch.tensor([2.2]),
| ... torch.tensor([0.1, 0.2, 0.3, 0.4]))
| >>> m.sample()
| tensor([ 0.1294, 0.2324, 0.3859, 0.2523])
|
| Args:
| temperature (Tensor): relaxation temperature
| probs (Tensor): event probabilities
| logits (Tensor): unnormalized log probability for each event
|
| Method resolution order:
| RelaxedOneHotCategorical
| torch.distributions.transformed_distribution.TransformedDistribution
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, temperature: torch.Tensor, probs: torch.Tensor | None = None, logits: torch.Tensor | None = None, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| logits
|
| probs
|
| temperature
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'base_dist': <class 'torch.distributions.relaxed_ca...
|
| arg_constraints = {'logits': IndependentConstraint(Real(), 1), 'probs'...
|
| has_rsample = True
|
| support = Simplex()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| cdf(self, value)
| Computes the cumulative distribution function by inverting the
| transform(s) and computing the score of the base distribution.
|
| icdf(self, value)
| Computes the inverse cumulative distribution function using
| transform(s) and computing the score of the base distribution.
|
| log_prob(self, value)
| Scores the sample by inverting the transform(s) and computing the score
| using the score of the base distribution and the log abs det jacobian.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched. Samples first from base distribution and applies
| `transform()` for every transform in the list.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched. Samples first from
| base distribution and applies `transform()` for every transform in the
| list.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| entropy(self) -> torch.Tensor
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class ReshapeTransform(Transform)
| ReshapeTransform(in_shape: torch.Size, out_shape: torch.Size, cache_size: int = 0) -> None
|
| Unit Jacobian transform to reshape the rightmost part of a tensor.
|
| Note that ``in_shape`` and ``out_shape`` must have the same number of
| elements, just as for :meth:`torch.Tensor.reshape`.
|
| Arguments:
| in_shape (torch.Size): The input event shape.
| out_shape (torch.Size): The output event shape.
| cache_size (int): Size of cache. If zero, no caching is done. If one,
| the latest single value is cached. Only 0 and 1 are supported. (Default 0.)
|
| Method resolution order:
| ReshapeTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __init__(self, in_shape: torch.Size, out_shape: torch.Size, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| codomain
|
| domain
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| bijective = True
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __eq__(self, other)
| Return self==value.
|
| __getstate__(self)
| Helper for pickle.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| sign
| Returns the sign of the determinant of the Jacobian, if applicable.
| In general this only makes sense for bijective transforms.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Transform:
|
| __hash__ = None
class SigmoidTransform(Transform)
| SigmoidTransform(cache_size: int = 0) -> None
|
| Transform via the mapping :math:`y = \frac{1}{1 + \exp(-x)}` and :math:`x = \text{logit}(y)`.
|
| Method resolution order:
| SigmoidTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| bijective = True
|
| codomain = Interval(lower_bound=0.0, upper_bound=1.0)
|
| domain = Real()
|
| sign = 1
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __getstate__(self)
| Helper for pickle.
|
| __init__(self, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class SoftmaxTransform(Transform)
| SoftmaxTransform(cache_size: int = 0) -> None
|
| Transform from unconstrained space to the simplex via :math:`y = \exp(x)` then
| normalizing.
|
| This is not bijective and cannot be used for HMC. However this acts mostly
| coordinate-wise (except for the final normalization), and thus is
| appropriate for coordinate-wise optimization algorithms.
|
| Method resolution order:
| SoftmaxTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| codomain = Simplex()
|
| domain = IndependentConstraint(Real(), 1)
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __getstate__(self)
| Helper for pickle.
|
| __init__(self, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| sign
| Returns the sign of the determinant of the Jacobian, if applicable.
| In general this only makes sense for bijective transforms.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Transform:
|
| bijective = False
class SoftplusTransform(Transform)
| SoftplusTransform(cache_size: int = 0) -> None
|
| Transform via the mapping :math:`\text{Softplus}(x) = \log(1 + \exp(x))`.
| The implementation reverts to the linear function when :math:`x > 20`.
|
| Method resolution order:
| SoftplusTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| bijective = True
|
| codomain = GreaterThan(lower_bound=0.0)
|
| domain = Real()
|
| sign = 1
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __getstate__(self)
| Helper for pickle.
|
| __init__(self, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class StackTransform(Transform)
| StackTransform(tseq: collections.abc.Sequence[torch.distributions.transforms.Transform], dim: int = 0, cache_size: int = 0) -> None
|
| Transform functor that applies a sequence of transforms `tseq`
| component-wise to each submatrix at `dim`
| in a way compatible with :func:`torch.stack`.
|
| Example::
|
| x = torch.stack([torch.range(1, 10), torch.range(1, 10)], dim=1)
| t = StackTransform([ExpTransform(), identity_transform], dim=1)
| y = t(x)
|
| Method resolution order:
| StackTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __init__(self, tseq: collections.abc.Sequence[torch.distributions.transforms.Transform], dim: int = 0, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| bijective
|
| codomain
|
| domain
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'transforms': list[torch.distributions.transforms.T...
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __eq__(self, other)
| Return self==value.
|
| __getstate__(self)
| Helper for pickle.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| sign
| Returns the sign of the determinant of the Jacobian, if applicable.
| In general this only makes sense for bijective transforms.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Transform:
|
| __hash__ = None
class StickBreakingTransform(Transform)
| StickBreakingTransform(cache_size: int = 0) -> None
|
| Transform from unconstrained space to the simplex of one additional
| dimension via a stick-breaking process.
|
| This transform arises as an iterated sigmoid transform in a stick-breaking
| construction of the `Dirichlet` distribution: the first logit is
| transformed via sigmoid to the first probability and the probability of
| everything else, and then the process recurses.
|
| This is bijective and appropriate for use in HMC; however it mixes
| coordinates together and is less appropriate for optimization.
|
| Method resolution order:
| StickBreakingTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| bijective = True
|
| codomain = Simplex()
|
| domain = IndependentConstraint(Real(), 1)
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __getstate__(self)
| Helper for pickle.
|
| __init__(self, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| sign
| Returns the sign of the determinant of the Jacobian, if applicable.
| In general this only makes sense for bijective transforms.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class StudentT(torch.distributions.distribution.Distribution)
| StudentT(df: torch.Tensor | float, loc: torch.Tensor | float = 0.0, scale: torch.Tensor | float = 1.0, validate_args: bool | None = None) -> None
|
| Creates a Student's t-distribution parameterized by degree of
| freedom :attr:`df`, mean :attr:`loc` and scale :attr:`scale`.
|
| Example::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = StudentT(torch.tensor([2.0]))
| >>> m.sample() # Student's t-distributed with degrees of freedom=2
| tensor([ 0.1046])
|
| Args:
| df (float or Tensor): degrees of freedom
| loc (float or Tensor): mean of the distribution
| scale (float or Tensor): scale of the distribution
|
| Method resolution order:
| StudentT
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, df: torch.Tensor | float, loc: torch.Tensor | float = 0.0, scale: torch.Tensor | float = 1.0, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'df': GreaterThan(lower_bound=0.0), 'loc': Real(), ...
|
| has_rsample = True
|
| support = Real()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class TanhTransform(Transform)
| TanhTransform(cache_size: int = 0) -> None
|
| Transform via the mapping :math:`y = \tanh(x)`.
|
| It is equivalent to
|
| .. code-block:: python
|
| ComposeTransform(
| [
| AffineTransform(0.0, 2.0),
| SigmoidTransform(),
| AffineTransform(-1.0, 2.0),
| ]
| )
|
| However this might not be numerically stable, thus it is recommended to use `TanhTransform`
| instead.
|
| Note that one should use `cache_size=1` when it comes to `NaN/Inf` values.
|
| Method resolution order:
| TanhTransform
| Transform
| builtins.object
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| bijective = True
|
| codomain = Interval(lower_bound=-1.0, upper_bound=1.0)
|
| domain = Real()
|
| sign = 1
|
| ----------------------------------------------------------------------
| Methods inherited from Transform:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __getstate__(self)
| Helper for pickle.
|
| __init__(self, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Transform:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Transform:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Transform(builtins.object)
| Transform(cache_size: int = 0) -> None
|
| Abstract class for invertible transformations with computable log
| det jacobians. They are primarily used in
| :class:`torch.distributions.TransformedDistribution`.
|
| Caching is useful for transforms whose inverses are either expensive or
| numerically unstable. Note that care must be taken with memoized values
| since the autograd graph may be reversed. For example while the following
| works with or without caching::
|
| y = t(x)
| t.log_abs_det_jacobian(x, y).backward() # x will receive gradients.
|
| However the following will error when caching due to dependency reversal::
|
| y = t(x)
| z = t.inv(y)
| grad(z.sum(), [y]) # error because z is x
|
| Derived classes should implement one or both of :meth:`_call` or
| :meth:`_inverse`. Derived classes that set `bijective=True` should also
| implement :meth:`log_abs_det_jacobian`.
|
| Args:
| cache_size (int): Size of cache. If zero, no caching is done. If one,
| the latest single value is cached. Only 0 and 1 are supported.
|
| Attributes:
| domain (:class:`~torch.distributions.constraints.Constraint`):
| The constraint representing valid inputs to this transform.
| codomain (:class:`~torch.distributions.constraints.Constraint`):
| The constraint representing valid outputs to this transform
| which are inputs to the inverse transform.
| bijective (bool): Whether this transform is bijective. A transform
| ``t`` is bijective iff ``t.inv(t(x)) == x`` and
| ``t(t.inv(y)) == y`` for every ``x`` in the domain and ``y`` in
| the codomain. Transforms that are not bijective should at least
| maintain the weaker pseudoinverse properties
| ``t(t.inv(t(x)) == t(x)`` and ``t.inv(t(t.inv(y))) == t.inv(y)``.
| sign (int or Tensor): For bijective univariate transforms, this
| should be +1 or -1 depending on whether transform is monotone
| increasing or decreasing.
|
| Methods defined here:
|
| __call__(self, x)
| Computes the transform `x => y`.
|
| __eq__(self, other)
| Return self==value.
|
| __getstate__(self)
| Helper for pickle.
|
| __init__(self, cache_size: int = 0) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __ne__(self, other)
| Return self!=value.
|
| __repr__(self)
| Return repr(self).
|
| forward_shape(self, shape)
| Infers the shape of the forward computation, given the input shape.
| Defaults to preserving shape.
|
| inverse_shape(self, shape)
| Infers the shapes of the inverse computation, given the output shape.
| Defaults to preserving shape.
|
| log_abs_det_jacobian(self, x, y)
| Computes the log det jacobian `log |dy/dx|` given input and output.
|
| with_cache(self, cache_size=1)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| event_dim
|
| inv
| Returns the inverse :class:`Transform` of this transform.
| This should satisfy ``t.inv.inv is t``.
|
| sign
| Returns the sign of the determinant of the Jacobian, if applicable.
| In general this only makes sense for bijective transforms.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'codomain': <class 'torch.distributions.constraints...
|
| __hash__ = None
|
| bijective = False
class TransformedDistribution(torch.distributions.distribution.Distribution)
| TransformedDistribution(base_distribution: torch.distributions.distribution.Distribution, transforms: torch.distributions.transforms.Transform | list[torch.distributions.transforms.Transform], validate_args: bool | None = None) -> None
|
| Extension of the Distribution class, which applies a sequence of Transforms
| to a base distribution. Let f be the composition of transforms applied::
|
| X ~ BaseDistribution
| Y = f(X) ~ TransformedDistribution(BaseDistribution, f)
| log p(Y) = log p(X) + log |det (dX/dY)|
|
| Note that the ``.event_shape`` of a :class:`TransformedDistribution` is the
| maximum shape of its base distribution and its transforms, since transforms
| can introduce correlations among events.
|
| An example for the usage of :class:`TransformedDistribution` would be::
|
| # Building a Logistic Distribution
| # X ~ Uniform(0, 1)
| # f = a + b * logit(X)
| # Y ~ f(X) ~ Logistic(a, b)
| base_distribution = Uniform(0, 1)
| transforms = [SigmoidTransform().inv, AffineTransform(loc=a, scale=b)]
| logistic = TransformedDistribution(base_distribution, transforms)
|
| For more examples, please look at the implementations of
| :class:`~torch.distributions.gumbel.Gumbel`,
| :class:`~torch.distributions.half_cauchy.HalfCauchy`,
| :class:`~torch.distributions.half_normal.HalfNormal`,
| :class:`~torch.distributions.log_normal.LogNormal`,
| :class:`~torch.distributions.pareto.Pareto`,
| :class:`~torch.distributions.weibull.Weibull`,
| :class:`~torch.distributions.relaxed_bernoulli.RelaxedBernoulli` and
| :class:`~torch.distributions.relaxed_categorical.RelaxedOneHotCategorical`
|
| Method resolution order:
| TransformedDistribution
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, base_distribution: torch.distributions.distribution.Distribution, transforms: torch.distributions.transforms.Transform | list[torch.distributions.transforms.Transform], validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| cdf(self, value)
| Computes the cumulative distribution function by inverting the
| transform(s) and computing the score of the base distribution.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| icdf(self, value)
| Computes the inverse cumulative distribution function using
| transform(s) and computing the score of the base distribution.
|
| log_prob(self, value)
| Scores the sample by inverting the transform(s) and computing the score
| using the score of the base distribution and the log abs det jacobian.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched. Samples first from base distribution and applies
| `transform()` for every transform in the list.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched. Samples first from
| base distribution and applies `transform()` for every transform in the
| list.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| has_rsample
|
| support
| Returns a :class:`~torch.distributions.constraints.Constraint` object
| representing this distribution's support.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'arg_constraints': dict[str, torch.distributions.co...
|
| arg_constraints = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| entropy(self) -> torch.Tensor
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class Uniform(torch.distributions.distribution.Distribution)
| Uniform(low: torch.Tensor | float, high: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Generates uniformly distributed random samples from the half-open interval
| ``[low, high)``.
|
| Example::
|
| >>> m = Uniform(torch.tensor([0.0]), torch.tensor([5.0]))
| >>> m.sample() # uniformly distributed in the range [0.0, 5.0)
| >>> # xdoctest: +SKIP
| tensor([ 2.3418])
|
| Args:
| low (float or Tensor): lower range (inclusive).
| high (float or Tensor): upper range (exclusive).
|
| Method resolution order:
| Uniform
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, low: torch.Tensor | float, high: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| cdf(self, value)
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| icdf(self, value)
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| arg_constraints
| Returns a dictionary from argument names to
| :class:`~torch.distributions.constraints.Constraint` objects that
| should be satisfied by each argument of this distribution. Args that
| are not tensors need not appear in this dict.
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| stddev
| Returns the standard deviation of the distribution.
|
| support
| Returns a :class:`~torch.distributions.constraints.Constraint` object
| representing this distribution's support.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| has_rsample = True
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class VonMises(torch.distributions.distribution.Distribution)
| VonMises(loc: torch.Tensor, concentration: torch.Tensor, validate_args: bool | None = None) -> None
|
| A circular von Mises distribution.
|
| This implementation uses polar coordinates. The ``loc`` and ``value`` args
| can be any real number (to facilitate unconstrained optimization), but are
| interpreted as angles modulo 2 pi.
|
| Example::
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = VonMises(torch.tensor([1.0]), torch.tensor([1.0]))
| >>> m.sample() # von Mises distributed with loc=1 and concentration=1
| tensor([1.9777])
|
| :param torch.Tensor loc: an angle in radians.
| :param torch.Tensor concentration: concentration parameter
|
| Method resolution order:
| VonMises
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, loc: torch.Tensor, concentration: torch.Tensor, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| sample(self, sample_shape=torch.Size([]))
| The sampling algorithm for the von Mises distribution is based on the
| following paper: D.J. Best and N.I. Fisher, "Efficient simulation of the
| von Mises distribution." Applied Statistics (1979): 152-157.
|
| Sampling is always done in double precision internally to avoid a hang
| in _rejection_sample() for small values of the concentration, which
| starts to happen for single precision around 1e-4 (see issue #88443).
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| The provided mean is the circular one.
|
| mode
| Returns the mode of the distribution.
|
| variance
| The provided variance is the circular one.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'concentration': GreaterThan(lower_bound=0.0), 'loc...
|
| has_rsample = False
|
| support = Real()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| entropy(self) -> torch.Tensor
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class Weibull(torch.distributions.transformed_distribution.TransformedDistribution)
| Weibull(scale: torch.Tensor | float, concentration: torch.Tensor | float, validate_args: bool | None = None) -> None
|
| Samples from a two-parameter Weibull distribution.
|
| Example:
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> m = Weibull(torch.tensor([1.0]), torch.tensor([1.0]))
| >>> m.sample() # sample from a Weibull distribution with scale=1, concentration=1
| tensor([ 0.4784])
|
| Args:
| scale (float or Tensor): Scale parameter of distribution (lambda).
| concentration (float or Tensor): Concentration parameter of distribution (k/shape).
| validate_args (bool, optional): Whether to validate arguments. Default: None.
|
| Method resolution order:
| Weibull
| torch.distributions.transformed_distribution.TransformedDistribution
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, scale: torch.Tensor | float, concentration: torch.Tensor | float, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Returns entropy of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| arg_constraints = {'concentration': GreaterThan(lower_bound=0.0), 'sca...
|
| support = GreaterThan(lower_bound=0.0)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| cdf(self, value)
| Computes the cumulative distribution function by inverting the
| transform(s) and computing the score of the base distribution.
|
| icdf(self, value)
| Computes the inverse cumulative distribution function using
| transform(s) and computing the score of the base distribution.
|
| log_prob(self, value)
| Scores the sample by inverting the transform(s) and computing the score
| using the score of the base distribution and the log abs det jacobian.
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped reparameterized sample or sample_shape
| shaped batch of reparameterized samples if the distribution parameters
| are batched. Samples first from base distribution and applies
| `transform()` for every transform in the list.
|
| sample(self, sample_shape=torch.Size([]))
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched. Samples first from
| base distribution and applies `transform()` for every transform in the
| list.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.transformed_distribution.TransformedDistribution:
|
| has_rsample
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
class Wishart(torch.distributions.exp_family.ExponentialFamily)
| Wishart(df: torch.Tensor | int | float | bool, covariance_matrix: torch.Tensor | None = None, precision_matrix: torch.Tensor | None = None, scale_tril: torch.Tensor | None = None, validate_args: bool | None = None) -> None
|
| Creates a Wishart distribution parameterized by a symmetric positive definite matrix :math:`\Sigma`,
| or its Cholesky decomposition :math:`\mathbf{\Sigma} = \mathbf{L}\mathbf{L}^\top`
|
| Example:
| >>> # xdoctest: +SKIP("FIXME: scale_tril must be at least two-dimensional")
| >>> m = Wishart(torch.Tensor([2]), covariance_matrix=torch.eye(2))
| >>> m.sample() # Wishart distributed with mean=`df * I` and
| >>> # variance(x_ij)=`df` for i != j and variance(x_ij)=`2 * df` for i == j
|
| Args:
| df (float or Tensor): real-valued parameter larger than the (dimension of Square matrix) - 1
| covariance_matrix (Tensor): positive-definite covariance matrix
| precision_matrix (Tensor): positive-definite precision matrix
| scale_tril (Tensor): lower-triangular factor of covariance, with positive-valued diagonal
| Note:
| Only one of :attr:`covariance_matrix` or :attr:`precision_matrix` or
| :attr:`scale_tril` can be specified.
| Using :attr:`scale_tril` will be more efficient: all computations internally
| are based on :attr:`scale_tril`. If :attr:`covariance_matrix` or
| :attr:`precision_matrix` is passed instead, it is only used to compute
| the corresponding lower triangular matrices using a Cholesky decomposition.
| 'torch.distributions.LKJCholesky' is a restricted Wishart distribution.[1]
|
| **References**
|
| [1] Wang, Z., Wu, Y. and Chu, H., 2018. `On equivalence of the LKJ distribution and the restricted Wishart distribution`.
| [2] Sawyer, S., 2007. `Wishart Distributions and Inverse-Wishart Sampling`.
| [3] Anderson, T. W., 2003. `An Introduction to Multivariate Statistical Analysis (3rd ed.)`.
| [4] Odell, P. L. & Feiveson, A. H., 1966. `A Numerical Procedure to Generate a Sample Covariance Matrix`. JASA, 61(313):199-203.
| [5] Ku, Y.-C. & Bloomfield, P., 2010. `Generating Random Wishart Matrices with Fractional Degrees of Freedom in OX`.
|
| Method resolution order:
| Wishart
| torch.distributions.exp_family.ExponentialFamily
| torch.distributions.distribution.Distribution
| builtins.object
|
| Methods defined here:
|
| __init__(self, df: torch.Tensor | int | float | bool, covariance_matrix: torch.Tensor | None = None, precision_matrix: torch.Tensor | None = None, scale_tril: torch.Tensor | None = None, validate_args: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| entropy(self)
| Method to compute the entropy using Bregman divergence of the log normalizer.
|
| expand(self, batch_shape, _instance=None)
| Returns a new distribution instance (or populates an existing instance
| provided by a derived class) with batch dimensions expanded to
| `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
| the distribution's parameters. As such, this does not allocate new
| memory for the expanded distribution instance. Additionally,
| this does not repeat any args checking or parameter broadcasting in
| `__init__.py`, when an instance is first created.
|
| Args:
| batch_shape (torch.Size): the desired expanded size.
| _instance: new instance provided by subclasses that
| need to override `.expand`.
|
| Returns:
| New distribution instance with batch dimensions expanded to
| `batch_shape`.
|
| log_prob(self, value)
| Returns the log of the probability density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| rsample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([]), max_try_correction=None) -> torch.Tensor
| .. warning::
| In some cases, sampling algorithm based on Bartlett decomposition may return singular matrix samples.
| Several tries to correct singular samples are performed by default, but it may end up returning
| singular matrix samples. Singular samples may return `-inf` values in `.log_prob()`.
| In those cases, the user should validate the samples and either fix the value of `df`
| or adjust `max_try_correction` value for argument in `.rsample` accordingly.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| arg_constraints
| Returns a dictionary from argument names to
| :class:`~torch.distributions.constraints.Constraint` objects that
| should be satisfied by each argument of this distribution. Args that
| are not tensors need not appear in this dict.
|
| covariance_matrix
|
| mean
| Returns the mean of the distribution.
|
| mode
| Returns the mode of the distribution.
|
| precision_matrix
|
| scale_tril
|
| variance
| Returns the variance of the distribution.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| has_rsample = True
|
| support = PositiveDefinite()
|
| ----------------------------------------------------------------------
| Methods inherited from torch.distributions.distribution.Distribution:
|
| __repr__(self) -> str
| Return repr(self).
|
| cdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| enumerate_support(self, expand: bool = True) -> torch.Tensor
| Returns tensor containing all values supported by a discrete
| distribution. The result will enumerate over dimension 0, so the shape
| of the result will be `(cardinality,) + batch_shape + event_shape`
| (where `event_shape = ()` for univariate distributions).
|
| Note that this enumerates over all batched tensors in lock-step
| `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
| along dim 0, but with the remaining batch dimensions being
| singleton dimensions, `[[0], [1], ..`.
|
| To iterate over the full Cartesian product use
| `itertools.product(m.enumerate_support())`.
|
| Args:
| expand (bool): whether to expand the support over the
| batch dims to match the distribution's `batch_shape`.
|
| Returns:
| Tensor iterating over dimension 0.
|
| icdf(self, value: torch.Tensor) -> torch.Tensor
| Returns the inverse cumulative density/mass function evaluated at
| `value`.
|
| Args:
| value (Tensor):
|
| perplexity(self) -> torch.Tensor
| Returns perplexity of distribution, batched over batch_shape.
|
| Returns:
| Tensor of shape batch_shape.
|
| sample(self, sample_shape: torch.Size | list[int] | tuple[int, ...] = torch.Size([])) -> torch.Tensor
| Generates a sample_shape shaped sample or sample_shape shaped batch of
| samples if the distribution parameters are batched.
|
| sample_n(self, n: int) -> torch.Tensor
| Generates n samples or n batches of samples if the distribution
| parameters are batched.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.distributions.distribution.Distribution:
|
| set_default_validate_args(value: bool) -> None
| Sets whether validation is enabled or disabled.
|
| The default behavior mimics Python's ``assert`` statement: validation
| is on by default, but is disabled if Python is run in optimized mode
| (via ``python -O``). Validation may be expensive, so you may want to
| disable it once a model is working.
|
| Args:
| value (bool): Whether to enable validation.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.distributions.distribution.Distribution:
|
| batch_shape
| Returns the shape over which parameters are batched.
|
| event_shape
| Returns the shape of a single sample (without batching).
|
| stddev
| Returns the standard deviation of the distribution.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.distributions.distribution.Distribution:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.distributions.distribution.Distribution:
|
| has_enumerate_support = False
FUNCTIONS
kl_divergence(p: torch.distributions.distribution.Distribution, q: torch.distributions.distribution.Distribution) -> torch.Tensor
Compute Kullback-Leibler divergence :math:`KL(p \| q)` between two distributions.
.. math::
KL(p \| q) = \int p(x) \log\frac {p(x)} {q(x)} \,dx
Args:
p (Distribution): A :class:`~torch.distributions.Distribution` object.
q (Distribution): A :class:`~torch.distributions.Distribution` object.
Returns:
Tensor: A batch of KL divergences of shape `batch_shape`.
Raises:
NotImplementedError: If the distribution types have not been registered via
:meth:`register_kl`.
KL divergence is currently implemented for the following distribution pairs:
* :class:`~torch.distributions.Bernoulli` and :class:`~torch.distributions.Bernoulli`
* :class:`~torch.distributions.Bernoulli` and :class:`~torch.distributions.Poisson`
* :class:`~torch.distributions.Beta` and :class:`~torch.distributions.Beta`
* :class:`~torch.distributions.Beta` and :class:`~torch.distributions.ContinuousBernoulli`
* :class:`~torch.distributions.Beta` and :class:`~torch.distributions.Exponential`
* :class:`~torch.distributions.Beta` and :class:`~torch.distributions.Gamma`
* :class:`~torch.distributions.Beta` and :class:`~torch.distributions.Normal`
* :class:`~torch.distributions.Beta` and :class:`~torch.distributions.Pareto`
* :class:`~torch.distributions.Beta` and :class:`~torch.distributions.Uniform`
* :class:`~torch.distributions.Binomial` and :class:`~torch.distributions.Binomial`
* :class:`~torch.distributions.Categorical` and :class:`~torch.distributions.Categorical`
* :class:`~torch.distributions.Cauchy` and :class:`~torch.distributions.Cauchy`
* :class:`~torch.distributions.ContinuousBernoulli` and :class:`~torch.distributions.ContinuousBernoulli`
* :class:`~torch.distributions.ContinuousBernoulli` and :class:`~torch.distributions.Exponential`
* :class:`~torch.distributions.ContinuousBernoulli` and :class:`~torch.distributions.Normal`
* :class:`~torch.distributions.ContinuousBernoulli` and :class:`~torch.distributions.Pareto`
* :class:`~torch.distributions.ContinuousBernoulli` and :class:`~torch.distributions.Uniform`
* :class:`~torch.distributions.Dirichlet` and :class:`~torch.distributions.Dirichlet`
* :class:`~torch.distributions.Exponential` and :class:`~torch.distributions.Beta`
* :class:`~torch.distributions.Exponential` and :class:`~torch.distributions.ContinuousBernoulli`
* :class:`~torch.distributions.Exponential` and :class:`~torch.distributions.Exponential`
* :class:`~torch.distributions.Exponential` and :class:`~torch.distributions.Gamma`
* :class:`~torch.distributions.Exponential` and :class:`~torch.distributions.Gumbel`
* :class:`~torch.distributions.Exponential` and :class:`~torch.distributions.Normal`
* :class:`~torch.distributions.Exponential` and :class:`~torch.distributions.Pareto`
* :class:`~torch.distributions.Exponential` and :class:`~torch.distributions.Uniform`
* :class:`~torch.distributions.ExponentialFamily` and :class:`~torch.distributions.ExponentialFamily`
* :class:`~torch.distributions.Gamma` and :class:`~torch.distributions.Beta`
* :class:`~torch.distributions.Gamma` and :class:`~torch.distributions.ContinuousBernoulli`
* :class:`~torch.distributions.Gamma` and :class:`~torch.distributions.Exponential`
* :class:`~torch.distributions.Gamma` and :class:`~torch.distributions.Gamma`
* :class:`~torch.distributions.Gamma` and :class:`~torch.distributions.Gumbel`
* :class:`~torch.distributions.Gamma` and :class:`~torch.distributions.Normal`
* :class:`~torch.distributions.Gamma` and :class:`~torch.distributions.Pareto`
* :class:`~torch.distributions.Gamma` and :class:`~torch.distributions.Uniform`
* :class:`~torch.distributions.Geometric` and :class:`~torch.distributions.Geometric`
* :class:`~torch.distributions.Gumbel` and :class:`~torch.distributions.Beta`
* :class:`~torch.distributions.Gumbel` and :class:`~torch.distributions.ContinuousBernoulli`
* :class:`~torch.distributions.Gumbel` and :class:`~torch.distributions.Exponential`
* :class:`~torch.distributions.Gumbel` and :class:`~torch.distributions.Gamma`
* :class:`~torch.distributions.Gumbel` and :class:`~torch.distributions.Gumbel`
* :class:`~torch.distributions.Gumbel` and :class:`~torch.distributions.Normal`
* :class:`~torch.distributions.Gumbel` and :class:`~torch.distributions.Pareto`
* :class:`~torch.distributions.Gumbel` and :class:`~torch.distributions.Uniform`
* :class:`~torch.distributions.HalfNormal` and :class:`~torch.distributions.HalfNormal`
* :class:`~torch.distributions.Independent` and :class:`~torch.distributions.Independent`
* :class:`~torch.distributions.Laplace` and :class:`~torch.distributions.Beta`
* :class:`~torch.distributions.Laplace` and :class:`~torch.distributions.ContinuousBernoulli`
* :class:`~torch.distributions.Laplace` and :class:`~torch.distributions.Exponential`
* :class:`~torch.distributions.Laplace` and :class:`~torch.distributions.Gamma`
* :class:`~torch.distributions.Laplace` and :class:`~torch.distributions.Laplace`
* :class:`~torch.distributions.Laplace` and :class:`~torch.distributions.Normal`
* :class:`~torch.distributions.Laplace` and :class:`~torch.distributions.Pareto`
* :class:`~torch.distributions.Laplace` and :class:`~torch.distributions.Uniform`
* :class:`~torch.distributions.LowRankMultivariateNormal` and :class:`~torch.distributions.LowRankMultivariateNormal`
* :class:`~torch.distributions.LowRankMultivariateNormal` and :class:`~torch.distributions.MultivariateNormal`
* :class:`~torch.distributions.MultivariateNormal` and :class:`~torch.distributions.LowRankMultivariateNormal`
* :class:`~torch.distributions.MultivariateNormal` and :class:`~torch.distributions.MultivariateNormal`
* :class:`~torch.distributions.Normal` and :class:`~torch.distributions.Beta`
* :class:`~torch.distributions.Normal` and :class:`~torch.distributions.ContinuousBernoulli`
* :class:`~torch.distributions.Normal` and :class:`~torch.distributions.Exponential`
* :class:`~torch.distributions.Normal` and :class:`~torch.distributions.Gamma`
* :class:`~torch.distributions.Normal` and :class:`~torch.distributions.Gumbel`
* :class:`~torch.distributions.Normal` and :class:`~torch.distributions.Laplace`
* :class:`~torch.distributions.Normal` and :class:`~torch.distributions.Normal`
* :class:`~torch.distributions.Normal` and :class:`~torch.distributions.Pareto`
* :class:`~torch.distributions.Normal` and :class:`~torch.distributions.Uniform`
* :class:`~torch.distributions.OneHotCategorical` and :class:`~torch.distributions.OneHotCategorical`
* :class:`~torch.distributions.Pareto` and :class:`~torch.distributions.Beta`
* :class:`~torch.distributions.Pareto` and :class:`~torch.distributions.ContinuousBernoulli`
* :class:`~torch.distributions.Pareto` and :class:`~torch.distributions.Exponential`
* :class:`~torch.distributions.Pareto` and :class:`~torch.distributions.Gamma`
* :class:`~torch.distributions.Pareto` and :class:`~torch.distributions.Normal`
* :class:`~torch.distributions.Pareto` and :class:`~torch.distributions.Pareto`
* :class:`~torch.distributions.Pareto` and :class:`~torch.distributions.Uniform`
* :class:`~torch.distributions.Poisson` and :class:`~torch.distributions.Bernoulli`
* :class:`~torch.distributions.Poisson` and :class:`~torch.distributions.Binomial`
* :class:`~torch.distributions.Poisson` and :class:`~torch.distributions.Poisson`
* :class:`~torch.distributions.TransformedDistribution` and :class:`~torch.distributions.TransformedDistribution`
* :class:`~torch.distributions.Uniform` and :class:`~torch.distributions.Beta`
* :class:`~torch.distributions.Uniform` and :class:`~torch.distributions.ContinuousBernoulli`
* :class:`~torch.distributions.Uniform` and :class:`~torch.distributions.Exponential`
* :class:`~torch.distributions.Uniform` and :class:`~torch.distributions.Gamma`
* :class:`~torch.distributions.Uniform` and :class:`~torch.distributions.Gumbel`
* :class:`~torch.distributions.Uniform` and :class:`~torch.distributions.Normal`
* :class:`~torch.distributions.Uniform` and :class:`~torch.distributions.Pareto`
* :class:`~torch.distributions.Uniform` and :class:`~torch.distributions.Uniform`
register_kl(type_p, type_q)
Decorator to register a pairwise function with :meth:`kl_divergence`.
Usage::
@register_kl(Normal, Normal)
def kl_normal_normal(p, q):
# insert implementation here
Lookup returns the most specific (type,type) match ordered by subclass. If
the match is ambiguous, a `RuntimeWarning` is raised. For example to
resolve the ambiguous situation::
@register_kl(BaseP, DerivedQ)
def kl_version1(p, q): ...
@register_kl(DerivedP, BaseQ)
def kl_version2(p, q): ...
you should register a third most-specific implementation, e.g.::
register_kl(DerivedP, DerivedQ)(kl_version1) # Break the tie.
Args:
type_p (type): A subclass of :class:`~torch.distributions.Distribution`.
type_q (type): A subclass of :class:`~torch.distributions.Distribution`.
DATA
__all__ = ['Bernoulli', 'Beta', 'Binomial', 'Categorical', 'Cauchy', '...
biject_to = <torch.distributions.constraint_registry.ConstraintRegistr...
identity_transform = ComposeTransform(
)
transform_to = <torch.distributions.constraint_registry.ConstraintRegi...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\distributions\__init__.py
torch.div
Python Library Documentation: built-in function div in module torch
div(...)
div(input, other, *, rounding_mode=None, out=None) -> Tensor
Divides each element of the input ``input`` by the corresponding element of
:attr:`other`.
.. math::
\text{out}_i = \frac{\text{input}_i}{\text{other}_i}
.. note::
By default, this performs a "true" division like Python 3.
See the :attr:`rounding_mode` argument for floor division.
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
Always promotes integer types to the default scalar type.
Args:
input (Tensor): the dividend
other (Tensor or Number): the divisor
Keyword args:
rounding_mode (str, optional): Type of rounding applied to the result:
* None - default behavior. Performs no rounding and, if both :attr:`input` and
:attr:`other` are integer types, promotes the inputs to the default scalar type.
Equivalent to true division in Python (the ``/`` operator) and NumPy's ``np.true_divide``.
* ``"trunc"`` - rounds the results of the division towards zero.
Equivalent to C-style integer division.
* ``"floor"`` - rounds the results of the division down.
Equivalent to floor division in Python (the ``//`` operator) and NumPy's ``np.floor_divide``.
out (Tensor, optional): the output tensor.
Examples::
>>> x = torch.tensor([ 0.3810, 1.2774, -0.2972, -0.3719, 0.4637])
>>> torch.div(x, 0.5)
tensor([ 0.7620, 2.5548, -0.5944, -0.7438, 0.9274])
>>> a = torch.tensor([[-0.3711, -1.9353, -0.4605, -0.2917],
... [ 0.1815, -1.0111, 0.9805, -1.5923],
... [ 0.1062, 1.4581, 0.7759, -1.2344],
... [-0.1830, -0.0313, 1.1908, -1.4757]])
>>> b = torch.tensor([ 0.8032, 0.2930, -0.8113, -0.2308])
>>> torch.div(a, b)
tensor([[-0.4620, -6.6051, 0.5676, 1.2639],
[ 0.2260, -3.4509, -1.2086, 6.8990],
[ 0.1322, 4.9764, -0.9564, 5.3484],
[-0.2278, -0.1068, -1.4678, 6.3938]])
>>> torch.div(a, b, rounding_mode='trunc')
tensor([[-0., -6., 0., 1.],
[ 0., -3., -1., 6.],
[ 0., 4., -0., 5.],
[-0., -0., -1., 6.]])
>>> torch.div(a, b, rounding_mode='floor')
tensor([[-1., -7., 0., 1.],
[ 0., -4., -2., 6.],
[ 0., 4., -1., 5.],
[-1., -1., -2., 6.]])
torch.divide
Python Library Documentation: built-in function divide in module torch
divide(...)
divide(input, other, *, rounding_mode=None, out=None) -> Tensor
Alias for :func:`torch.div`.
torch.dot
Python Library Documentation: built-in function dot in module torch
dot(...)
dot(input, tensor, *, out=None) -> Tensor
Computes the dot product of two 1D tensors.
.. note::
Unlike NumPy's dot, torch.dot intentionally only supports computing the dot product
of two 1D tensors with the same number of elements.
Args:
input (Tensor): first tensor in the dot product, must be 1D.
tensor (Tensor): second tensor in the dot product, must be 1D.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.dot(torch.tensor([2, 3]), torch.tensor([2, 1]))
tensor(7)
>>> t1, t2 = torch.tensor([0, 1]), torch.tensor([2, 3])
>>> torch.dot(t1, t2)
tensor(3)
torch.double
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.dropout
Python Library Documentation: built-in function dropout in module torch dropout(...)
torch.dropout_
Python Library Documentation: built-in function dropout_ in module torch dropout_(...)
torch.dsmm
Python Library Documentation: built-in function dsmm in module torch dsmm(...)
torch.dsplit
Python Library Documentation: built-in function dsplit in module torch
dsplit(...)
dsplit(input, indices_or_sections) -> List of Tensors
Splits :attr:`input`, a tensor with three or more dimensions, into multiple tensors
depthwise according to :attr:`indices_or_sections`. Each split is a view of
:attr:`input`.
This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=2)
(the split dimension is 2), except that if :attr:`indices_or_sections` is an integer
it must evenly divide the split dimension or a runtime error will be thrown.
This function is based on NumPy's :func:`numpy.dsplit`.
Args:
input (Tensor): tensor to split.
indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
Example::
>>> t = torch.arange(16.0).reshape(2, 2, 4)
>>> t
tensor([[[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.]],
[[ 8., 9., 10., 11.],
[12., 13., 14., 15.]]])
>>> torch.dsplit(t, 2)
(tensor([[[ 0., 1.],
[ 4., 5.]],
[[ 8., 9.],
[12., 13.]]]),
tensor([[[ 2., 3.],
[ 6., 7.]],
[[10., 11.],
[14., 15.]]]))
>>> torch.dsplit(t, [3, 6])
(tensor([[[ 0., 1., 2.],
[ 4., 5., 6.]],
[[ 8., 9., 10.],
[12., 13., 14.]]]),
tensor([[[ 3.],
[ 7.]],
[[11.],
[15.]]]),
tensor([], size=(2, 2, 0)))
torch.dstack
Python Library Documentation: built-in function dstack in module torch
dstack(...)
dstack(tensors, *, out=None) -> Tensor
Stack tensors in sequence depthwise (along third axis).
This is equivalent to concatenation along the third axis after 1-D and 2-D tensors have been reshaped by :func:`torch.atleast_3d`.
Args:
tensors (sequence of Tensors): sequence of tensors to concatenate
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([1, 2, 3])
>>> b = torch.tensor([4, 5, 6])
>>> torch.dstack((a,b))
tensor([[[1, 4],
[2, 5],
[3, 6]]])
>>> a = torch.tensor([[1],[2],[3]])
>>> b = torch.tensor([[4],[5],[6]])
>>> torch.dstack((a,b))
tensor([[[1, 4]],
[[2, 5]],
[[3, 6]]])
torch.dtype
Python Library Documentation: class dtype in module torch class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.e
Python Library Documentation: float object
class float(object)
| float(x=0, /)
|
| Convert a string or number to a floating-point number, if possible.
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(self, /)
| Return the ceiling as an Integral.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(self, /)
| Return the floor as an Integral.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Formats the float according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __int__(self, /)
| int(self)
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __round__(self, ndigits=None, /)
| Return the Integral closest to x, rounding half toward even.
|
| When an argument is passed, work like built-in round(x, ndigits).
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(self, /)
| Return the Integral closest to x between 0 and x.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is exactly equal to the original float.
|
| The ratio is in lowest terms and has a positive denominator. Raise
| OverflowError on infinities and a ValueError on NaNs.
|
| >>> (10.0).as_integer_ratio()
| (10, 1)
| >>> (0.0).as_integer_ratio()
| (0, 1)
| >>> (-.25).as_integer_ratio()
| (-1, 4)
|
| conjugate(self, /)
| Return self, the complex conjugate of any float.
|
| hex(self, /)
| Return a hexadecimal representation of a floating-point number.
|
| >>> (-0.1).hex()
| '-0x1.999999999999ap-4'
| >>> 3.14159.hex()
| '0x1.921f9f01b866ep+1'
|
| is_integer(self, /)
| Return True if the float is an integer.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __getformat__(typestr, /)
| You probably don't want to use this function.
|
| typestr
| Must be 'double' or 'float'.
|
| It exists mainly to be used in Python's test suite.
|
| This function returns whichever of 'unknown', 'IEEE, big-endian' or 'IEEE,
| little-endian' best describes the format of floating-point numbers used by the
| C type named by typestr.
|
| fromhex(string, /)
| Create a floating-point number from a hexadecimal string.
|
| >>> float.fromhex('0x1.ffffp10')
| 2047.984375
| >>> float.fromhex('-0x1p-1074')
| -5e-324
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| imag
| the imaginary part of a complex number
|
| real
| the real part of a complex number
torch.eig
Python Library Documentation: function eig in module torch._linalg_utils eig(self: torch.Tensor, eigenvectors: bool = False, *, e=None, v=None) -> tuple[torch.Tensor, torch.Tensor]
torch.einsum
Python Library Documentation: function einsum in module torch.functional
einsum(*args: Any) -> torch.Tensor
einsum(equation, *operands) -> Tensor
Sums the product of the elements of the input :attr:`operands` along dimensions specified using a notation
based on the Einstein summation convention.
Einsum allows computing many common multi-dimensional linear algebraic array operations by representing them
in a short-hand format based on the Einstein summation convention, given by :attr:`equation`. The details of
this format are described below, but the general idea is to label every dimension of the input :attr:`operands`
with some subscript and define which subscripts are part of the output. The output is then computed by summing
the product of the elements of the :attr:`operands` along the dimensions whose subscripts are not part of the
output. For example, matrix multiplication can be computed using einsum as `torch.einsum("ij,jk->ik", A, B)`.
Here, j is the summation subscript and i and k the output subscripts (see section below for more details on why).
Equation:
The :attr:`equation` string specifies the subscripts (letters in `[a-zA-Z]`) for each dimension of
the input :attr:`operands` in the same order as the dimensions, separating subscripts for each operand by a
comma (','), e.g. `'ij,jk'` specify subscripts for two 2D operands. The dimensions labeled with the same subscript
must be broadcastable, that is, their size must either match or be `1`. The exception is if a subscript is
repeated for the same input operand, in which case the dimensions labeled with this subscript for this operand
must match in size and the operand will be replaced by its diagonal along these dimensions. The subscripts that
appear exactly once in the :attr:`equation` will be part of the output, sorted in increasing alphabetical order.
The output is computed by multiplying the input :attr:`operands` element-wise, with their dimensions aligned based
on the subscripts, and then summing out the dimensions whose subscripts are not part of the output.
Optionally, the output subscripts can be explicitly defined by adding an arrow ('->') at the end of the equation
followed by the subscripts for the output. For instance, the following equation computes the transpose of a
matrix multiplication: 'ij,jk->ki'. The output subscripts must appear at least once for some input operand and
at most once for the output.
Ellipsis ('...') can be used in place of subscripts to broadcast the dimensions covered by the ellipsis.
Each input operand may contain at most one ellipsis which will cover the dimensions not covered by subscripts,
e.g. for an input operand with 5 dimensions, the ellipsis in the equation `'ab...c'` cover the third and fourth
dimensions. The ellipsis does not need to cover the same number of dimensions across the :attr:`operands` but the
'shape' of the ellipsis (the size of the dimensions covered by them) must broadcast together. If the output is not
explicitly defined with the arrow ('->') notation, the ellipsis will come first in the output (left-most dimensions),
before the subscript labels that appear exactly once for the input operands. e.g. the following equation implements
batch matrix multiplication `'...ij,...jk'`.
A few final notes: the equation may contain whitespaces between the different elements (subscripts, ellipsis,
arrow and comma) but something like `'. . .'` is not valid. An empty string `''` is valid for scalar operands.
.. note::
``torch.einsum`` handles ellipsis ('...') differently from NumPy in that it allows dimensions
covered by the ellipsis to be summed over, that is, ellipsis are not required to be part of the output.
.. note::
Please install opt-einsum (https://optimized-einsum.readthedocs.io/en/stable/) in order to enroll into a more
performant einsum. You can install when installing torch like so: `pip install torch[opt-einsum]` or by itself
with `pip install opt-einsum`.
If opt-einsum is available, this function will automatically speed up computation and/or consume less memory
by optimizing contraction order through our opt_einsum backend :mod:`torch.backends.opt_einsum` (The _ vs - is
confusing, I know). This optimization occurs when there are at least three inputs, since the order does not matter
otherwise. Note that finding `the` optimal path is an NP-hard problem, thus, opt-einsum relies on different
heuristics to achieve near-optimal results. If opt-einsum is not available, the default order is to contract
from left to right.
To bypass this default behavior, add the following to disable opt_einsum and skip path calculation:
``torch.backends.opt_einsum.enabled = False``
To specify which strategy you'd like for opt_einsum to compute the contraction path, add the following line:
``torch.backends.opt_einsum.strategy = 'auto'``. The default strategy is 'auto', and we also support 'greedy' and
'optimal'. Disclaimer that the runtime of 'optimal' is factorial in the number of inputs! See more details in
the opt_einsum documentation (https://optimized-einsum.readthedocs.io/en/stable/path_finding.html).
.. note::
As of PyTorch 1.10 :func:`torch.einsum` also supports the sublist format (see examples below). In this format,
subscripts for each operand are specified by sublists, list of integers in the range [0, 52). These sublists
follow their operands, and an extra sublist can appear at the end of the input to specify the output's
subscripts., e.g. `torch.einsum(op1, sublist1, op2, sublist2, ..., [subslist_out])`. Python's `Ellipsis` object
may be provided in a sublist to enable broadcasting as described in the Equation section above.
Args:
equation (str): The subscripts for the Einstein summation.
operands (List[Tensor]): The tensors to compute the Einstein summation of.
Examples::
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # trace
>>> torch.einsum('ii', torch.randn(4, 4))
tensor(-1.2104)
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # diagonal
>>> torch.einsum('ii->i', torch.randn(4, 4))
tensor([-0.1034, 0.7952, -0.2433, 0.4545])
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # outer product
>>> x = torch.randn(5)
>>> y = torch.randn(4)
>>> torch.einsum('i,j->ij', x, y)
tensor([[ 0.1156, -0.2897, -0.3918, 0.4963],
[-0.3744, 0.9381, 1.2685, -1.6070],
[ 0.7208, -1.8058, -2.4419, 3.0936],
[ 0.1713, -0.4291, -0.5802, 0.7350],
[ 0.5704, -1.4290, -1.9323, 2.4480]])
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # batch matrix multiplication
>>> As = torch.randn(3, 2, 5)
>>> Bs = torch.randn(3, 5, 4)
>>> torch.einsum('bij,bjk->bik', As, Bs)
tensor([[[-1.0564, -1.5904, 3.2023, 3.1271],
[-1.6706, -0.8097, -0.8025, -2.1183]],
[[ 4.2239, 0.3107, -0.5756, -0.2354],
[-1.4558, -0.3460, 1.5087, -0.8530]],
[[ 2.8153, 1.8787, -4.3839, -1.2112],
[ 0.3728, -2.1131, 0.0921, 0.8305]]])
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # with sublist format and ellipsis
>>> torch.einsum(As, [..., 0, 1], Bs, [..., 1, 2], [..., 0, 2])
tensor([[[-1.0564, -1.5904, 3.2023, 3.1271],
[-1.6706, -0.8097, -0.8025, -2.1183]],
[[ 4.2239, 0.3107, -0.5756, -0.2354],
[-1.4558, -0.3460, 1.5087, -0.8530]],
[[ 2.8153, 1.8787, -4.3839, -1.2112],
[ 0.3728, -2.1131, 0.0921, 0.8305]]])
>>> # batch permute
>>> A = torch.randn(2, 3, 4, 5)
>>> torch.einsum('...ij->...ji', A).shape
torch.Size([2, 3, 5, 4])
>>> # equivalent to torch.nn.functional.bilinear
>>> A = torch.randn(3, 5, 4)
>>> l = torch.randn(2, 5)
>>> r = torch.randn(2, 4)
>>> torch.einsum('bn,anm,bm->ba', l, A, r)
tensor([[-0.3430, -5.2405, 0.4494],
[ 0.3311, 5.5201, -3.0356]])
torch.embedding
Python Library Documentation: built-in function embedding in module torch embedding(...)
torch.embedding_bag
Python Library Documentation: built-in function embedding_bag in module torch embedding_bag(...)
torch.embedding_renorm_
Python Library Documentation: built-in function embedding_renorm_ in module torch embedding_renorm_(...)
torch.empty
Python Library Documentation: built-in function empty in module torch
empty(...)
empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
Returns a tensor filled with uninitialized data. The shape of the tensor is
defined by the variable argument :attr:`size`.
.. note::
If :func:`torch.use_deterministic_algorithms()` and
:attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
``True``, the output tensor is initialized to prevent any possible
nondeterministic behavior from using the data as an input to an operation.
Floating point and complex tensors are filled with NaN, and integer tensors
are filled with the maximum value.
Args:
size (int...): a sequence of integers defining the shape of the output tensor.
Can be a variable number of arguments or a collection like a list or tuple.
Keyword args:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.contiguous_format``.
Example::
>>> torch.empty((2,3), dtype=torch.int64)
tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
[ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
torch.empty_like
Python Library Documentation: built-in function empty_like in module torch
empty_like(...)
empty_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns an uninitialized tensor with the same size as :attr:`input`.
``torch.empty_like(input)`` is equivalent to
``torch.empty(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
.. note::
If :func:`torch.use_deterministic_algorithms()` and
:attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
``True``, the output tensor is initialized to prevent any possible
nondeterministic behavior from using the data as an input to an operation.
Floating point and complex tensors are filled with NaN, and integer tensors
are filled with the maximum value.
When ``torch.preserve_format`` is used:
If the input tensor is dense (i.e., non-overlapping strided),
its memory format (including strides) is retained.
Otherwise (e.g., a non-dense view like a stepped slice),
the output is converted to the dense format.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
Example::
>>> a=torch.empty((2,3), dtype=torch.int32, device = 'cuda')
>>> torch.empty_like(a)
tensor([[0, 0, 0],
[0, 0, 0]], device='cuda:0', dtype=torch.int32)
torch.empty_permuted
Python Library Documentation: built-in function empty_permuted in module torch
empty_permuted(...)
empty_permuted(size, physical_layout, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
Creates an uninitialized, non-overlapping and dense tensor with the
specified :attr:`size`, with :attr:`physical_layout` specifying how the
dimensions are physically laid out in memory (each logical dimension is listed
from outermost to innermost). :attr:`physical_layout` is a generalization
of NCHW/NHWC notation: if each dimension is assigned a number according to
what order they occur in size (N=0, C=1, H=2, W=3), then NCHW is ``(0, 1, 2, 3)``
while NHWC is ``(0, 2, 3, 1)``. Equivalently, the strides of the output
tensor ``t`` are such that ``t.stride(physical_layout[i]) == contiguous_strides[i]``
(notably, this function is *not* equivalent to ``torch.empty(size).permute(physical_layout)``).
Unlike :func:`torch.empty_strided`, this is guaranteed to produce a dense
tensor with no overlaps. If possible, prefer using this function over
:func:`torch.empty_strided` or manual use of :func:`torch.as_strided`.
.. note::
If :func:`torch.use_deterministic_algorithms()` and
:attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
``True``, the output tensor is initialized to prevent any possible
nondeterministic behavior from using the data as an input to an operation.
Floating point and complex tensors are filled with NaN, and integer tensors
are filled with the maximum value.
Args:
size (tuple of int): the shape of the output tensor
physical_layout (tuple of int): the ordering of dimensions physically in memory
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Examples:
>>> torch.empty((2, 3, 5, 7)).stride()
(105, 35, 7, 1)
>>> torch.empty_permuted((2, 3, 5, 7), (0, 1, 2, 3)).stride()
(105, 35, 7, 1)
>>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).stride()
(105, 1, 21, 3)
>>> torch.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).stride()
(105, 1, 21, 3)
>>> torch.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).dim_order()
(0, 2, 3, 1)
torch.empty_quantized
Python Library Documentation: built-in function empty_quantized in module torch empty_quantized(...)
torch.empty_strided
Python Library Documentation: built-in function empty_strided in module torch
empty_strided(...)
empty_strided(size, stride, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
Creates a tensor with the specified :attr:`size` and :attr:`stride` and filled with undefined data.
.. warning::
If the constructed tensor is "overlapped" (with multiple indices referring to the same element
in memory) its behavior is undefined.
.. note::
If :func:`torch.use_deterministic_algorithms()` and
:attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
``True``, the output tensor is initialized to prevent any possible
nondeterministic behavior from using the data as an input to an operation.
Floating point and complex tensors are filled with NaN, and integer tensors
are filled with the maximum value.
Args:
size (tuple of int): the shape of the output tensor
stride (tuple of int): the strides of the output tensor
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> a = torch.empty_strided((2, 3), (1, 2))
>>> a
tensor([[8.9683e-44, 4.4842e-44, 5.1239e+07],
[0.0000e+00, 0.0000e+00, 3.0705e-41]])
>>> a.stride()
(1, 2)
>>> a.size()
torch.Size([2, 3])
torch.enable_grad
Python Library Documentation: class enable_grad in module torch.autograd.grad_mode class enable_grad(torch.utils._contextlib._NoParamDecoratorContextManager) | enable_grad(orig_func: Optional[~F] = None) -> Union[Self, ~F] | | Context-manager that enables gradient calculation. | | Enables gradient calculation, if it has been disabled via :class:`~no_grad` | or :class:`~set_grad_enabled`. | | This context manager is thread local; it will not affect computation | in other threads. | | Also functions as a decorator. | | .. note:: | enable_grad is one of several mechanisms that can enable or | disable gradients locally see :ref:`locally-disable-grad-doc` for | more information on how they compare. | | .. note:: | This API does not apply to :ref:`forward-mode AD <forward-mode-ad>`. | | Example:: | >>> # xdoctest: +SKIP | >>> x = torch.tensor([1.], requires_grad=True) | >>> with torch.no_grad(): | ... with torch.enable_grad(): | ... y = x * 2 | >>> y.requires_grad | True | >>> y.backward() | >>> x.grad | tensor([2.]) | >>> @torch.enable_grad() | ... def doubler(x): | ... return x * 2 | >>> with torch.no_grad(): | ... z = doubler(x) | >>> z.requires_grad | True | >>> @torch.enable_grad() | ... def tripler(x): | ... return x * 3 | >>> with torch.no_grad(): | ... z = tripler(x) | >>> z.requires_grad | True | | Method resolution order: | enable_grad | torch.utils._contextlib._NoParamDecoratorContextManager | torch.utils._contextlib._DecoratorContextManager | builtins.object | | Methods defined here: | | __enter__(self) -> None | | __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None | | ---------------------------------------------------------------------- | Static methods inherited from torch.utils._contextlib._NoParamDecoratorContextManager: | | __new__(cls, orig_func: Optional[~F] = None) -> Union[Self, ~F] | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from torch.utils._contextlib._DecoratorContextManager: | | __call__(self, orig_func: ~F) -> ~F | Call self as a function. | | clone(self) | | ---------------------------------------------------------------------- | Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
torch.eq
Python Library Documentation: built-in function eq in module torch
eq(...)
eq(input, other, *, out=None) -> Tensor
Computes element-wise equality
The second argument can be a number or a tensor whose shape is
:ref:`broadcastable <broadcasting-semantics>` with the first argument.
Args:
input (Tensor): the tensor to compare
other (Tensor or float): the tensor or value to compare
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
A boolean tensor that is True where :attr:`input` is equal to :attr:`other` and False elsewhere
Example::
>>> torch.eq(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[ True, False],
[False, True]])
torch.equal
Python Library Documentation: built-in function equal in module torch
equal(...)
equal(input, other) -> bool
``True`` if two tensors have the same size and elements, ``False`` otherwise.
.. note::
Tensors containing NaNs are never equal to each other. Additionally, this function does not
differentiate between the data types of the tensors during comparison. For more thorough tensor checks,
use :meth:`torch.testing.assert_close`.
Example::
>>> torch.equal(torch.tensor([1, 2]), torch.tensor([1, 2]))
True
>>> torch.equal(torch.tensor([3, torch.nan]), torch.tensor([3, torch.nan]))
False
>>> torch.equal(torch.tensor([1, 2, 3], dtype=torch.int32), torch.tensor([1, 2, 3], dtype=torch.float32))
True
torch.erf
Python Library Documentation: built-in function erf in module torch
erf(...)
erf(input, *, out=None) -> Tensor
Alias for :func:`torch.special.erf`.
torch.erf_
Python Library Documentation: built-in function erf_ in module torch erf_(...)
torch.erfc
Python Library Documentation: built-in function erfc in module torch
erfc(...)
erfc(input, *, out=None) -> Tensor
Alias for :func:`torch.special.erfc`.
torch.erfc_
Python Library Documentation: built-in function erfc_ in module torch erfc_(...)
torch.erfinv
Python Library Documentation: built-in function erfinv in module torch
erfinv(...)
erfinv(input, *, out=None) -> Tensor
Alias for :func:`torch.special.erfinv`.
torch.exp
Python Library Documentation: built-in function exp in module torch
exp(...)
exp(input, *, out=None) -> Tensor
Returns a new tensor with the exponential of the elements
of the input tensor :attr:`input`.
.. math::
y_{i} = e^{x_{i}}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.exp(torch.tensor([0, math.log(2.)]))
tensor([ 1., 2.])
torch.exp2
Python Library Documentation: built-in function exp2 in module torch
exp2(...)
exp2(input, *, out=None) -> Tensor
Alias for :func:`torch.special.exp2`.
torch.exp2_
Python Library Documentation: built-in function exp2_ in module torch exp2_(...)
torch.exp_
Python Library Documentation: built-in function exp_ in module torch exp_(...)
torch.expand_copy
Python Library Documentation: built-in function expand_copy in module torch
expand_copy(...)
Performs the same operation as :func:`torch.Tensor.expand`, but all output tensors
are freshly created instead of aliasing the input.
torch.expm1
Python Library Documentation: built-in function expm1 in module torch
expm1(...)
expm1(input, *, out=None) -> Tensor
Alias for :func:`torch.special.expm1`.
torch.expm1_
Python Library Documentation: built-in function expm1_ in module torch expm1_(...)
torch.export
Python Library Documentation: package torch.export in torch
NAME
torch.export
PACKAGE CONTENTS
_draft_export
_leakage_detection_utils
_patches
_remove_auto_functionalized_pass
_remove_effect_tokens_pass
_safeguard
_state_dict_utils
_swap
_trace
_tree_utils
_unlift
_wrapper_utils
custom_obj
custom_ops
decomp_utils
dynamic_shapes
experimental (package)
exported_program
graph_signature
passes (package)
pt2_archive (package)
unflatten
CLASSES
abc.ABC(builtins.object)
torch.export.unflatten.FlatArgsAdapter
builtins.dict(builtins.object)
torch.export.decomp_utils.CustomDecompTable
builtins.object
torch.export.dynamic_shapes.AdditionalInputs
torch.export.dynamic_shapes.Dim
torch.export.dynamic_shapes.ShapesCollection
torch.export.exported_program.ExportedProgram
torch.export.exported_program.ModuleCallEntry
torch.export.exported_program.ModuleCallSignature
torch.export.graph_signature.ExportBackwardSignature
torch.export.graph_signature.ExportGraphSignature
torch.export.unflatten._SubmoduleBase(builtins.object)
torch.export.unflatten.UnflattenedModule(torch.export.unflatten._SubmoduleBase, torch.nn.modules.module.Module)
torch.nn.modules.module.Module(builtins.object)
torch.export.unflatten.UnflattenedModule(torch.export.unflatten._SubmoduleBase, torch.nn.modules.module.Module)
class AdditionalInputs(builtins.object)
| Infers dynamic_shapes based on additional inputs.
|
| This is useful particularly for deployment engineers who, on the one hand, may
| have access to ample testing or profiling data that can provide a fair sense of
| representative inputs for a model, but on the other hand, may not know enough
| about the model to guess which input shapes should be dynamic.
|
| Input shapes that are different than the original are considered dynamic; conversely,
| those that are the same as the original are considered static. Moreover, we verify
| that the additional inputs are valid for the exported program. This guarantees that
| tracing with them instead of the original would have generated the same graph.
|
| Example::
|
| args0, kwargs0 = ... # example inputs for export
|
| # other representative inputs that the exported program will run on
| dynamic_shapes = torch.export.AdditionalInputs()
| dynamic_shapes.add(args1, kwargs1)
| ...
| dynamic_shapes.add(argsN, kwargsN)
|
| torch.export(..., args0, kwargs0, dynamic_shapes=dynamic_shapes)
|
| Methods defined here:
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| add(self, args, kwargs=None)
| Additional input :func:`args` and :func:`kwargs`.
|
| dynamic_shapes(self, m, args, kwargs=None)
| Infers a :func:`dynamic_shapes` pytree structure by merging shapes of the
| original input :func:`args` and :func:`kwargs` and of each additional input
| args and kwargs.
|
| verify(self, ep)
| Verifies that an exported program is valid for each additional input.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class CustomDecompTable(builtins.dict)
| This is a custom dictionary that is specifically used for handling decomp_table in export.
| The reason we need this is because in the new world, you can only *delete* an op from decomp
| table to preserve it. This is problematic for custom ops because we don't know when the custom
| op will actually be loaded to the dispatcher. As a result, we need to record the custom ops operations
| until we really need to materialize it (which is when we run decomposition pass.)
|
| Invariants we hold are:
| 1. All aten decomp is loaded at the init time
| 2. We materialize ALL ops when user ever reads from the table to make it more likely
| that dispatcher picks up the custom op.
| 3. If it is write operation, we don't necessarily materialize
| 4. We load the final time during export, right before calling run_decompositions()
|
| Method resolution order:
| CustomDecompTable
| builtins.dict
| builtins.object
|
| Methods defined here:
|
| __contains__(self, key) -> bool
| True if the dictionary has the specified key, else False.
|
| __delitem__(self, key) -> None
| Delete self[key].
|
| __getitem__(self, key)
| Return self[key].
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
| Implement iter(self).
|
| __len__(self) -> int
| Return len(self).
|
| __missing__(self, key) -> bool
|
| __reversed__(self)
| Return a reverse iterator over the dict keys.
|
| __setitem__(self, key, value) -> None
| Set self[key] to value.
|
| copy(self) -> 'CustomDecompTable'
| D.copy() -> a shallow copy of D
|
| items(self)
| D.items() -> a set-like object providing a view on D's items
|
| keys(self)
| D.keys() -> a set-like object providing a view on D's keys
|
| materialize(self) -> dict[torch._ops.OperatorBase, collections.abc.Callable]
|
| pop(self, *args)
| D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
|
| If the key is not found, return the default if given; otherwise,
| raise a KeyError.
|
| update(self, other_dict)
| D.update([E, ]**F) -> None. Update D from dict/iterable E and F.
| If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
| If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v
| In either case, this is followed by: for k in F: D[k] = F[k]
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __orig_bases__ = (dict[torch._ops.OperatorBase, collections.abc.Callab...
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.dict:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __gt__(self, value, /)
| Return self>value.
|
| __ior__(self, value, /)
| Return self|=value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __or__(self, value, /)
| Return self|value.
|
| __repr__(self, /)
| Return repr(self).
|
| __ror__(self, value, /)
| Return value|self.
|
| __sizeof__(...)
| D.__sizeof__() -> size of D in memory, in bytes
|
| clear(...)
| D.clear() -> None. Remove all items from D.
|
| get(self, key, default=None, /)
| Return the value for key if key is in the dictionary, else default.
|
| popitem(self, /)
| Remove and return a (key, value) pair as a 2-tuple.
|
| Pairs are returned in LIFO (last-in, first-out) order.
| Raises KeyError if the dict is empty.
|
| setdefault(self, key, default=None, /)
| Insert key with a value of default if key is not in the dictionary.
|
| Return the value for key if key is in the dictionary, else default.
|
| values(...)
| D.values() -> an object providing a view on D's values
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.dict:
|
| __class_getitem__(...)
| See PEP 585
|
| fromkeys(iterable, value=None, /)
| Create a new dictionary with keys from iterable and values set to value.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.dict:
|
| __new__(*args, **kwargs) class method of builtins.dict
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from builtins.dict:
|
| __hash__ = None
class Dim(builtins.object)
| Dim(name: str, *, min: int | None = None, max: int | None = None)
|
| The ``Dim`` class allows users to specify dynamism in their exported
| programs. By marking a dimension with a ``Dim``, the compiler associates the
| dimension with a symbolic integer containing a dynamic range.
|
| The API can be used in 2 ways: Dim hints (i.e. automatic dynamic shapes:
| ``Dim.AUTO``, ``Dim.DYNAMIC``, ``Dim.STATIC``), or named Dims (i.e.
| ``Dim("name", min=1, max=2)``).
|
| Dim hints provide the lowest barrier to exportability, with the user only
| needing to specify if a dimension if dynamic, static, or left for the
| compiler to decide (``Dim.AUTO``). The export process will automatically
| infer the remaining constraints on min/max ranges and relationships between
| dimensions.
|
| Example::
|
| class Foo(nn.Module):
| def forward(self, x, y):
| assert x.shape[0] == 4
| assert y.shape[0] >= 16
| return x @ y
|
|
| x = torch.randn(4, 8)
| y = torch.randn(8, 16)
| dynamic_shapes = {
| "x": {0: Dim.AUTO, 1: Dim.AUTO},
| "y": {0: Dim.AUTO, 1: Dim.AUTO},
| }
| ep = torch.export(Foo(), (x, y), dynamic_shapes=dynamic_shapes)
|
| Here, export would raise an exception if we replaced all uses of ``Dim.AUTO`` with ``Dim.DYNAMIC``,
| as ``x.shape[0]`` is constrained to be static by the model.
|
| More complex relations between dimensions may also be codegened as runtime assertion nodes by the compiler,
| e.g. ``(x.shape[0] + y.shape[1]) % 4 == 0``, to be raised if runtime inputs do not satisfy such constraints.
|
| You may also specify min-max bounds for Dim hints, e.g. ``Dim.AUTO(min=16, max=32)``, ``Dim.DYNAMIC(max=64)``,
| with the compiler inferring the remaining constraints within the ranges. An exception will be raised if
| the valid range is entirely outside the user-specified range.
|
| Named Dims provide a stricter way of specifying dynamism, where exceptions are raised if the compiler
| infers constraints that do not match the user specification. For example, exporting the previous
| model, the user would need the following ``dynamic_shapes`` argument::
|
| s0 = Dim("s0")
| s1 = Dim("s1", min=16)
| dynamic_shapes = {
| "x": {0: 4, 1: s0},
| "y": {0: s0, 1: s1},
| }
| ep = torch.export(Foo(), (x, y), dynamic_shapes=dynamic_shapes)
|
| Named Dims also allow specification of relationships between dimensions, up
| to univariate linear relations. For example, the following indicates one
| dimension is a multiple of another plus 4::
|
| s0 = Dim("s0")
| s1 = 3 * s0 + 4
|
| Methods defined here:
|
| __add__(self, other) -> 'Dim'
|
| __init__(self, name: str, *, min: int | None = None, max: int | None = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __mul__(self, other) -> 'Dim'
|
| __radd__(self, other) -> 'Dim'
|
| __repr__(self)
| Return repr(self).
|
| __rmul__(self, other) -> 'Dim'
|
| __rsub__(self, other) -> 'Dim'
|
| __sub__(self, other) -> 'Dim'
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| AUTO = DimHint(AUTO)
|
| DYNAMIC = DimHint(DYNAMIC)
|
| STATIC = DimHint(STATIC)
class ExportBackwardSignature(builtins.object)
| ExportBackwardSignature(gradients_to_parameters: dict[str, str], gradients_to_user_inputs: dict[str, str], loss_output: str) -> None
|
| ExportBackwardSignature(gradients_to_parameters: dict[str, str], gradients_to_user_inputs: dict[str, str], loss_output: str)
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, gradients_to_parameters: dict[str, str], gradients_to_user_inputs: dict[str, str], loss_output: str) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'gradients_to_parameters': dict[str, str], 'gradien...
|
| __dataclass_fields__ = {'gradients_to_parameters': Field(name='gradien...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('gradients_to_parameters', 'gradients_to_user_inputs...
class ExportGraphSignature(builtins.object)
| ExportGraphSignature(input_specs: list[torch.export.graph_signature.InputSpec], output_specs: list[torch.export.graph_signature.OutputSpec]) -> None
|
| :class:`ExportGraphSignature` models the input/output signature of Export Graph,
| which is a fx.Graph with stronger invariants guarantees.
|
| Export Graph is functional and does not access "states" like parameters
| or buffers within the graph via ``getattr`` nodes. Instead, :func:`export`
| guarantees that parameters, buffers, and constant tensors are lifted out of
| the graph as inputs. Similarly, any mutations to buffers are not included
| in the graph either, instead the updated values of mutated buffers are
| modeled as additional outputs of Export Graph.
|
| The ordering of all inputs and outputs are::
|
| Inputs = [*parameters_buffers_constant_tensors, *flattened_user_inputs]
| Outputs = [*mutated_inputs, *flattened_user_outputs]
|
| e.g. If following module is exported::
|
| class CustomModule(nn.Module):
| def __init__(self) -> None:
| super(CustomModule, self).__init__()
|
| # Define a parameter
| self.my_parameter = nn.Parameter(torch.tensor(2.0))
|
| # Define two buffers
| self.register_buffer("my_buffer1", torch.tensor(3.0))
| self.register_buffer("my_buffer2", torch.tensor(4.0))
|
| def forward(self, x1, x2):
| # Use the parameter, buffers, and both inputs in the forward method
| output = (
| x1 + self.my_parameter
| ) * self.my_buffer1 + x2 * self.my_buffer2
|
| # Mutate one of the buffers (e.g., increment it by 1)
| self.my_buffer2.add_(1.0) # In-place addition
|
| return output
|
|
| mod = CustomModule()
| ep = torch.export.export(mod, (torch.tensor(1.0), torch.tensor(2.0)))
|
| Resulting Graph is non-functional::
|
| graph():
| %p_my_parameter : [num_users=1] = placeholder[target=p_my_parameter]
| %b_my_buffer1 : [num_users=1] = placeholder[target=b_my_buffer1]
| %b_my_buffer2 : [num_users=2] = placeholder[target=b_my_buffer2]
| %x1 : [num_users=1] = placeholder[target=x1]
| %x2 : [num_users=1] = placeholder[target=x2]
| %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%x1, %p_my_parameter), kwargs = {})
| %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add, %b_my_buffer1), kwargs = {})
| %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%x2, %b_my_buffer2), kwargs = {})
| %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul, %mul_1), kwargs = {})
| %add_ : [num_users=0] = call_function[target=torch.ops.aten.add_.Tensor](args = (%b_my_buffer2, 1.0), kwargs = {})
| return (add_1,)
|
| Resulting ExportGraphSignature of the non-functional Graph would be::
|
| # inputs
| p_my_parameter: PARAMETER target='my_parameter'
| b_my_buffer1: BUFFER target='my_buffer1' persistent=True
| b_my_buffer2: BUFFER target='my_buffer2' persistent=True
| x1: USER_INPUT
| x2: USER_INPUT
|
| # outputs
| add_1: USER_OUTPUT
|
| To get a functional Graph, you can use :func:`run_decompositions`::
|
| mod = CustomModule()
| ep = torch.export.export(mod, (torch.tensor(1.0), torch.tensor(2.0)))
| ep = ep.run_decompositions()
|
| Resulting Graph is functional::
|
| graph():
| %p_my_parameter : [num_users=1] = placeholder[target=p_my_parameter]
| %b_my_buffer1 : [num_users=1] = placeholder[target=b_my_buffer1]
| %b_my_buffer2 : [num_users=2] = placeholder[target=b_my_buffer2]
| %x1 : [num_users=1] = placeholder[target=x1]
| %x2 : [num_users=1] = placeholder[target=x2]
| %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%x1, %p_my_parameter), kwargs = {})
| %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add, %b_my_buffer1), kwargs = {})
| %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%x2, %b_my_buffer2), kwargs = {})
| %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul, %mul_1), kwargs = {})
| %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%b_my_buffer2, 1.0), kwargs = {})
| return (add_2, add_1)
|
| Resulting ExportGraphSignature of the functional Graph would be::
|
| # inputs
| p_my_parameter: PARAMETER target='my_parameter'
| b_my_buffer1: BUFFER target='my_buffer1' persistent=True
| b_my_buffer2: BUFFER target='my_buffer2' persistent=True
| x1: USER_INPUT
| x2: USER_INPUT
|
| # outputs
| add_2: BUFFER_MUTATION target='my_buffer2'
| add_1: USER_OUTPUT
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, input_specs: list[torch.export.graph_signature.InputSpec], output_specs: list[torch.export.graph_signature.OutputSpec]) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __post_init__(self) -> None
|
| __repr__(self)
| Return repr(self).
|
| __str__(self)
| Return str(self).
|
| get_replace_hook(self, replace_inputs=False)
|
| replace_all_uses(self, old: str, new: str)
| Replace all uses of the old name with new name in the signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| assertion_dep_token
|
| backward_signature
|
| buffers
|
| buffers_to_mutate
|
| input_tokens
|
| inputs_to_buffers
|
| inputs_to_lifted_custom_objs
|
| inputs_to_lifted_tensor_constants
|
| inputs_to_parameters
|
| lifted_custom_objs
|
| lifted_tensor_constants
|
| non_persistent_buffers
|
| output_tokens
|
| parameters
|
| parameters_to_mutate
|
| user_inputs
|
| user_inputs_to_mutate
|
| user_outputs
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'input_specs': list[torch.export.graph_signature.In...
|
| __dataclass_fields__ = {'input_specs': Field(name='input_specs',type=l...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('input_specs', 'output_specs')
class ExportedProgram(builtins.object)
| ExportedProgram(root: torch.nn.modules.module.Module | dict[str, typing.Any], graph: torch.fx.graph.Graph, graph_signature: torch.export.graph_signature.ExportGraphSignature, state_dict: dict[str, torch.Tensor | torch.nn.parameter.Parameter], range_constraints: 'dict[sympy.Symbol, Any]', module_call_graph: list[torch.export.exported_program.ModuleCallEntry], example_inputs: tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None = None, constants: dict[str, torch.Tensor | torch.ScriptObject | torch._library.fake_class_registry.FakeScriptObject | torch.utils._pytree.TreeSpec] | None = None, *, verifiers: list[type[torch._export.verifier.Verifier]] | None = None)
|
| Package of a program from :func:`export`. It contains
| an :class:`torch.fx.Graph` that represents Tensor computation, a state_dict containing
| tensor values of all lifted parameters and buffers, and various metadata.
|
| You can call an ExportedProgram like the original callable traced by
| :func:`export` with the same calling convention.
|
| To perform transformations on the graph, use ``.module`` property to access
| an :class:`torch.fx.GraphModule`. You can then use
| `FX transformation <https://pytorch.org/docs/stable/fx.html#writing-transformations>`_
| to rewrite the graph. Afterwards, you can simply use :func:`export`
| again to construct a correct ExportedProgram.
|
| Methods defined here:
|
| __call__(self, *args: Any, **kwargs: Any) -> Any
| Call self as a function.
|
| __init__(self, root: torch.nn.modules.module.Module | dict[str, typing.Any], graph: torch.fx.graph.Graph, graph_signature: torch.export.graph_signature.ExportGraphSignature, state_dict: dict[str, torch.Tensor | torch.nn.parameter.Parameter], range_constraints: 'dict[sympy.Symbol, Any]', module_call_graph: list[torch.export.exported_program.ModuleCallEntry], example_inputs: tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None = None, constants: dict[str, torch.Tensor | torch.ScriptObject | torch._library.fake_class_registry.FakeScriptObject | torch.utils._pytree.TreeSpec] | None = None, *, verifiers: list[type[torch._export.verifier.Verifier]] | None = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self) -> str
| Return str(self).
|
| buffers(self) -> collections.abc.Iterator[torch.Tensor]
| Returns an iterator over original module buffers.
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| module(self, check_guards=True) -> torch.fx.graph_module.GraphModule
| Returns a self contained GraphModule with all the parameters/buffers inlined.
|
| - When `check_guards=True` (default), a `_guards_fn` submodule is generated
| and a call to a `_guards_fn` submodule is inserted right after placeholders
| in the graph. This module checks guards on inputs.
| - When `check_guards=False`, a subset of these checks are performed by a
| forward pre-hook on the graph module. No `_guards_fn` submodule is generated.
|
| named_buffers(self) -> collections.abc.Iterator[tuple[str, torch.Tensor]]
| Returns an iterator over original module buffers, yielding
| both the name of the buffer as well as the buffer itself.
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| named_parameters(self) -> collections.abc.Iterator[tuple[str, torch.nn.parameter.Parameter]]
| Returns an iterator over original module parameters, yielding
| both the name of the parameter as well as the parameter itself.
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| parameters(self) -> collections.abc.Iterator[torch.nn.parameter.Parameter]
| Returns an iterator over original module's parameters.
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| run_decompositions(self, decomp_table: dict[torch._ops.OperatorBase, collections.abc.Callable] | None = None, decompose_custom_triton_ops: bool = False) -> 'ExportedProgram'
| Run a set of decompositions on the exported program and returns a new
| exported program. By default we will run the Core ATen decompositions to
| get operators in the
| `Core ATen Operator Set <https://pytorch.org/docs/stable/torch.compiler_ir.html>`_.
|
| For now, we do not decompose joint graphs.
|
| Args:
| decomp_table:
| An optional argument that specifies decomp behaviour for Aten ops
| (1) If None, we decompose to core aten decompositions
| (2) If empty, we don't decompose any operator
|
|
| Some examples:
|
| If you don't want to decompose anything
|
| .. code-block:: python
|
| ep = torch.export.export(model, ...)
| ep = ep.run_decompositions(decomp_table={})
|
| If you want to get a core aten operator set except for certain operator, you can do following:
|
| .. code-block:: python
|
| ep = torch.export.export(model, ...)
| decomp_table = torch.export.default_decompositions()
| decomp_table[your_op] = your_custom_decomp
| ep = ep.run_decompositions(decomp_table=decomp_table)
|
| validate(self)
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| call_spec
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| constants
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| dialect
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| example_inputs
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| graph
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| graph_module
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| graph_signature
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| module_call_graph
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| range_constraints
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| state_dict
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| tensor_constants
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| verifier
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| verifiers
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'_constants': dict[str, torch.Tensor | torch.Script...
class FlatArgsAdapter(abc.ABC)
| Adapts input arguments with ``input_spec`` to align ``target_spec``.
|
| Method resolution order:
| FlatArgsAdapter
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| adapt(self, target_spec: torch.utils._pytree.TreeSpec, input_spec: torch.utils._pytree.TreeSpec, input_args: list[typing.Any], metadata: dict[str, typing.Any] | None = None, obj: typing.Any | None = None) -> list[typing.Any]
| NOTE: This adapter may mutate given ``input_args_with_path``.
|
| get_flat_arg_paths(self) -> list[str]
| Returns a list of paths that are used to access the flat args.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset({'adapt'})
|
| __annotations__ = {}
class ModuleCallEntry(builtins.object)
| ModuleCallEntry(fqn: str, signature: torch.export.exported_program.ModuleCallSignature | None = None) -> None
|
| ModuleCallEntry(fqn: str, signature: torch.export.exported_program.ModuleCallSignature | None = None)
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, fqn: str, signature: torch.export.exported_program.ModuleCallSignature | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'fqn': <class 'str'>, 'signature': torch.export.exp...
|
| __dataclass_fields__ = {'fqn': Field(name='fqn',type=<class 'str'>,def...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('fqn', 'signature')
|
| signature = None
class ModuleCallSignature(builtins.object)
| ModuleCallSignature(inputs: list[torch.export.graph_signature.TensorArgument | torch.export.graph_signature.SymIntArgument | torch.export.graph_signature.SymFloatArgument | torch.export.graph_signature.SymBoolArgument | torch.export.graph_signature.ConstantArgument | torch.export.graph_signature.CustomObjArgument | torch.export.graph_signature.TokenArgument], outputs: list[torch.export.graph_signature.TensorArgument | torch.export.graph_signature.SymIntArgument | torch.export.graph_signature.SymFloatArgument | torch.export.graph_signature.SymBoolArgument | torch.export.graph_signature.ConstantArgument | torch.export.graph_signature.CustomObjArgument | torch.export.graph_signature.TokenArgument], in_spec: torch.utils._pytree.TreeSpec, out_spec: torch.utils._pytree.TreeSpec, forward_arg_names: list[str] | None = None) -> None
|
| ModuleCallSignature(inputs: list[torch.export.graph_signature.TensorArgument | torch.export.graph_signature.SymIntArgument | torch.export.graph_signature.SymFloatArgument | torch.export.graph_signature.SymBoolArgument | torch.export.graph_signature.ConstantArgument | torch.export.graph_signature.CustomObjArgument | torch.export.graph_signature.TokenArgument], outputs: list[torch.export.graph_signature.TensorArgument | torch.export.graph_signature.SymIntArgument | torch.export.graph_signature.SymFloatArgument | torch.export.graph_signature.SymBoolArgument | torch.export.graph_signature.ConstantArgument | torch.export.graph_signature.CustomObjArgument | torch.export.graph_signature.TokenArgument], in_spec: torch.utils._pytree.TreeSpec, out_spec: torch.utils._pytree.TreeSpec, forward_arg_names: list[str] | None = None)
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __init__(self, inputs: list[torch.export.graph_signature.TensorArgument | torch.export.graph_signature.SymIntArgument | torch.export.graph_signature.SymFloatArgument | torch.export.graph_signature.SymBoolArgument | torch.export.graph_signature.ConstantArgument | torch.export.graph_signature.CustomObjArgument | torch.export.graph_signature.TokenArgument], outputs: list[torch.export.graph_signature.TensorArgument | torch.export.graph_signature.SymIntArgument | torch.export.graph_signature.SymFloatArgument | torch.export.graph_signature.SymBoolArgument | torch.export.graph_signature.ConstantArgument | torch.export.graph_signature.CustomObjArgument | torch.export.graph_signature.TokenArgument], in_spec: torch.utils._pytree.TreeSpec, out_spec: torch.utils._pytree.TreeSpec, forward_arg_names: list[str] | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| replace_all_uses_with(self, original_node, new_node)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'forward_arg_names': list[str] | None, 'in_spec': <...
|
| __dataclass_fields__ = {'forward_arg_names': Field(name='forward_arg_n...
|
| __dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,or...
|
| __hash__ = None
|
| __match_args__ = ('inputs', 'outputs', 'in_spec', 'out_spec', 'forward...
|
| forward_arg_names = None
class ShapesCollection(builtins.object)
| Builder for dynamic_shapes.
| Used to assign dynamic shape specifications to tensors that appear in inputs.
|
| This is useful particularly when :func:`args` is a nested input structure, and it's
| easier to index the input tensors, than to replicate the structure of :func:`args` in
| the :func:`dynamic_shapes` specification.
|
| Example::
|
| args = {"x": tensor_x, "others": [tensor_y, tensor_z]}
|
| dim = torch.export.Dim(...)
| dynamic_shapes = torch.export.ShapesCollection()
| dynamic_shapes[tensor_x] = (dim, dim + 1, 8)
| dynamic_shapes[tensor_y] = {0: dim * 2}
| # This is equivalent to the following (now auto-generated):
| # dynamic_shapes = {"x": (dim, dim + 1, 8), "others": [{0: dim * 2}, None]}
|
| torch.export(..., args, dynamic_shapes=dynamic_shapes)
|
| To specify dynamism for integers, we need to first wrap the integers using
| _IntWrapper so that we have a "unique identification tag" for each integer.
|
| Example::
|
| args = {"x": tensor_x, "others": [int_x, int_y]}
| # Wrap all ints with _IntWrapper
| mapped_args = pytree.tree_map_only(int, lambda a: _IntWrapper(a), args)
|
| dynamic_shapes = torch.export.ShapesCollection()
| dynamic_shapes[tensor_x] = (dim, dim + 1, 8)
| dynamic_shapes[mapped_args["others"][0]] = Dim.DYNAMIC
|
| # This is equivalent to the following (now auto-generated):
| # dynamic_shapes = {"x": (dim, dim + 1, 8), "others": [Dim.DYNAMIC, None]}
|
| torch.export(..., args, dynamic_shapes=dynamic_shapes)
|
| Methods defined here:
|
| __getitem__(self, t)
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| __len__(self)
|
| __setitem__(self, t, shape)
|
| dynamic_shapes(self, m, args, kwargs=None)
| Generates the :func:`dynamic_shapes` pytree structure according to :func:`args` and :func:`kwargs`.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class UnflattenedModule(_SubmoduleBase, torch.nn.modules.module.Module)
| UnflattenedModule(export_module: torch.export.exported_program.ExportedProgram, flat_args_adapter: torch.export.unflatten.FlatArgsAdapter | None = None)
|
| Method resolution order:
| UnflattenedModule
| _SubmoduleBase
| torch.nn.modules.module.Module
| builtins.object
|
| Methods defined here:
|
| __init__(self, export_module: torch.export.exported_program.ExportedProgram, flat_args_adapter: torch.export.unflatten.FlatArgsAdapter | None = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| finalize(self)
|
| forward(self, *args, **kwargs)
| Define the computation performed at every call.
|
| Should be overridden by all subclasses.
|
| .. note::
| Although the recipe for forward pass needs to be defined within
| this function, one should call the :class:`Module` instance afterwards
| instead of this since the former takes care of running the
| registered hooks while the latter silently ignores them.
|
| print_readable(self, print_output=True, include_stride=False, include_device=False, colored=False)
|
| process_forward_inputs(self, *args, **kwargs)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from _SubmoduleBase:
|
| type_name(self) -> str | None
| Subclass of this class - InterpreterModule, InterpreterModuleDispatcher, represents
| corresponding model in eager model. To get this type information for those modules
| in eager model we need to use this method.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _SubmoduleBase:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from torch.nn.modules.module.Module:
|
| __call__ = _wrapped_call_impl(self, *args, **kwargs)
|
| __delattr__(self, name) -> None
| Implement delattr(self, name).
|
| __dir__(self)
| Default dir() implementation.
|
| __getattr__(self, name: str) -> Union[torch.Tensor, ForwardRef('Module')]
| # It is crucial that the return type is not annotated as `Any`, otherwise type checking
| # on `torch.nn.Module` and all its subclasses is largely disabled as a result. See:
| # https://github.com/pytorch/pytorch/pull/115074
|
| __getstate__(self)
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setattr__(self, name: str, value: Union[torch.Tensor, ForwardRef('Module')]) -> None
| Implement setattr(self, name, value).
|
| __setstate__(self, state)
|
| add_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Add a child module to the current module.
|
| The module can be accessed as an attribute using the given name.
|
| Args:
| name (str): name of the child module. The child module can be
| accessed from this module using the given name
| module (Module): child module to be added to the module.
|
| apply(self, fn: collections.abc.Callable[['Module'], None]) -> Self
| Apply ``fn`` recursively to every submodule (as returned by ``.children()``) as well as self.
|
| Typical use includes initializing the parameters of a model
| (see also :ref:`nn-init-doc`).
|
| Args:
| fn (:class:`Module` -> None): function to be applied to each submodule
|
| Returns:
| Module: self
|
| Example::
|
| >>> @torch.no_grad()
| >>> def init_weights(m):
| >>> print(m)
| >>> if type(m) is nn.Linear:
| >>> m.weight.fill_(1.0)
| >>> print(m.weight)
| >>> net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
| >>> net.apply(init_weights)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
|
| bfloat16(self) -> Self
| Casts all floating point parameters and buffers to ``bfloat16`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| buffers(self, recurse: bool = True) -> collections.abc.Iterator[torch.Tensor]
| Return an iterator over module buffers.
|
| Args:
| recurse (bool): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module.
|
| Yields:
| torch.Tensor: module buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for buf in model.buffers():
| >>> print(type(buf), buf.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| children(self) -> collections.abc.Iterator['Module']
| Return an iterator over immediate children modules.
|
| Yields:
| Module: a child module
|
| compile(self, *args, **kwargs) -> None
| Compile this Module's forward using :func:`torch.compile`.
|
| This Module's `__call__` method is compiled and all arguments are passed as-is
| to :func:`torch.compile`.
|
| See :func:`torch.compile` for details on the arguments for this function.
|
| cpu(self) -> Self
| Move all model parameters and buffers to the CPU.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| cuda(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the GPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on GPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| double(self) -> Self
| Casts all floating point parameters and buffers to ``double`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| eval(self) -> Self
| Set the module in evaluation mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e. whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| This is equivalent with :meth:`self.train(False) <torch.nn.Module.train>`.
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.eval()` and several similar mechanisms that may be confused with it.
|
| Returns:
| Module: self
|
| extra_repr(self) -> str
| Return the extra representation of the module.
|
| To print customized extra information, you should re-implement
| this method in your own modules. Both single-line and multi-line
| strings are acceptable.
|
| float(self) -> Self
| Casts all floating point parameters and buffers to ``float`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| get_buffer(self, target: str) -> torch.Tensor
| Return the buffer given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the buffer
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.Tensor: The buffer referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not a
| buffer
|
| get_extra_state(self) -> Any
| Return any extra state to include in the module's state_dict.
|
| Implement this and a corresponding :func:`set_extra_state` for your module
| if you need to store extra state. This function is called when building the
| module's `state_dict()`.
|
| Note that extra state should be picklable to ensure working serialization
| of the state_dict. We only provide backwards compatibility guarantees
| for serializing Tensors; other objects may break backwards compatibility if
| their serialized pickled form changes.
|
| Returns:
| object: Any extra state to store in the module's state_dict
|
| get_parameter(self, target: str) -> torch.nn.parameter.Parameter
| Return the parameter given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the Parameter
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Parameter: The Parameter referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not an
| ``nn.Parameter``
|
| get_submodule(self, target: str) -> 'Module'
| Return the submodule given by ``target`` if it exists, otherwise throw an error.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(16, 33, kernel_size=(3, 3), stride=(2, 2))
| )
| (linear): Linear(in_features=100, out_features=200, bias=True)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` which has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To check whether or not we have the ``linear`` submodule, we
| would call ``get_submodule("net_b.linear")``. To check whether
| we have the ``conv`` submodule, we would call
| ``get_submodule("net_b.net_c.conv")``.
|
| The runtime of ``get_submodule`` is bounded by the degree
| of module nesting in ``target``. A query against
| ``named_modules`` achieves the same result, but it is O(N) in
| the number of transitive modules. So, for a simple check to see
| if some submodule exists, ``get_submodule`` should always be
| used.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Module: The submodule referenced by ``target``
|
| Raises:
| AttributeError: If at any point along the path resulting from
| the target string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| half(self) -> Self
| Casts all floating point parameters and buffers to ``half`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| ipu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the IPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on IPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| load_state_dict(self, state_dict: collections.abc.Mapping[str, typing.Any], strict: bool = True, assign: bool = False)
| Copy parameters and buffers from :attr:`state_dict` into this module and its descendants.
|
| If :attr:`strict` is ``True``, then
| the keys of :attr:`state_dict` must exactly match the keys returned
| by this module's :meth:`~torch.nn.Module.state_dict` function.
|
| .. warning::
| If :attr:`assign` is ``True`` the optimizer must be created after
| the call to :attr:`load_state_dict` unless
| :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| Args:
| state_dict (dict): a dict containing parameters and
| persistent buffers.
| strict (bool, optional): whether to strictly enforce that the keys
| in :attr:`state_dict` match the keys returned by this module's
| :meth:`~torch.nn.Module.state_dict` function. Default: ``True``
| assign (bool, optional): When set to ``False``, the properties of the tensors
| in the current module are preserved whereas setting it to ``True`` preserves
| properties of the Tensors in the state dict. The only
| exception is the ``requires_grad`` field of :class:`~torch.nn.Parameter`
| for which the value from the module is preserved. Default: ``False``
|
| Returns:
| ``NamedTuple`` with ``missing_keys`` and ``unexpected_keys`` fields:
| * ``missing_keys`` is a list of str containing any keys that are expected
| by this module but missing from the provided ``state_dict``.
| * ``unexpected_keys`` is a list of str containing the keys that are not
| expected by this module but present in the provided ``state_dict``.
|
| Note:
| If a parameter or buffer is registered as ``None`` and its corresponding key
| exists in :attr:`state_dict`, :meth:`load_state_dict` will raise a
| ``RuntimeError``.
|
| modules(self, remove_duplicate: bool = True) -> collections.abc.Iterator['Module']
| Return an iterator over all modules in the network.
|
| Args:
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not.
|
| Yields:
| Module: a module in the network
|
| Note:
| Duplicate modules are returned only once by default. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.modules()):
| ... print(idx, '->', m)
|
| 0 -> Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
| 1 -> Linear(in_features=2, out_features=2, bias=True)
|
| mtia(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the MTIA.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on MTIA while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| named_buffers(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.Tensor]]
| Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
|
| Args:
| prefix (str): prefix to prepend to all buffer names.
| recurse (bool, optional): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module. Defaults to True.
| remove_duplicate (bool, optional): whether to remove the duplicated buffers in the result. Defaults to True.
|
| Yields:
| (str, torch.Tensor): Tuple containing the name and buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, buf in self.named_buffers():
| >>> if name in ['running_var']:
| >>> print(buf.size())
|
| named_children(self) -> collections.abc.Iterator[tuple[str, 'Module']]
| Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
|
| Yields:
| (str, Module): Tuple containing a name and child module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, module in model.named_children():
| >>> if name in ['conv4', 'conv5']:
| >>> print(module)
|
| named_modules(self, memo: set['Module'] | None = None, prefix: str = '', remove_duplicate: bool = True)
| Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
|
| Args:
| memo: a memo to store the set of modules already added to the result
| prefix: a prefix that will be added to the name of the module
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not
|
| Yields:
| (str, Module): Tuple of name and module
|
| Note:
| Duplicate modules are returned only once. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.named_modules()):
| ... print(idx, '->', m)
|
| 0 -> ('', Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| ))
| 1 -> ('0', Linear(in_features=2, out_features=2, bias=True))
|
| named_parameters(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.nn.parameter.Parameter]]
| Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
|
| Args:
| prefix (str): prefix to prepend to all parameter names.
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
| remove_duplicate (bool, optional): whether to remove the duplicated
| parameters in the result. Defaults to True.
|
| Yields:
| (str, Parameter): Tuple containing the name and parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, param in self.named_parameters():
| >>> if name in ['bias']:
| >>> print(param.size())
|
| parameters(self, recurse: bool = True) -> collections.abc.Iterator[torch.nn.parameter.Parameter]
| Return an iterator over module parameters.
|
| This is typically passed to an optimizer.
|
| Args:
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
|
| Yields:
| Parameter: module parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for param in model.parameters():
| >>> print(type(param), param.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| register_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None]) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| This function is deprecated in favor of :meth:`~torch.nn.Module.register_full_backward_hook` and
| the behavior of this function will change in future versions.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_buffer(self, name: str, tensor: torch.Tensor | None, persistent: bool = True) -> None
| Add a buffer to the module.
|
| This is typically used to register a buffer that should not be
| considered a model parameter. For example, BatchNorm's ``running_mean``
| is not a parameter, but is part of the module's state. Buffers, by
| default, are persistent and will be saved alongside parameters. This
| behavior can be changed by setting :attr:`persistent` to ``False``. The
| only difference between a persistent buffer and a non-persistent buffer
| is that the latter will not be a part of this module's
| :attr:`state_dict`.
|
| Buffers can be accessed as attributes using given names.
|
| Args:
| name (str): name of the buffer. The buffer can be accessed
| from this module using the given name
| tensor (Tensor or None): buffer to be registered. If ``None``, then operations
| that run on buffers, such as :attr:`cuda`, are ignored. If ``None``,
| the buffer is **not** included in the module's :attr:`state_dict`.
| persistent (bool): whether the buffer is part of this module's
| :attr:`state_dict`.
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> self.register_buffer('running_mean', torch.zeros(num_features))
|
| register_forward_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...], typing.Any], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any], typing.Any], typing.Any | None], *, prepend: bool = False, with_kwargs: bool = False, always_call: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward hook on the module.
|
| The hook will be called every time after :func:`forward` has computed an output.
|
| If ``with_kwargs`` is ``False`` or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| output. It can modify the input inplace but it will not have effect on
| forward since this is called after :func:`forward` is called. The hook
| should have the following signature::
|
| hook(module, args, output) -> None or modified output
|
| If ``with_kwargs`` is ``True``, the forward hook will be passed the
| ``kwargs`` given to the forward function and be expected to return the
| output possibly modified. The hook should have the following signature::
|
| hook(module, args, kwargs, output) -> None or modified output
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If ``True``, the provided ``hook`` will be fired
| before all existing ``forward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``forward`` hooks registered with
| :func:`register_module_forward_hook` will fire before all hooks
| registered by this method.
| Default: ``False``
| with_kwargs (bool): If ``True``, the ``hook`` will be passed the
| kwargs given to the forward function.
| Default: ``False``
| always_call (bool): If ``True`` the ``hook`` will be run regardless of
| whether an exception is raised while calling the Module.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_forward_pre_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...]], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[typing.Any, dict[str, typing.Any]] | None], *, prepend: bool = False, with_kwargs: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward pre-hook on the module.
|
| The hook will be called every time before :func:`forward` is invoked.
|
|
| If ``with_kwargs`` is false or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| input. User can either return a tuple or a single modified value in the
| hook. We will wrap the value into a tuple if a single value is returned
| (unless that value is already a tuple). The hook should have the
| following signature::
|
| hook(module, args) -> None or modified input
|
| If ``with_kwargs`` is true, the forward pre-hook will be passed the
| kwargs given to the forward function. And if the hook modifies the
| input, both the args and kwargs should be returned. The hook should have
| the following signature::
|
| hook(module, args, kwargs) -> None or a tuple of modified input and kwargs
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``forward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``forward_pre`` hooks registered with
| :func:`register_module_forward_pre_hook` will fire before all
| hooks registered by this method.
| Default: ``False``
| with_kwargs (bool): If true, the ``hook`` will be passed the kwargs
| given to the forward function.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| The hook will be called every time the gradients with respect to a module are computed, and its firing rules are as follows:
|
| 1. Ordinarily, the hook fires when the gradients are computed with respect to the module inputs.
| 2. If none of the module inputs require gradients, the hook will fire when the gradients are computed
| with respect to module outputs.
| 3. If none of the module outputs require gradients, then the hooks will not fire.
|
| The hook should have the following signature::
|
| hook(module, grad_input, grad_output) -> tuple(Tensor) or None
|
| The :attr:`grad_input` and :attr:`grad_output` are tuples that contain the gradients
| with respect to the inputs and outputs respectively. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the input that will be used in place of :attr:`grad_input` in
| subsequent computations. :attr:`grad_input` will only correspond to the inputs given
| as positional arguments and all kwarg arguments are ignored. Entries
| in :attr:`grad_input` and :attr:`grad_output` will be ``None`` for all non-Tensor
| arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs or outputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``backward`` hooks registered with
| :func:`register_module_full_backward_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_pre_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward pre-hook on the module.
|
| The hook will be called every time the gradients for the module are computed.
| The hook should have the following signature::
|
| hook(module, grad_output) -> tuple[Tensor, ...], Tensor or None
|
| The :attr:`grad_output` is a tuple. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the output that will be used in place of :attr:`grad_output` in
| subsequent computations. Entries in :attr:`grad_output` will be ``None`` for
| all non-Tensor arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``backward_pre`` hooks registered with
| :func:`register_module_full_backward_pre_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_post_hook(self, hook)
| Register a post-hook to be run after module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, incompatible_keys) -> None
|
| The ``module`` argument is the current module that this hook is registered
| on, and the ``incompatible_keys`` argument is a ``NamedTuple`` consisting
| of attributes ``missing_keys`` and ``unexpected_keys``. ``missing_keys``
| is a ``list`` of ``str`` containing the missing keys and
| ``unexpected_keys`` is a ``list`` of ``str`` containing the unexpected keys.
|
| The given incompatible_keys can be modified inplace if needed.
|
| Note that the checks performed when calling :func:`load_state_dict` with
| ``strict=True`` are affected by modifications the hook makes to
| ``missing_keys`` or ``unexpected_keys``, as expected. Additions to either
| set of keys will result in an error being thrown when ``strict=True``, and
| clearing out both missing and unexpected keys will avoid an error.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook)
| Register a pre-hook to be run before module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) -> None # noqa: B950
|
| Arguments:
| hook (Callable): Callable hook that will be invoked before
| loading the state dict.
|
| register_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Alias for :func:`add_module`.
|
| register_parameter(self, name: str, param: torch.nn.parameter.Parameter | None) -> None
| Add a parameter to the module.
|
| The parameter can be accessed as an attribute using given name.
|
| Args:
| name (str): name of the parameter. The parameter can be accessed
| from this module using the given name
| param (Parameter or None): parameter to be added to the module. If
| ``None``, then operations that run on parameters, such as :attr:`cuda`,
| are ignored. If ``None``, the parameter is **not** included in the
| module's :attr:`state_dict`.
|
| register_state_dict_post_hook(self, hook)
| Register a post-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata) -> None
|
| The registered hooks can modify the ``state_dict`` inplace.
|
| register_state_dict_pre_hook(self, hook)
| Register a pre-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, prefix, keep_vars) -> None
|
| The registered hooks can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| requires_grad_(self, requires_grad: bool = True) -> Self
| Change if autograd should record operations on parameters in this module.
|
| This method sets the parameters' :attr:`requires_grad` attributes
| in-place.
|
| This method is helpful for freezing part of the module for finetuning
| or training parts of a model individually (e.g., GAN training).
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.requires_grad_()` and several similar mechanisms that may be confused with it.
|
| Args:
| requires_grad (bool): whether autograd should record operations on
| parameters in this module. Default: ``True``.
|
| Returns:
| Module: self
|
| set_extra_state(self, state: Any) -> None
| Set extra state contained in the loaded `state_dict`.
|
| This function is called from :func:`load_state_dict` to handle any extra state
| found within the `state_dict`. Implement this function and a corresponding
| :func:`get_extra_state` for your module if you need to store extra state within its
| `state_dict`.
|
| Args:
| state (dict): Extra state from the `state_dict`
|
| set_submodule(self, target: str, module: 'Module', strict: bool = False) -> None
| Set the submodule given by ``target`` if it exists, otherwise throw an error.
|
| .. note::
| If ``strict`` is set to ``False`` (default), the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``strict`` is set to ``True``,
| the method will only attempt to replace an existing submodule and throw an error if
| the submodule does not exist.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(3, 3, 3)
| )
| (linear): Linear(3, 3)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To override the ``Conv2d`` with a new submodule ``Linear``, you
| could call ``set_submodule("net_b.net_c.conv", nn.Linear(1, 1))``
| where ``strict`` could be ``True`` or ``False``
|
| To add a new submodule ``Conv2d`` to the existing ``net_b`` module,
| you would call ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1))``.
|
| In the above if you set ``strict=True`` and call
| ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1), strict=True)``, an AttributeError
| will be raised because ``net_b`` does not have a submodule named ``conv``.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
| module: The module to set the submodule to.
| strict: If ``False``, the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``True``,
| the method will only attempt to replace an existing submodule and throw an error
| if the submodule doesn't already exist.
|
| Raises:
| ValueError: If the ``target`` string is empty or if ``module`` is not an instance of ``nn.Module``.
| AttributeError: If at any point along the path resulting from
| the ``target`` string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| share_memory(self) -> Self
| See :meth:`torch.Tensor.share_memory_`.
|
| state_dict(self, *args, destination=None, prefix='', keep_vars=False)
| Return a dictionary containing references to the whole state of the module.
|
| Both parameters and persistent buffers (e.g. running averages) are
| included. Keys are corresponding parameter and buffer names.
| Parameters and buffers set to ``None`` are not included.
|
| .. note::
| The returned object is a shallow copy. It contains references
| to the module's parameters and buffers.
|
| .. warning::
| Currently ``state_dict()`` also accepts positional arguments for
| ``destination``, ``prefix`` and ``keep_vars`` in order. However,
| this is being deprecated and keyword arguments will be enforced in
| future releases.
|
| .. warning::
| Please avoid the use of argument ``destination`` as it is not
| designed for end-users.
|
| Args:
| destination (dict, optional): If provided, the state of module will
| be updated into the dict and the same object is returned.
| Otherwise, an ``OrderedDict`` will be created and returned.
| Default: ``None``.
| prefix (str, optional): a prefix added to parameter and buffer
| names to compose the keys in state_dict. Default: ``''``.
| keep_vars (bool, optional): by default the :class:`~torch.Tensor` s
| returned in the state dict are detached from autograd. If it's
| set to ``True``, detaching will not be performed.
| Default: ``False``.
|
| Returns:
| dict:
| a dictionary containing a whole state of the module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> module.state_dict().keys()
| ['bias', 'weight']
|
| to(self, *args, **kwargs)
| Move and/or cast the parameters and buffers.
|
| This can be called as
|
| .. function:: to(device=None, dtype=None, non_blocking=False)
| :noindex:
|
| .. function:: to(dtype, non_blocking=False)
| :noindex:
|
| .. function:: to(tensor, non_blocking=False)
| :noindex:
|
| .. function:: to(memory_format=torch.channels_last)
| :noindex:
|
| Its signature is similar to :meth:`torch.Tensor.to`, but only accepts
| floating point or complex :attr:`dtype`\ s. In addition, this method will
| only cast the floating point or complex parameters and buffers to :attr:`dtype`
| (if given). The integral parameters and buffers will be moved
| :attr:`device`, if that is given, but with dtypes unchanged. When
| :attr:`non_blocking` is set, it tries to convert/move asynchronously
| with respect to the host if possible, e.g., moving CPU Tensors with
| pinned memory to CUDA devices.
|
| See below for examples.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (:class:`torch.device`): the desired device of the parameters
| and buffers in this module
| dtype (:class:`torch.dtype`): the desired floating point or complex dtype of
| the parameters and buffers in this module
| tensor (torch.Tensor): Tensor whose dtype and device are the desired
| dtype and device for all parameters and buffers in this module
| memory_format (:class:`torch.memory_format`): the desired memory
| format for 4D parameters and buffers in this module (keyword
| only argument)
|
| Returns:
| Module: self
|
| Examples::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> linear = nn.Linear(2, 2)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]])
| >>> linear.to(torch.double)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]], dtype=torch.float64)
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA1)
| >>> gpu1 = torch.device("cuda:1")
| >>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
| >>> cpu = torch.device("cpu")
| >>> linear.to(cpu)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16)
|
| >>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.3741+0.j, 0.2382+0.j],
| [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
| >>> linear(torch.ones(3, 2, dtype=torch.cdouble))
| tensor([[0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
|
| to_empty(self, *, device: str | torch.device | int | None, recurse: bool = True) -> Self
| Move the parameters and buffers to the specified device without copying storage.
|
| Args:
| device (:class:`torch.device`): The desired device of the parameters
| and buffers in this module.
| recurse (bool): Whether parameters and buffers of submodules should
| be recursively moved to the specified device.
|
| Returns:
| Module: self
|
| train(self, mode: bool = True) -> Self
| Set the module in training mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e., whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| Args:
| mode (bool): whether to set training mode (``True``) or evaluation
| mode (``False``). Default: ``True``.
|
| Returns:
| Module: self
|
| type(self, dst_type: torch.dtype | str) -> Self
| Casts all parameters and buffers to :attr:`dst_type`.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| dst_type (type or string): the desired type
|
| Returns:
| Module: self
|
| xpu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the XPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing optimizer if the module will
| live on XPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset gradients of all model parameters.
|
| See similar function under :class:`torch.optim.Optimizer` for more context.
|
| Args:
| set_to_none (bool): instead of setting to zero, set the grads to None.
| See :meth:`torch.optim.Optimizer.zero_grad` for details.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.nn.modules.module.Module:
|
| T_destination = ~T_destination
|
| call_super_init = False
|
| dump_patches = False
FUNCTIONS
default_decompositions() -> 'CustomDecompTable'
This is the default decomposition table which contains decomposition of
all ATEN operators to core aten opset. Use this API together with
:func:`run_decompositions()`
dims(*names: str, min: int | None = None, max: int | None = None) -> tuple[torch.export.dynamic_shapes.Dim, ...]
Util to create multiple :func:`Dim` types.
Returns:
A tuple of :func:`Dim` types.
draft_export(mod: torch.nn.modules.module.Module, args: tuple[typing.Any, ...], kwargs: collections.abc.Mapping[str, typing.Any] | None = None, *, dynamic_shapes: dict[str, typing.Any] | tuple[typing.Any, ...] | list[typing.Any] | None = None, preserve_module_call_signature: tuple[str, ...] = (), strict: bool = False, prefer_deferred_runtime_asserts_over_guards: bool = False) -> torch.export.exported_program.ExportedProgram
A version of torch.export.export which is designed to consistently produce
an ExportedProgram, even if there are potential soundness issues, and to
generate a report listing the issues found.
export(mod: torch.nn.modules.module.Module, args: tuple[typing.Any, ...], kwargs: collections.abc.Mapping[str, typing.Any] | None = None, *, dynamic_shapes: dict[str, typing.Any] | tuple[typing.Any, ...] | list[typing.Any] | None = None, strict: bool = False, preserve_module_call_signature: tuple[str, ...] = (), prefer_deferred_runtime_asserts_over_guards: bool = False) -> torch.export.exported_program.ExportedProgram
:func:`export` takes any nn.Module along with example inputs, and produces a traced graph representing
only the Tensor computation of the function in an Ahead-of-Time (AOT) fashion,
which can subsequently be executed with different inputs or serialized. The
traced graph (1) produces normalized operators in the functional ATen operator set
(as well as any user-specified custom operators), (2) has eliminated all Python control
flow and data structures (with certain exceptions), and (3) records the set of
shape constraints needed to show that this normalization and control-flow elimination
is sound for future inputs.
**Soundness Guarantee**
While tracing, :func:`export()` takes note of shape-related assumptions
made by the user program and the underlying PyTorch operator kernels.
The output :class:`ExportedProgram` is considered valid only when these
assumptions hold true.
Tracing makes assumptions on the shapes (not values) of input tensors.
Such assumptions must be validated at graph capture time for :func:`export`
to succeed. Specifically:
- Assumptions on static shapes of input tensors are automatically validated without additional effort.
- Assumptions on dynamic shape of input tensors require explicit specification
by using the :func:`Dim` API to construct dynamic dimensions and by associating
them with example inputs through the ``dynamic_shapes`` argument.
If any assumption can not be validated, a fatal error will be raised. When that happens,
the error message will include suggested fixes to the specification that are needed
to validate the assumptions. For example :func:`export` might suggest the
following fix to the definition of a dynamic dimension ``dim0_x``, say appearing in the
shape associated with input ``x``, that was previously defined as ``Dim("dim0_x")``::
dim = Dim("dim0_x", max=5)
This example means the generated code requires dimension 0 of input ``x`` to be less
than or equal to 5 to be valid. You can inspect the suggested fixes to dynamic dimension
definitions and then copy them verbatim into your code without needing to change the
``dynamic_shapes`` argument to your :func:`export` call.
Args:
mod: We will trace the forward method of this module.
args: Example positional inputs.
kwargs: Optional example keyword inputs.
dynamic_shapes:
An optional argument where the type should either be:
1) a dict from argument names of ``f`` to their dynamic shape specifications,
2) a tuple that specifies dynamic shape specifications for each input in original order.
If you are specifying dynamism on keyword args, you will need to pass them in the order that
is defined in the original function signature.
The dynamic shape of a tensor argument can be specified as either
(1) a dict from dynamic dimension indices to :func:`Dim` types, where it is
not required to include static dimension indices in this dict, but when they are,
they should be mapped to None; or (2) a tuple / list of :func:`Dim` types or None,
where the :func:`Dim` types correspond to dynamic dimensions, and static dimensions
are denoted by None. Arguments that are dicts or tuples / lists of tensors are
recursively specified by using mappings or sequences of contained specifications.
strict: When disabled (default), the export function will trace the program through
Python runtime, which by itself will not validate some of the implicit assumptions
baked into the graph. It will still validate most critical assumptions like shape
safety. When enabled (by setting ``strict=True``), the export function will trace
the program through TorchDynamo which will ensure the soundness of the resulting
graph. TorchDynamo has limited Python feature coverage, thus you may experience more
errors. Note that toggling this argument does not affect the resulting IR spec to be
different and the model will be serialized in the same way regardless of what value
is passed here.
preserve_module_call_signature: A list of submodule paths for which the original
calling conventions are preserved as metadata. The metadata will be used when calling
torch.export.unflatten to preserve the original calling conventions of modules.
Returns:
An :class:`ExportedProgram` containing the traced callable.
**Acceptable input/output types**
Acceptable types of inputs (for ``args`` and ``kwargs``) and outputs include:
- Primitive types, i.e. ``torch.Tensor``, ``int``, ``float``, ``bool`` and ``str``.
- Dataclasses, but they must be registered by calling :func:`register_dataclass` first.
- (Nested) Data structures comprising of ``dict``, ``list``, ``tuple``, ``namedtuple`` and
``OrderedDict`` containing all above types.
load(f: Union[str, os.PathLike[str], IO[bytes]], *, extra_files: dict[str, typing.Any] | None = None, expected_opset_version: dict[str, int] | None = None) -> torch.export.exported_program.ExportedProgram
.. warning::
Under active development, saved files may not be usable in newer versions
of PyTorch.
.. warning::
:func:`torch.export.load()` uses pickle under the hood to load models. **Never load data from an untrusted source.**
Loads an :class:`ExportedProgram` previously saved with
:func:`torch.export.save <torch.export.save>`.
Args:
f (str | os.PathLike[str] | IO[bytes]): A file-like object (has to
implement write and flush) or a string containing a file name.
extra_files (Optional[Dict[str, Any]]): The extra filenames given in
this map would be loaded and their content would be stored in the
provided map.
expected_opset_version (Optional[Dict[str, int]]): A map of opset names
to expected opset versions
Returns:
An :class:`ExportedProgram` object
Example::
import torch
import io
# Load ExportedProgram from file
ep = torch.export.load("exported_program.pt2")
# Load ExportedProgram from io.BytesIO object
with open("exported_program.pt2", "rb") as f:
buffer = io.BytesIO(f.read())
buffer.seek(0)
ep = torch.export.load(buffer)
# Load with extra files.
extra_files = {"foo.txt": ""} # values will be replaced with data
ep = torch.export.load("exported_program.pt2", extra_files=extra_files)
print(extra_files["foo.txt"])
print(ep(torch.randn(5)))
register_dataclass(cls: type[typing.Any], *, serialized_type_name: str | None = None) -> None
Registers a dataclass as a valid input/output type for :func:`torch.export.export`.
Args:
cls: the dataclass type to register
serialized_type_name: The serialized name for the dataclass. This is
required if you want to serialize the pytree TreeSpec containing this
dataclass.
Example::
import torch
from dataclasses import dataclass
@dataclass
class InputDataClass:
feature: torch.Tensor
bias: int
@dataclass
class OutputDataClass:
res: torch.Tensor
torch.export.register_dataclass(InputDataClass)
torch.export.register_dataclass(OutputDataClass)
class Mod(torch.nn.Module):
def forward(self, x: InputDataClass) -> OutputDataClass:
res = x.feature + x.bias
return OutputDataClass(res=res)
ep = torch.export.export(Mod(), (InputDataClass(torch.ones(2, 2), 1),))
print(ep)
save(ep: torch.export.exported_program.ExportedProgram, f: Union[str, os.PathLike[str], IO[bytes]], *, extra_files: dict[str, typing.Any] | None = None, opset_version: dict[str, int] | None = None, pickle_protocol: int = 2) -> None
.. warning::
Under active development, saved files may not be usable in newer versions
of PyTorch.
Saves an :class:`ExportedProgram` to a file-like object. It can then be
loaded using the Python API :func:`torch.export.load <torch.export.load>`.
Args:
ep (ExportedProgram): The exported program to save.
f (str | os.PathLike[str] | IO[bytes]) A file-like object (has to
implement write and flush) or a string containing a file name.
extra_files (Optional[Dict[str, Any]]): Map from filename to contents
which will be stored as part of f.
opset_version (Optional[Dict[str, int]]): A map of opset names
to the version of this opset
pickle_protocol: can be specified to override the default protocol
Example::
import torch
import io
class MyModule(torch.nn.Module):
def forward(self, x):
return x + 10
ep = torch.export.export(MyModule(), (torch.randn(5),))
# Save to file
torch.export.save(ep, "exported_program.pt2")
# Save to io.BytesIO buffer
buffer = io.BytesIO()
torch.export.save(ep, buffer)
# Save with extra files
extra_files = {"foo.txt": b"bar".decode("utf-8")}
torch.export.save(ep, "exported_program.pt2", extra_files=extra_files)
unflatten(module: torch.export.exported_program.ExportedProgram, flat_args_adapter: torch.export.unflatten.FlatArgsAdapter | None = None) -> torch.export.unflatten.UnflattenedModule
Unflatten an ExportedProgram, producing a module with the same module
hierarchy as the original eager module. This can be useful if you are trying
to use :mod:`torch.export` with another system that expects a module
hierarchy instead of the flat graph that :mod:`torch.export` usually produces.
.. note:: The args/kwargs of unflattened modules will not necessarily match
the eager module, so doing a module swap (e.g. :code:`self.submod =
new_mod`) will not necessarily work. If you need to swap a module out, you
need to set the :code:`preserve_module_call_signature` parameter of
:func:`torch.export.export`.
Args:
module (ExportedProgram): The ExportedProgram to unflatten.
flat_args_adapter (Optional[FlatArgsAdapter]): Adapt flat args if input TreeSpec does not match with exported module's.
Returns:
An instance of :class:`UnflattenedModule`, which has the same module
hierarchy as the original eager module pre-export.
DATA
Constraint = torch.export.dynamic_shapes._Constraint | torch.... | tor...
__all__ = ['AdditionalInputs', 'Constraint', 'CustomDecompTable', 'def...
__annotations__ = {'log': <class 'logging.Logger'>}
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\export\__init__.py
torch.eye
Python Library Documentation: built-in function eye in module torch
eye(...)
eye(n, m=None, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.
Args:
n (int): the number of rows
m (int, optional): the number of columns with default being :attr:`n`
Keyword arguments:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 2-D tensor with ones on the diagonal and zeros elsewhere
Example::
>>> torch.eye(3)
tensor([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
torch.fake_quantize_per_channel_affine
Python Library Documentation: built-in function fake_quantize_per_channel_affine in module torch
fake_quantize_per_channel_affine(...)
fake_quantize_per_channel_affine(input, scale, zero_point, axis, quant_min, quant_max) -> Tensor
Returns a new tensor with the data in :attr:`input` fake quantized per channel using :attr:`scale`,
:attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`, across the channel specified by :attr:`axis`.
.. math::
\text{output} = (
min(
\text{quant\_max},
max(
\text{quant\_min},
\text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
)
) - \text{zero\_point}
) \times \text{scale}
Args:
input (Tensor): the input value(s), in ``torch.float32``
scale (Tensor): quantization scale, per channel in ``torch.float32``
zero_point (Tensor): quantization zero_point, per channel in ``torch.int32`` or ``torch.half`` or ``torch.float32``
axis (int32): channel axis
quant_min (int64): lower bound of the quantized domain
quant_max (int64): upper bound of the quantized domain
Returns:
Tensor: A newly fake_quantized per channel ``torch.float32`` tensor
Example::
>>> x = torch.randn(2, 2, 2)
>>> x
tensor([[[-0.2525, -0.0466],
[ 0.3491, -0.2168]],
[[-0.5906, 1.6258],
[ 0.6444, -0.0542]]])
>>> scales = (torch.randn(2) + 1) * 0.05
>>> scales
tensor([0.0475, 0.0486])
>>> zero_points = torch.zeros(2).to(torch.int32)
>>> zero_points
tensor([0, 0])
>>> torch.fake_quantize_per_channel_affine(x, scales, zero_points, 1, 0, 255)
tensor([[[0.0000, 0.0000],
[0.3405, 0.0000]],
[[0.0000, 1.6134],
[0.6323, 0.0000]]])
torch.fake_quantize_per_tensor_affine
Python Library Documentation: built-in function fake_quantize_per_tensor_affine in module torch
fake_quantize_per_tensor_affine(...)
fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max) -> Tensor
Returns a new tensor with the data in :attr:`input` fake quantized using :attr:`scale`,
:attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`.
.. math::
\text{output} = (
min(
\text{quant\_max},
max(
\text{quant\_min},
\text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
)
) - \text{zero\_point}
) \times \text{scale}
Args:
input (Tensor): the input value(s), ``torch.float32`` tensor
scale (double scalar or ``float32`` Tensor): quantization scale
zero_point (int64 scalar or ``int32`` Tensor): quantization zero_point
quant_min (int64): lower bound of the quantized domain
quant_max (int64): upper bound of the quantized domain
Returns:
Tensor: A newly fake_quantized ``torch.float32`` tensor
Example::
>>> x = torch.randn(4)
>>> x
tensor([ 0.0552, 0.9730, 0.3973, -1.0780])
>>> torch.fake_quantize_per_tensor_affine(x, 0.1, 0, 0, 255)
tensor([0.1000, 1.0000, 0.4000, 0.0000])
>>> torch.fake_quantize_per_tensor_affine(x, torch.tensor(0.1), torch.tensor(0), 0, 255)
tensor([0.1000, 1.0000, 0.4000, 0.0000])
torch.fbgemm_linear_fp16_weight
Python Library Documentation: built-in function fbgemm_linear_fp16_weight in module torch fbgemm_linear_fp16_weight(...)
torch.fbgemm_linear_fp16_weight_fp32_activation
Python Library Documentation: built-in function fbgemm_linear_fp16_weight_fp32_activation in module torch fbgemm_linear_fp16_weight_fp32_activation(...)
torch.fbgemm_linear_int8_weight
Python Library Documentation: built-in function fbgemm_linear_int8_weight in module torch fbgemm_linear_int8_weight(...)
torch.fbgemm_linear_int8_weight_fp32_activation
Python Library Documentation: built-in function fbgemm_linear_int8_weight_fp32_activation in module torch fbgemm_linear_int8_weight_fp32_activation(...)
torch.fbgemm_linear_quantize_weight
Python Library Documentation: built-in function fbgemm_linear_quantize_weight in module torch fbgemm_linear_quantize_weight(...)
torch.fbgemm_pack_gemm_matrix_fp16
Python Library Documentation: built-in function fbgemm_pack_gemm_matrix_fp16 in module torch fbgemm_pack_gemm_matrix_fp16(...)
torch.fbgemm_pack_quantized_matrix
Python Library Documentation: built-in function fbgemm_pack_quantized_matrix in module torch fbgemm_pack_quantized_matrix(...)
torch.feature_alpha_dropout
Python Library Documentation: built-in function feature_alpha_dropout in module torch feature_alpha_dropout(...)
torch.feature_alpha_dropout_
Python Library Documentation: built-in function feature_alpha_dropout_ in module torch feature_alpha_dropout_(...)
torch.feature_dropout
Python Library Documentation: built-in function feature_dropout in module torch feature_dropout(...)
torch.feature_dropout_
Python Library Documentation: built-in function feature_dropout_ in module torch feature_dropout_(...)
torch.fft
Python Library Documentation: package torch.fft in torch
NAME
torch.fft
PACKAGE CONTENTS
CLASSES
torch._C.TensorBase(builtins.object)
torch.Tensor
class Tensor(torch._C.TensorBase)
| Method resolution order:
| Tensor
| torch._C.TensorBase
| builtins.object
|
| Methods defined here:
|
| __abs__ = abs(...)
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __neg__ = neg(...)
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| solve(self, other) from torch._tensor.Tensor
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C.TensorBase:
|
| __add__(...)
|
| __and__(...)
|
| __bool__(...)
|
| __complex__(...)
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __div__(...)
|
| __eq__(...)
| Return self==value.
|
| __float__(...)
|
| __ge__(...)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(...)
| Return self>value.
|
| __iadd__(...)
|
| __iand__(...)
|
| __idiv__(...)
|
| __ifloordiv__(...)
|
| __ilshift__(...)
|
| __imod__(...)
|
| __imul__(...)
|
| __index__(...)
|
| __int__(...)
|
| __invert__(...)
|
| __ior__(...)
|
| __irshift__(...)
|
| __isub__(...)
|
| __ixor__(...)
|
| __le__(...)
| Return self<=value.
|
| __long__(...)
|
| __lshift__(...)
|
| __lt__(...)
| Return self<value.
|
| __matmul__(...)
|
| __mod__(...)
|
| __mul__(...)
|
| __ne__(...)
| Return self!=value.
|
| __nonzero__(...)
|
| __or__(...)
| Return self|value.
|
| __radd__(...)
|
| __rand__(...)
|
| __rmul__(...)
|
| __ror__(...)
| Return value|self.
|
| __rshift__(...)
|
| __rxor__(...)
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sub__(...)
|
| __truediv__(...)
|
| __xor__(...)
|
| abs(...)
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...)
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...)
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...)
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...)
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...)
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...)
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...)
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...)
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...)
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...)
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...)
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...)
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...)
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...)
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...)
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...)
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...)
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...)
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...)
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...)
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...)
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...)
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...)
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...)
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...)
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...)
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...)
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...)
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...)
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...)
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...)
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...)
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...)
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...)
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...)
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...)
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...)
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...)
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...)
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...)
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...)
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...)
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...)
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...)
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...)
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...)
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...)
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...)
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...)
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...)
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...)
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...)
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...)
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...)
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...)
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...)
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...)
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...)
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| baddbmm(...)
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...)
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...)
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...)
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...)
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...)
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...)
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...)
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...)
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...)
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...)
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...)
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...)
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...)
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...)
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...)
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...)
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...)
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...)
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...)
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...)
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...)
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...)
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...)
|
| cdouble(...)
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...)
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...)
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...)
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...)
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...)
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...)
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...)
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...)
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...)
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...)
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...)
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...)
|
| clamp_max_(...)
|
| clamp_min(...)
|
| clamp_min_(...)
|
| clip(...)
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...)
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...)
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...)
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...)
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...)
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...)
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...)
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...)
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...)
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...)
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...)
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...)
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...)
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...)
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...)
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...)
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...)
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...)
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...)
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...)
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...)
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...)
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...)
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...)
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...)
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...)
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...)
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...)
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...)
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...)
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...)
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...)
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...)
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...)
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...)
| det() -> Tensor
|
| See :func:`torch.det`
|
| diag(...)
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...)
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...)
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...)
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...)
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...)
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...)
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...)
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...)
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dist(...)
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...)
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...)
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...)
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...)
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...)
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...)
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...)
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| element_size(...)
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...)
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...)
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...)
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...)
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...)
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...)
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...)
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...)
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...)
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...)
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...)
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...)
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...)
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...)
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...)
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...)
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...)
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...)
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...)
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...)
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...)
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...)
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...)
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...)
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...)
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...)
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...)
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...)
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...)
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...)
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...)
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...)
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...)
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...)
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...)
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...)
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...)
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...)
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...)
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...)
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...)
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...)
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...)
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...)
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...)
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...)
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...)
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...)
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...)
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...)
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...)
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...)
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...)
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...)
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...)
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...)
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...)
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...)
|
| heaviside(...)
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...)
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...)
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...)
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...)
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...)
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...)
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...)
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...)
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...)
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...)
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...)
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...)
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index_add(...)
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...)
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...)
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...)
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...)
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...)
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...)
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...)
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...)
|
| index_reduce_(...)
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...)
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...)
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...)
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...)
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...)
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...)
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...)
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...)
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...)
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...)
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...)
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...)
|
| is_floating_point(...)
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...)
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...)
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...)
|
| is_pinned(...)
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...)
|
| is_set_to(...)
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_signed(...)
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...)
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...)
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...)
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...)
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...)
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...)
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...)
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| item(...)
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...)
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...)
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...)
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...)
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...)
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...)
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...)
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...)
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...)
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...)
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...)
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...)
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...)
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...)
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...)
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...)
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...)
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...)
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...)
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...)
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...)
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...)
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...)
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...)
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...)
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...)
|
| logaddexp(...)
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...)
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...)
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...)
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...)
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...)
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...)
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...)
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...)
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...)
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...)
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...)
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...)
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...)
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...)
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...)
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lt(...)
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...)
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu_solve(...)
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...)
|
| map_(...)
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...)
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...)
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...)
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...)
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...)
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...)
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...)
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...)
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...)
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...)
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...)
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...)
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...)
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...)
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...)
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...)
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| moveaxis(...)
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...)
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...)
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...)
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...)
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...)
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...)
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...)
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...)
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...)
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...)
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...)
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...)
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...)
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...)
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...)
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...)
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...)
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...)
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...)
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...)
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...)
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...)
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...)
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...)
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...)
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...)
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...)
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...)
|
| new_empty(...)
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...)
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...)
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...)
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...)
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...)
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...)
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...)
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...)
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...)
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| normal_(...)
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...)
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...)
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...)
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...)
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...)
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...)
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...)
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...)
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...)
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...)
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...)
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...)
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...)
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...)
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...)
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...)
|
| prod(...)
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...)
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...)
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...)
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...)
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...)
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...)
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...)
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...)
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...)
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...)
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...)
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...)
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...)
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...)
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...)
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...)
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...)
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| relu(...)
|
| relu_(...)
|
| remainder(...)
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...)
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...)
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...)
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...)
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...)
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...)
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...)
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...)
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize_(...)
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as_(...)
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...)
|
| resolve_conj(...)
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...)
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...)
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...)
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...)
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...)
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...)
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...)
|
| rsqrt(...)
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...)
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...)
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...)
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...)
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...)
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...)
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...)
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...)
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...)
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...)
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...)
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...)
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| short(...)
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...)
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...)
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...)
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...)
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...)
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...)
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...)
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...)
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...)
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...)
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...)
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...)
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...)
|
| slice_scatter(...)
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...)
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...)
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...)
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| sort(...)
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...)
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...)
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...)
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...)
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split_with_sizes(...)
|
| sqrt(...)
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...)
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...)
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...)
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...)
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...)
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...)
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...)
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| storage_offset(...)
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| stride(...)
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...)
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...)
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...)
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...)
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...)
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...)
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...)
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...)
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...)
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...)
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...)
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| t(...)
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...)
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...)
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...)
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...)
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...)
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...)
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...)
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...)
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...)
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...)
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...)
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...)
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...)
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...)
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...)
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...)
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_csc(...)
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...)
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...)
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...)
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...)
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...)
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...)
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...)
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...)
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...)
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...)
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...)
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...)
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...)
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...)
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...)
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...)
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...)
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...)
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unfold(...)
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...)
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unsafe_chunk(...)
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...)
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...)
|
| unsqueeze(...)
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...)
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...)
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...)
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...)
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...)
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...)
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...)
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...)
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...)
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...)
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...)
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...)
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...)
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch._C.TensorBase:
|
| __new__(*args, **kwargs) class method of torch._C.TensorBase
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C.TensorBase:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| dtype
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_cuda
| Is ``True`` if the Tensor is stored on the GPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_sparse
| Is ``True`` if the Tensor uses sparse COO storage layout, ``False`` otherwise.
|
| is_sparse_csr
| Is ``True`` if the Tensor uses sparse CSR storage layout, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| is_xpu
| Is ``True`` if the Tensor is stored on the XPU, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| layout
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
FUNCTIONS
fft = fft_fft(...)
fft(input, n=None, dim=-1, norm=None, *, out=None) -> Tensor
Computes the one dimensional discrete Fourier transform of :attr:`input`.
Note:
The Fourier domain representation of any real signal satisfies the
Hermitian property: `X[i] = conj(X[-i])`. This function always returns both
the positive and negative frequency terms even though, for real inputs, the
negative frequencies are redundant. :func:`~torch.fft.rfft` returns the
more compact one-sided representation where only the positive frequencies
are returned.
Note:
Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimension.
Args:
input (Tensor): the input tensor
n (int, optional): Signal length. If given, the input will either be zero-padded
or trimmed to this length before computing the FFT.
dim (int, optional): The dimension along which to take the one dimensional FFT.
norm (str, optional): Normalization mode. For the forward transform
(:func:`~torch.fft.fft`), these correspond to:
* ``"forward"`` - normalize by ``1/n``
* ``"backward"`` - no normalization
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the FFT orthonormal)
Calling the backward transform (:func:`~torch.fft.ifft`) with the same
normalization mode will apply an overall normalization of ``1/n`` between
the two transforms. This is required to make :func:`~torch.fft.ifft`
the exact inverse.
Default is ``"backward"`` (no normalization).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> t = torch.arange(4)
>>> t
tensor([0, 1, 2, 3])
>>> torch.fft.fft(t)
tensor([ 6.+0.j, -2.+2.j, -2.+0.j, -2.-2.j])
>>> t = torch.tensor([0.+1.j, 2.+3.j, 4.+5.j, 6.+7.j])
>>> torch.fft.fft(t)
tensor([12.+16.j, -8.+0.j, -4.-4.j, 0.-8.j])
fft2 = fft_fft2(...)
fft2(input, s=None, dim=(-2, -1), norm=None, *, out=None) -> Tensor
Computes the 2 dimensional discrete Fourier transform of :attr:`input`.
Equivalent to :func:`~torch.fft.fftn` but FFTs only the last two dimensions by default.
Note:
The Fourier domain representation of any real signal satisfies the
Hermitian property: ``X[i, j] = conj(X[-i, -j])``. This
function always returns all positive and negative frequency terms even
though, for real inputs, half of these values are redundant.
:func:`~torch.fft.rfft2` returns the more compact one-sided representation
where only the positive frequencies of the last dimension are returned.
Note:
Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimensions.
Args:
input (Tensor): the input tensor
s (Tuple[int], optional): Signal size in the transformed dimensions.
If given, each dimension ``dim[i]`` will either be zero-padded or
trimmed to the length ``s[i]`` before computing the FFT.
If a length ``-1`` is specified, no padding is done in that dimension.
Default: ``s = [input.size(d) for d in dim]``
dim (Tuple[int], optional): Dimensions to be transformed.
Default: last two dimensions.
norm (str, optional): Normalization mode. For the forward transform
(:func:`~torch.fft.fft2`), these correspond to:
* ``"forward"`` - normalize by ``1/n``
* ``"backward"`` - no normalization
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the FFT orthonormal)
Where ``n = prod(s)`` is the logical FFT size.
Calling the backward transform (:func:`~torch.fft.ifft2`) with the same
normalization mode will apply an overall normalization of ``1/n``
between the two transforms. This is required to make
:func:`~torch.fft.ifft2` the exact inverse.
Default is ``"backward"`` (no normalization).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> x = torch.rand(10, 10, dtype=torch.complex64)
>>> fft2 = torch.fft.fft2(x)
The discrete Fourier transform is separable, so :func:`~torch.fft.fft2`
here is equivalent to two one-dimensional :func:`~torch.fft.fft` calls:
>>> two_ffts = torch.fft.fft(torch.fft.fft(x, dim=0), dim=1)
>>> torch.testing.assert_close(fft2, two_ffts, check_stride=False)
fftfreq = fft_fftfreq(...)
fftfreq(n, d=1.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Computes the discrete Fourier Transform sample frequencies for a signal of size :attr:`n`.
Note:
By convention, :func:`~torch.fft.fft` returns positive frequency terms
first, followed by the negative frequencies in reverse order, so that
``f[-i]`` for all :math:`0 < i \leq n/2`` in Python gives the negative
frequency terms. For an FFT of length :attr:`n` and with inputs spaced in
length unit :attr:`d`, the frequencies are::
f = [0, 1, ..., (n - 1) // 2, -(n // 2), ..., -1] / (d * n)
Note:
For even lengths, the Nyquist frequency at ``f[n/2]`` can be thought of as
either negative or positive. :func:`~torch.fft.fftfreq` follows NumPy's
convention of taking it to be negative.
Args:
n (int): the FFT length
d (float, optional): The sampling length scale.
The spacing between individual samples of the FFT input.
The default assumes unit spacing, dividing that result by the actual
spacing gives the result in physical frequency units.
Keyword Args:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example:
>>> torch.fft.fftfreq(5)
tensor([ 0.0000, 0.2000, 0.4000, -0.4000, -0.2000])
For even input, we can see the Nyquist frequency at ``f[2]`` is given as
negative:
>>> torch.fft.fftfreq(4)
tensor([ 0.0000, 0.2500, -0.5000, -0.2500])
fftn = fft_fftn(...)
fftn(input, s=None, dim=None, norm=None, *, out=None) -> Tensor
Computes the N dimensional discrete Fourier transform of :attr:`input`.
Note:
The Fourier domain representation of any real signal satisfies the
Hermitian property: ``X[i_1, ..., i_n] = conj(X[-i_1, ..., -i_n])``. This
function always returns all positive and negative frequency terms even
though, for real inputs, half of these values are redundant.
:func:`~torch.fft.rfftn` returns the more compact one-sided representation
where only the positive frequencies of the last dimension are returned.
Note:
Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimensions.
Args:
input (Tensor): the input tensor
s (Tuple[int], optional): Signal size in the transformed dimensions.
If given, each dimension ``dim[i]`` will either be zero-padded or
trimmed to the length ``s[i]`` before computing the FFT.
If a length ``-1`` is specified, no padding is done in that dimension.
Default: ``s = [input.size(d) for d in dim]``
dim (Tuple[int], optional): Dimensions to be transformed.
Default: all dimensions, or the last ``len(s)`` dimensions if :attr:`s` is given.
norm (str, optional): Normalization mode. For the forward transform
(:func:`~torch.fft.fftn`), these correspond to:
* ``"forward"`` - normalize by ``1/n``
* ``"backward"`` - no normalization
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the FFT orthonormal)
Where ``n = prod(s)`` is the logical FFT size.
Calling the backward transform (:func:`~torch.fft.ifftn`) with the same
normalization mode will apply an overall normalization of ``1/n``
between the two transforms. This is required to make
:func:`~torch.fft.ifftn` the exact inverse.
Default is ``"backward"`` (no normalization).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> x = torch.rand(10, 10, dtype=torch.complex64)
>>> fftn = torch.fft.fftn(x)
The discrete Fourier transform is separable, so :func:`~torch.fft.fftn`
here is equivalent to two one-dimensional :func:`~torch.fft.fft` calls:
>>> two_ffts = torch.fft.fft(torch.fft.fft(x, dim=0), dim=1)
>>> torch.testing.assert_close(fftn, two_ffts, check_stride=False)
fftshift = fft_fftshift(...)
fftshift(input, dim=None) -> Tensor
Reorders n-dimensional FFT data, as provided by :func:`~torch.fft.fftn`, to have
negative frequency terms first.
This performs a periodic shift of n-dimensional data such that the origin
``(0, ..., 0)`` is moved to the center of the tensor. Specifically, to
``input.shape[dim] // 2`` in each selected dimension.
Note:
By convention, the FFT returns positive frequency terms first, followed by
the negative frequencies in reverse order, so that ``f[-i]`` for all
:math:`0 < i \leq n/2` in Python gives the negative frequency terms.
:func:`~torch.fft.fftshift` rearranges all frequencies into ascending order
from negative to positive with the zero-frequency term in the center.
Note:
For even lengths, the Nyquist frequency at ``f[n/2]`` can be thought of as
either negative or positive. :func:`~torch.fft.fftshift` always puts the
Nyquist term at the 0-index. This is the same convention used by
:func:`~torch.fft.fftfreq`.
Args:
input (Tensor): the tensor in FFT order
dim (int, Tuple[int], optional): The dimensions to rearrange.
Only dimensions specified here will be rearranged, any other dimensions
will be left in their original order.
Default: All dimensions of :attr:`input`.
Example:
>>> f = torch.fft.fftfreq(4)
>>> f
tensor([ 0.0000, 0.2500, -0.5000, -0.2500])
>>> torch.fft.fftshift(f)
tensor([-0.5000, -0.2500, 0.0000, 0.2500])
Also notice that the Nyquist frequency term at ``f[2]`` was moved to the
beginning of the tensor.
This also works for multi-dimensional transforms:
>>> x = torch.fft.fftfreq(5, d=1/5) + 0.1 * torch.fft.fftfreq(5, d=1/5).unsqueeze(1)
>>> x
tensor([[ 0.0000, 1.0000, 2.0000, -2.0000, -1.0000],
[ 0.1000, 1.1000, 2.1000, -1.9000, -0.9000],
[ 0.2000, 1.2000, 2.2000, -1.8000, -0.8000],
[-0.2000, 0.8000, 1.8000, -2.2000, -1.2000],
[-0.1000, 0.9000, 1.9000, -2.1000, -1.1000]])
>>> torch.fft.fftshift(x)
tensor([[-2.2000, -1.2000, -0.2000, 0.8000, 1.8000],
[-2.1000, -1.1000, -0.1000, 0.9000, 1.9000],
[-2.0000, -1.0000, 0.0000, 1.0000, 2.0000],
[-1.9000, -0.9000, 0.1000, 1.1000, 2.1000],
[-1.8000, -0.8000, 0.2000, 1.2000, 2.2000]])
:func:`~torch.fft.fftshift` can also be useful for spatial data. If our
data is defined on a centered grid (``[-(N//2), (N-1)//2]``) then we can
use the standard FFT defined on an uncentered grid (``[0, N)``) by first
applying an :func:`~torch.fft.ifftshift`.
>>> x_centered = torch.arange(-5, 5)
>>> x_uncentered = torch.fft.ifftshift(x_centered)
>>> fft_uncentered = torch.fft.fft(x_uncentered)
Similarly, we can convert the frequency domain components to centered
convention by applying :func:`~torch.fft.fftshift`.
>>> fft_centered = torch.fft.fftshift(fft_uncentered)
The inverse transform, from centered Fourier space back to centered spatial
data, can be performed by applying the inverse shifts in reverse order:
>>> x_centered_2 = torch.fft.fftshift(torch.fft.ifft(torch.fft.ifftshift(fft_centered)))
>>> torch.testing.assert_close(x_centered.to(torch.complex64), x_centered_2, check_stride=False)
hfft = fft_hfft(...)
hfft(input, n=None, dim=-1, norm=None, *, out=None) -> Tensor
Computes the one dimensional discrete Fourier transform of a Hermitian
symmetric :attr:`input` signal.
Note:
:func:`~torch.fft.hfft`/:func:`~torch.fft.ihfft` are analogous to
:func:`~torch.fft.rfft`/:func:`~torch.fft.irfft`. The real FFT expects
a real signal in the time-domain and gives a Hermitian symmetry in the
frequency-domain. The Hermitian FFT is the opposite; Hermitian symmetric in
the time-domain and real-valued in the frequency-domain. For this reason,
special care needs to be taken with the length argument :attr:`n`, in the
same way as with :func:`~torch.fft.irfft`.
Note:
Because the signal is Hermitian in the time-domain, the result will be
real in the frequency domain. Note that some input frequencies must be
real-valued to satisfy the Hermitian property. In these cases the imaginary
component will be ignored. For example, any imaginary component in
``input[0]`` would result in one or more complex frequency terms which
cannot be represented in a real output and so will always be ignored.
Note:
The correct interpretation of the Hermitian input depends on the length of
the original data, as given by :attr:`n`. This is because each input shape
could correspond to either an odd or even length signal. By default, the
signal is assumed to be even length and odd signals will not round-trip
properly. So, it is recommended to always pass the signal length :attr:`n`.
Note:
Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimension.
With default arguments, size of the transformed dimension should be (2^n + 1) as argument
`n` defaults to even output size = 2 * (transformed_dim_size - 1)
Args:
input (Tensor): the input tensor representing a half-Hermitian signal
n (int, optional): Output signal length. This determines the length of the
real output. If given, the input will either be zero-padded or trimmed to this
length before computing the Hermitian FFT.
Defaults to even output: ``n=2*(input.size(dim) - 1)``.
dim (int, optional): The dimension along which to take the one dimensional Hermitian FFT.
norm (str, optional): Normalization mode. For the forward transform
(:func:`~torch.fft.hfft`), these correspond to:
* ``"forward"`` - normalize by ``1/n``
* ``"backward"`` - no normalization
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the Hermitian FFT orthonormal)
Calling the backward transform (:func:`~torch.fft.ihfft`) with the same
normalization mode will apply an overall normalization of ``1/n`` between
the two transforms. This is required to make :func:`~torch.fft.ihfft`
the exact inverse.
Default is ``"backward"`` (no normalization).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
Taking a real-valued frequency signal and bringing it into the time domain
gives Hermitian symmetric output:
>>> t = torch.linspace(0, 1, 5)
>>> t
tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
>>> T = torch.fft.ifft(t)
>>> T
tensor([ 0.5000-0.0000j, -0.1250-0.1720j, -0.1250-0.0406j, -0.1250+0.0406j,
-0.1250+0.1720j])
Note that ``T[1] == T[-1].conj()`` and ``T[2] == T[-2].conj()`` is
redundant. We can thus compute the forward transform without considering
negative frequencies:
>>> torch.fft.hfft(T[:3], n=5)
tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
Like with :func:`~torch.fft.irfft`, the output length must be given in order
to recover an even length output:
>>> torch.fft.hfft(T[:3])
tensor([0.1250, 0.2809, 0.6250, 0.9691])
ifft = fft_ifft(...)
ifft(input, n=None, dim=-1, norm=None, *, out=None) -> Tensor
Computes the one dimensional inverse discrete Fourier transform of :attr:`input`.
Note:
Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimension.
Args:
input (Tensor): the input tensor
n (int, optional): Signal length. If given, the input will either be zero-padded
or trimmed to this length before computing the IFFT.
dim (int, optional): The dimension along which to take the one dimensional IFFT.
norm (str, optional): Normalization mode. For the backward transform
(:func:`~torch.fft.ifft`), these correspond to:
* ``"forward"`` - no normalization
* ``"backward"`` - normalize by ``1/n``
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the IFFT orthonormal)
Calling the forward transform (:func:`~torch.fft.fft`) with the same
normalization mode will apply an overall normalization of ``1/n`` between
the two transforms. This is required to make :func:`~torch.fft.ifft`
the exact inverse.
Default is ``"backward"`` (normalize by ``1/n``).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> t = torch.tensor([ 6.+0.j, -2.+2.j, -2.+0.j, -2.-2.j])
>>> torch.fft.ifft(t)
tensor([0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j])
ifft2 = fft_ifft2(...)
ifft2(input, s=None, dim=(-2, -1), norm=None, *, out=None) -> Tensor
Computes the 2 dimensional inverse discrete Fourier transform of :attr:`input`.
Equivalent to :func:`~torch.fft.ifftn` but IFFTs only the last two dimensions by default.
Note:
Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimensions.
Args:
input (Tensor): the input tensor
s (Tuple[int], optional): Signal size in the transformed dimensions.
If given, each dimension ``dim[i]`` will either be zero-padded or
trimmed to the length ``s[i]`` before computing the IFFT.
If a length ``-1`` is specified, no padding is done in that dimension.
Default: ``s = [input.size(d) for d in dim]``
dim (Tuple[int], optional): Dimensions to be transformed.
Default: last two dimensions.
norm (str, optional): Normalization mode. For the backward transform
(:func:`~torch.fft.ifft2`), these correspond to:
* ``"forward"`` - no normalization
* ``"backward"`` - normalize by ``1/n``
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the IFFT orthonormal)
Where ``n = prod(s)`` is the logical IFFT size.
Calling the forward transform (:func:`~torch.fft.fft2`) with the same
normalization mode will apply an overall normalization of ``1/n`` between
the two transforms. This is required to make :func:`~torch.fft.ifft2`
the exact inverse.
Default is ``"backward"`` (normalize by ``1/n``).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> x = torch.rand(10, 10, dtype=torch.complex64)
>>> ifft2 = torch.fft.ifft2(x)
The discrete Fourier transform is separable, so :func:`~torch.fft.ifft2`
here is equivalent to two one-dimensional :func:`~torch.fft.ifft` calls:
>>> two_iffts = torch.fft.ifft(torch.fft.ifft(x, dim=0), dim=1)
>>> torch.testing.assert_close(ifft2, two_iffts, check_stride=False)
ifftn = fft_ifftn(...)
ifftn(input, s=None, dim=None, norm=None, *, out=None) -> Tensor
Computes the N dimensional inverse discrete Fourier transform of :attr:`input`.
Note:
Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimensions.
Args:
input (Tensor): the input tensor
s (Tuple[int], optional): Signal size in the transformed dimensions.
If given, each dimension ``dim[i]`` will either be zero-padded or
trimmed to the length ``s[i]`` before computing the IFFT.
If a length ``-1`` is specified, no padding is done in that dimension.
Default: ``s = [input.size(d) for d in dim]``
dim (Tuple[int], optional): Dimensions to be transformed.
Default: all dimensions, or the last ``len(s)`` dimensions if :attr:`s` is given.
norm (str, optional): Normalization mode. For the backward transform
(:func:`~torch.fft.ifftn`), these correspond to:
* ``"forward"`` - no normalization
* ``"backward"`` - normalize by ``1/n``
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the IFFT orthonormal)
Where ``n = prod(s)`` is the logical IFFT size.
Calling the forward transform (:func:`~torch.fft.fftn`) with the same
normalization mode will apply an overall normalization of ``1/n`` between
the two transforms. This is required to make :func:`~torch.fft.ifftn`
the exact inverse.
Default is ``"backward"`` (normalize by ``1/n``).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> x = torch.rand(10, 10, dtype=torch.complex64)
>>> ifftn = torch.fft.ifftn(x)
The discrete Fourier transform is separable, so :func:`~torch.fft.ifftn`
here is equivalent to two one-dimensional :func:`~torch.fft.ifft` calls:
>>> two_iffts = torch.fft.ifft(torch.fft.ifft(x, dim=0), dim=1)
>>> torch.testing.assert_close(ifftn, two_iffts, check_stride=False)
ifftshift = fft_ifftshift(...)
ifftshift(input, dim=None) -> Tensor
Inverse of :func:`~torch.fft.fftshift`.
Args:
input (Tensor): the tensor in FFT order
dim (int, Tuple[int], optional): The dimensions to rearrange.
Only dimensions specified here will be rearranged, any other dimensions
will be left in their original order.
Default: All dimensions of :attr:`input`.
Example:
>>> f = torch.fft.fftfreq(5)
>>> f
tensor([ 0.0000, 0.2000, 0.4000, -0.4000, -0.2000])
A round-trip through :func:`~torch.fft.fftshift` and
:func:`~torch.fft.ifftshift` gives the same result:
>>> shifted = torch.fft.fftshift(f)
>>> torch.fft.ifftshift(shifted)
tensor([ 0.0000, 0.2000, 0.4000, -0.4000, -0.2000])
ihfft = fft_ihfft(...)
ihfft(input, n=None, dim=-1, norm=None, *, out=None) -> Tensor
Computes the inverse of :func:`~torch.fft.hfft`.
:attr:`input` must be a real-valued signal, interpreted in the Fourier domain.
The IFFT of a real signal is Hermitian-symmetric, ``X[i] = conj(X[-i])``.
:func:`~torch.fft.ihfft` represents this in the one-sided form where only the
positive frequencies below the Nyquist frequency are included. To compute the
full output, use :func:`~torch.fft.ifft`.
Note:
Supports torch.half on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimension.
Args:
input (Tensor): the real input tensor
n (int, optional): Signal length. If given, the input will either be zero-padded
or trimmed to this length before computing the Hermitian IFFT.
dim (int, optional): The dimension along which to take the one dimensional Hermitian IFFT.
norm (str, optional): Normalization mode. For the backward transform
(:func:`~torch.fft.ihfft`), these correspond to:
* ``"forward"`` - no normalization
* ``"backward"`` - normalize by ``1/n``
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the IFFT orthonormal)
Calling the forward transform (:func:`~torch.fft.hfft`) with the same
normalization mode will apply an overall normalization of ``1/n`` between
the two transforms. This is required to make :func:`~torch.fft.ihfft`
the exact inverse.
Default is ``"backward"`` (normalize by ``1/n``).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> t = torch.arange(5)
>>> t
tensor([0, 1, 2, 3, 4])
>>> torch.fft.ihfft(t)
tensor([ 2.0000-0.0000j, -0.5000-0.6882j, -0.5000-0.1625j])
Compare against the full output from :func:`~torch.fft.ifft`:
>>> torch.fft.ifft(t)
tensor([ 2.0000-0.0000j, -0.5000-0.6882j, -0.5000-0.1625j, -0.5000+0.1625j,
-0.5000+0.6882j])
irfft = fft_irfft(...)
irfft(input, n=None, dim=-1, norm=None, *, out=None) -> Tensor
Computes the inverse of :func:`~torch.fft.rfft`.
:attr:`input` is interpreted as a one-sided Hermitian signal in the Fourier
domain, as produced by :func:`~torch.fft.rfft`. By the Hermitian property, the
output will be real-valued.
Note:
Some input frequencies must be real-valued to satisfy the Hermitian
property. In these cases the imaginary component will be ignored.
For example, any imaginary component in the zero-frequency term cannot
be represented in a real output and so will always be ignored.
Note:
The correct interpretation of the Hermitian input depends on the length of
the original data, as given by :attr:`n`. This is because each input shape
could correspond to either an odd or even length signal. By default, the
signal is assumed to be even length and odd signals will not round-trip
properly. So, it is recommended to always pass the signal length :attr:`n`.
Note:
Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimension.
With default arguments, size of the transformed dimension should be (2^n + 1) as argument
`n` defaults to even output size = 2 * (transformed_dim_size - 1)
Args:
input (Tensor): the input tensor representing a half-Hermitian signal
n (int, optional): Output signal length. This determines the length of the
output signal. If given, the input will either be zero-padded or trimmed to this
length before computing the real IFFT.
Defaults to even output: ``n=2*(input.size(dim) - 1)``.
dim (int, optional): The dimension along which to take the one dimensional real IFFT.
norm (str, optional): Normalization mode. For the backward transform
(:func:`~torch.fft.irfft`), these correspond to:
* ``"forward"`` - no normalization
* ``"backward"`` - normalize by ``1/n``
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the real IFFT orthonormal)
Calling the forward transform (:func:`~torch.fft.rfft`) with the same
normalization mode will apply an overall normalization of ``1/n`` between
the two transforms. This is required to make :func:`~torch.fft.irfft`
the exact inverse.
Default is ``"backward"`` (normalize by ``1/n``).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> t = torch.linspace(0, 1, 5)
>>> t
tensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
>>> T = torch.fft.rfft(t)
>>> T
tensor([ 2.5000+0.0000j, -0.6250+0.8602j, -0.6250+0.2031j])
Without specifying the output length to :func:`~torch.fft.irfft`, the output
will not round-trip properly because the input is odd-length:
>>> torch.fft.irfft(T)
tensor([0.1562, 0.3511, 0.7812, 1.2114])
So, it is recommended to always pass the signal length :attr:`n`:
>>> roundtrip = torch.fft.irfft(T, t.numel())
>>> torch.testing.assert_close(roundtrip, t, check_stride=False)
irfft2 = fft_irfft2(...)
irfft2(input, s=None, dim=(-2, -1), norm=None, *, out=None) -> Tensor
Computes the inverse of :func:`~torch.fft.rfft2`.
Equivalent to :func:`~torch.fft.irfftn` but IFFTs only the last two dimensions by default.
:attr:`input` is interpreted as a one-sided Hermitian signal in the Fourier
domain, as produced by :func:`~torch.fft.rfft2`. By the Hermitian property, the
output will be real-valued.
Note:
Some input frequencies must be real-valued to satisfy the Hermitian
property. In these cases the imaginary component will be ignored.
For example, any imaginary component in the zero-frequency term cannot
be represented in a real output and so will always be ignored.
Note:
The correct interpretation of the Hermitian input depends on the length of
the original data, as given by :attr:`s`. This is because each input shape
could correspond to either an odd or even length signal. By default, the
signal is assumed to be even length and odd signals will not round-trip
properly. So, it is recommended to always pass the signal shape :attr:`s`.
Note:
Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimensions.
With default arguments, the size of last dimension should be (2^n + 1) as argument
`s` defaults to even output size = 2 * (last_dim_size - 1)
Args:
input (Tensor): the input tensor
s (Tuple[int], optional): Signal size in the transformed dimensions.
If given, each dimension ``dim[i]`` will either be zero-padded or
trimmed to the length ``s[i]`` before computing the real FFT.
If a length ``-1`` is specified, no padding is done in that dimension.
Defaults to even output in the last dimension:
``s[-1] = 2*(input.size(dim[-1]) - 1)``.
dim (Tuple[int], optional): Dimensions to be transformed.
The last dimension must be the half-Hermitian compressed dimension.
Default: last two dimensions.
norm (str, optional): Normalization mode. For the backward transform
(:func:`~torch.fft.irfft2`), these correspond to:
* ``"forward"`` - no normalization
* ``"backward"`` - normalize by ``1/n``
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the real IFFT orthonormal)
Where ``n = prod(s)`` is the logical IFFT size.
Calling the forward transform (:func:`~torch.fft.rfft2`) with the same
normalization mode will apply an overall normalization of ``1/n`` between
the two transforms. This is required to make :func:`~torch.fft.irfft2`
the exact inverse.
Default is ``"backward"`` (normalize by ``1/n``).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> t = torch.rand(10, 9)
>>> T = torch.fft.rfft2(t)
Without specifying the output length to :func:`~torch.fft.irfft2`, the output
will not round-trip properly because the input is odd-length in the last
dimension:
>>> torch.fft.irfft2(T).size()
torch.Size([10, 8])
So, it is recommended to always pass the signal shape :attr:`s`.
>>> roundtrip = torch.fft.irfft2(T, t.size())
>>> roundtrip.size()
torch.Size([10, 9])
>>> torch.testing.assert_close(roundtrip, t, check_stride=False)
irfftn = fft_irfftn(...)
irfftn(input, s=None, dim=None, norm=None, *, out=None) -> Tensor
Computes the inverse of :func:`~torch.fft.rfftn`.
:attr:`input` is interpreted as a one-sided Hermitian signal in the Fourier
domain, as produced by :func:`~torch.fft.rfftn`. By the Hermitian property, the
output will be real-valued.
Note:
Some input frequencies must be real-valued to satisfy the Hermitian
property. In these cases the imaginary component will be ignored.
For example, any imaginary component in the zero-frequency term cannot
be represented in a real output and so will always be ignored.
Note:
The correct interpretation of the Hermitian input depends on the length of
the original data, as given by :attr:`s`. This is because each input shape
could correspond to either an odd or even length signal. By default, the
signal is assumed to be even length and odd signals will not round-trip
properly. So, it is recommended to always pass the signal shape :attr:`s`.
Note:
Supports torch.half and torch.chalf on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimensions.
With default arguments, the size of last dimension should be (2^n + 1) as argument
`s` defaults to even output size = 2 * (last_dim_size - 1)
Args:
input (Tensor): the input tensor
s (Tuple[int], optional): Signal size in the transformed dimensions.
If given, each dimension ``dim[i]`` will either be zero-padded or
trimmed to the length ``s[i]`` before computing the real FFT.
If a length ``-1`` is specified, no padding is done in that dimension.
Defaults to even output in the last dimension:
``s[-1] = 2*(input.size(dim[-1]) - 1)``.
dim (Tuple[int], optional): Dimensions to be transformed.
The last dimension must be the half-Hermitian compressed dimension.
Default: all dimensions, or the last ``len(s)`` dimensions if :attr:`s` is given.
norm (str, optional): Normalization mode. For the backward transform
(:func:`~torch.fft.irfftn`), these correspond to:
* ``"forward"`` - no normalization
* ``"backward"`` - normalize by ``1/n``
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the real IFFT orthonormal)
Where ``n = prod(s)`` is the logical IFFT size.
Calling the forward transform (:func:`~torch.fft.rfftn`) with the same
normalization mode will apply an overall normalization of ``1/n`` between
the two transforms. This is required to make :func:`~torch.fft.irfftn`
the exact inverse.
Default is ``"backward"`` (normalize by ``1/n``).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> t = torch.rand(10, 9)
>>> T = torch.fft.rfftn(t)
Without specifying the output length to :func:`~torch.fft.irfft`, the output
will not round-trip properly because the input is odd-length in the last
dimension:
>>> torch.fft.irfftn(T).size()
torch.Size([10, 8])
So, it is recommended to always pass the signal shape :attr:`s`.
>>> roundtrip = torch.fft.irfftn(T, t.size())
>>> roundtrip.size()
torch.Size([10, 9])
>>> torch.testing.assert_close(roundtrip, t, check_stride=False)
rfft = fft_rfft(...)
rfft(input, n=None, dim=-1, norm=None, *, out=None) -> Tensor
Computes the one dimensional Fourier transform of real-valued :attr:`input`.
The FFT of a real signal is Hermitian-symmetric, ``X[i] = conj(X[-i])`` so
the output contains only the positive frequencies below the Nyquist frequency.
To compute the full output, use :func:`~torch.fft.fft`
Note:
Supports torch.half on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimension.
Args:
input (Tensor): the real input tensor
n (int, optional): Signal length. If given, the input will either be zero-padded
or trimmed to this length before computing the real FFT.
dim (int, optional): The dimension along which to take the one dimensional real FFT.
norm (str, optional): Normalization mode. For the forward transform
(:func:`~torch.fft.rfft`), these correspond to:
* ``"forward"`` - normalize by ``1/n``
* ``"backward"`` - no normalization
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the FFT orthonormal)
Calling the backward transform (:func:`~torch.fft.irfft`) with the same
normalization mode will apply an overall normalization of ``1/n`` between
the two transforms. This is required to make :func:`~torch.fft.irfft`
the exact inverse.
Default is ``"backward"`` (no normalization).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> t = torch.arange(4)
>>> t
tensor([0, 1, 2, 3])
>>> torch.fft.rfft(t)
tensor([ 6.+0.j, -2.+2.j, -2.+0.j])
Compare against the full output from :func:`~torch.fft.fft`:
>>> torch.fft.fft(t)
tensor([ 6.+0.j, -2.+2.j, -2.+0.j, -2.-2.j])
Notice that the symmetric element ``T[-1] == T[1].conj()`` is omitted.
At the Nyquist frequency ``T[-2] == T[2]`` is its own symmetric pair,
and therefore must always be real-valued.
rfft2 = fft_rfft2(...)
rfft2(input, s=None, dim=(-2, -1), norm=None, *, out=None) -> Tensor
Computes the 2-dimensional discrete Fourier transform of real :attr:`input`.
Equivalent to :func:`~torch.fft.rfftn` but FFTs only the last two dimensions by default.
The FFT of a real signal is Hermitian-symmetric, ``X[i, j] = conj(X[-i, -j])``,
so the full :func:`~torch.fft.fft2` output contains redundant information.
:func:`~torch.fft.rfft2` instead omits the negative frequencies in the last
dimension.
Note:
Supports torch.half on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimensions.
Args:
input (Tensor): the input tensor
s (Tuple[int], optional): Signal size in the transformed dimensions.
If given, each dimension ``dim[i]`` will either be zero-padded or
trimmed to the length ``s[i]`` before computing the real FFT.
If a length ``-1`` is specified, no padding is done in that dimension.
Default: ``s = [input.size(d) for d in dim]``
dim (Tuple[int], optional): Dimensions to be transformed.
Default: last two dimensions.
norm (str, optional): Normalization mode. For the forward transform
(:func:`~torch.fft.rfft2`), these correspond to:
* ``"forward"`` - normalize by ``1/n``
* ``"backward"`` - no normalization
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the real FFT orthonormal)
Where ``n = prod(s)`` is the logical FFT size.
Calling the backward transform (:func:`~torch.fft.irfft2`) with the same
normalization mode will apply an overall normalization of ``1/n`` between
the two transforms. This is required to make :func:`~torch.fft.irfft2`
the exact inverse.
Default is ``"backward"`` (no normalization).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> t = torch.rand(10, 10)
>>> rfft2 = torch.fft.rfft2(t)
>>> rfft2.size()
torch.Size([10, 6])
Compared against the full output from :func:`~torch.fft.fft2`, we have all
elements up to the Nyquist frequency.
>>> fft2 = torch.fft.fft2(t)
>>> torch.testing.assert_close(fft2[..., :6], rfft2, check_stride=False)
The discrete Fourier transform is separable, so :func:`~torch.fft.rfft2`
here is equivalent to a combination of :func:`~torch.fft.fft` and
:func:`~torch.fft.rfft`:
>>> two_ffts = torch.fft.fft(torch.fft.rfft(t, dim=1), dim=0)
>>> torch.testing.assert_close(rfft2, two_ffts, check_stride=False)
rfftfreq = fft_rfftfreq(...)
rfftfreq(n, d=1.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Computes the sample frequencies for :func:`~torch.fft.rfft` with a signal of size :attr:`n`.
Note:
:func:`~torch.fft.rfft` returns Hermitian one-sided output, so only the
positive frequency terms are returned. For a real FFT of length :attr:`n`
and with inputs spaced in length unit :attr:`d`, the frequencies are::
f = torch.arange((n + 1) // 2) / (d * n)
Note:
For even lengths, the Nyquist frequency at ``f[n/2]`` can be thought of as
either negative or positive. Unlike :func:`~torch.fft.fftfreq`,
:func:`~torch.fft.rfftfreq` always returns it as positive.
Args:
n (int): the real FFT length
d (float, optional): The sampling length scale.
The spacing between individual samples of the FFT input.
The default assumes unit spacing, dividing that result by the actual
spacing gives the result in physical frequency units.
Keyword Args:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example:
>>> torch.fft.rfftfreq(5)
tensor([0.0000, 0.2000, 0.4000])
>>> torch.fft.rfftfreq(4)
tensor([0.0000, 0.2500, 0.5000])
Compared to the output from :func:`~torch.fft.fftfreq`, we see that the
Nyquist frequency at ``f[2]`` has changed sign:
>>> torch.fft.fftfreq(4)
tensor([ 0.0000, 0.2500, -0.5000, -0.2500])
rfftn = fft_rfftn(...)
rfftn(input, s=None, dim=None, norm=None, *, out=None) -> Tensor
Computes the N-dimensional discrete Fourier transform of real :attr:`input`.
The FFT of a real signal is Hermitian-symmetric,
``X[i_1, ..., i_n] = conj(X[-i_1, ..., -i_n])`` so the full
:func:`~torch.fft.fftn` output contains redundant information.
:func:`~torch.fft.rfftn` instead omits the negative frequencies in the
last dimension.
Note:
Supports torch.half on CUDA with GPU Architecture SM53 or greater.
However it only supports powers of 2 signal length in every transformed dimensions.
Args:
input (Tensor): the input tensor
s (Tuple[int], optional): Signal size in the transformed dimensions.
If given, each dimension ``dim[i]`` will either be zero-padded or
trimmed to the length ``s[i]`` before computing the real FFT.
If a length ``-1`` is specified, no padding is done in that dimension.
Default: ``s = [input.size(d) for d in dim]``
dim (Tuple[int], optional): Dimensions to be transformed.
Default: all dimensions, or the last ``len(s)`` dimensions if :attr:`s` is given.
norm (str, optional): Normalization mode. For the forward transform
(:func:`~torch.fft.rfftn`), these correspond to:
* ``"forward"`` - normalize by ``1/n``
* ``"backward"`` - no normalization
* ``"ortho"`` - normalize by ``1/sqrt(n)`` (making the real FFT orthonormal)
Where ``n = prod(s)`` is the logical FFT size.
Calling the backward transform (:func:`~torch.fft.irfftn`) with the same
normalization mode will apply an overall normalization of ``1/n`` between
the two transforms. This is required to make :func:`~torch.fft.irfftn`
the exact inverse.
Default is ``"backward"`` (no normalization).
Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> t = torch.rand(10, 10)
>>> rfftn = torch.fft.rfftn(t)
>>> rfftn.size()
torch.Size([10, 6])
Compared against the full output from :func:`~torch.fft.fftn`, we have all
elements up to the Nyquist frequency.
>>> fftn = torch.fft.fftn(t)
>>> torch.testing.assert_close(fftn[..., :6], rfftn, check_stride=False)
The discrete Fourier transform is separable, so :func:`~torch.fft.rfftn`
here is equivalent to a combination of :func:`~torch.fft.fft` and
:func:`~torch.fft.rfft`:
>>> two_ffts = torch.fft.fft(torch.fft.rfft(t, dim=1), dim=0)
>>> torch.testing.assert_close(rfftn, two_ffts, check_stride=False)
DATA
__all__ = ['fft', 'ifft', 'fft2', 'ifft2', 'fftn', 'ifftn', 'rfft', 'i...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\fft\__init__.py
torch.fill
Python Library Documentation: built-in function fill in module torch fill(...)
torch.fill_
Python Library Documentation: built-in function fill_ in module torch fill_(...)
torch.finfo
Python Library Documentation: class finfo in module torch class finfo(builtins.object) | Methods defined here: | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __repr__(self, /) | Return repr(self). | | __str__(self, /) | Return str(self). | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | bits | | dtype | | eps | | max | | min | | resolution | | smallest_normal | | tiny | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __hash__ = None
torch.fix
Python Library Documentation: built-in function fix in module torch
fix(...)
fix(input, *, out=None) -> Tensor
Alias for :func:`torch.trunc`
torch.fix_
Python Library Documentation: built-in function fix_ in module torch fix_(...)
torch.flatten
Python Library Documentation: built-in function flatten in module torch
flatten(...)
flatten(input, start_dim=0, end_dim=-1) -> Tensor
Flattens :attr:`input` by reshaping it into a one-dimensional tensor. If :attr:`start_dim` or :attr:`end_dim`
are passed, only dimensions starting with :attr:`start_dim` and ending with :attr:`end_dim` are flattened.
The order of elements in :attr:`input` is unchanged.
Unlike NumPy's flatten, which always copies input's data, this function may return the original object, a view,
or copy. If no dimensions are flattened, then the original object :attr:`input` is returned. Otherwise, if input can
be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the
flattened shape is input's data copied. See :meth:`torch.Tensor.view` for details on when a view will be returned.
.. note::
Flattening a zero-dimensional tensor will return a one-dimensional view.
Args:
input (Tensor): the input tensor.
start_dim (int): the first dim to flatten
end_dim (int): the last dim to flatten
Example::
>>> t = torch.tensor([[[1, 2],
... [3, 4]],
... [[5, 6],
... [7, 8]]])
>>> torch.flatten(t)
tensor([1, 2, 3, 4, 5, 6, 7, 8])
>>> torch.flatten(t, start_dim=1)
tensor([[1, 2, 3, 4],
[5, 6, 7, 8]])
torch.flip
Python Library Documentation: built-in function flip in module torch
flip(...)
flip(input, dims) -> Tensor
Reverse the order of an n-D tensor along given axis in dims.
.. note::
`torch.flip` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.flip`,
which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
`torch.flip` is expected to be slower than `np.flip`.
Args:
input (Tensor): the input tensor.
dims (a list or tuple): axis to flip on
Example::
>>> x = torch.arange(8).view(2, 2, 2)
>>> x
tensor([[[ 0, 1],
[ 2, 3]],
[[ 4, 5],
[ 6, 7]]])
>>> torch.flip(x, [0, 1])
tensor([[[ 6, 7],
[ 4, 5]],
[[ 2, 3],
[ 0, 1]]])
torch.fliplr
Python Library Documentation: built-in function fliplr in module torch
fliplr(...)
fliplr(input) -> Tensor
Flip tensor in the left/right direction, returning a new tensor.
Flip the entries in each row in the left/right direction.
Columns are preserved, but appear in a different order than before.
Note:
Requires the tensor to be at least 2-D.
.. note::
`torch.fliplr` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.fliplr`,
which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
`torch.fliplr` is expected to be slower than `np.fliplr`.
Args:
input (Tensor): Must be at least 2-dimensional.
Example::
>>> x = torch.arange(4).view(2, 2)
>>> x
tensor([[0, 1],
[2, 3]])
>>> torch.fliplr(x)
tensor([[1, 0],
[3, 2]])
torch.flipud
Python Library Documentation: built-in function flipud in module torch
flipud(...)
flipud(input) -> Tensor
Flip tensor in the up/down direction, returning a new tensor.
Flip the entries in each column in the up/down direction.
Rows are preserved, but appear in a different order than before.
Note:
Requires the tensor to be at least 1-D.
.. note::
`torch.flipud` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.flipud`,
which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
`torch.flipud` is expected to be slower than `np.flipud`.
Args:
input (Tensor): Must be at least 1-dimensional.
Example::
>>> x = torch.arange(4).view(2, 2)
>>> x
tensor([[0, 1],
[2, 3]])
>>> torch.flipud(x)
tensor([[2, 3],
[0, 1]])
torch.float
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.float16
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.float32
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.float4_e2m1fn_x2
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.float64
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.float8_e4m3fn
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.float8_e4m3fnuz
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.float8_e5m2
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.float8_e5m2fnuz
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.float8_e8m0fnu
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.float_power
Python Library Documentation: built-in function float_power in module torch
float_power(...)
float_power(input, exponent, *, out=None) -> Tensor
Raises :attr:`input` to the power of :attr:`exponent`, elementwise, in double precision.
If neither input is complex returns a ``torch.float64`` tensor,
and if one or more inputs is complex returns a ``torch.complex128`` tensor.
.. note::
This function always computes in double precision, unlike :func:`torch.pow`,
which implements more typical :ref:`type promotion <type-promotion-doc>`.
This is useful when the computation needs to be performed in a wider or more precise dtype,
or the results of the computation may contain fractional values not representable in the input dtypes,
like when an integer base is raised to a negative integer exponent.
Args:
input (Tensor or Number): the base value(s)
exponent (Tensor or Number): the exponent value(s)
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randint(10, (4,))
>>> a
tensor([6, 4, 7, 1])
>>> torch.float_power(a, 2)
tensor([36., 16., 49., 1.], dtype=torch.float64)
>>> a = torch.arange(1, 5)
>>> a
tensor([ 1, 2, 3, 4])
>>> exp = torch.tensor([2, -3, 4, -5])
>>> exp
tensor([ 2, -3, 4, -5])
>>> torch.float_power(a, exp)
tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=torch.float64)
torch.floor
Python Library Documentation: built-in function floor in module torch
floor(...)
floor(input, *, out=None) -> Tensor
Returns a new tensor with the floor of the elements of :attr:`input`,
the largest integer less than or equal to each element.
For integer inputs, follows the array-api convention of returning a
copy of the input tensor.
.. math::
\text{out}_{i} = \left\lfloor \text{input}_{i} \right\rfloor
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-0.8166, 1.5308, -0.2530, -0.2091])
>>> torch.floor(a)
tensor([-1., 1., -1., -1.])
torch.floor_
Python Library Documentation: built-in function floor_ in module torch floor_(...)
torch.floor_divide
Python Library Documentation: built-in function floor_divide in module torch
floor_divide(...)
floor_divide(input, other, *, out=None) -> Tensor
.. note::
Before PyTorch 1.13 :func:`torch.floor_divide` incorrectly performed
truncation division. To restore the previous behavior use
:func:`torch.div` with ``rounding_mode='trunc'``.
Computes :attr:`input` divided by :attr:`other`, elementwise, and floors
the result.
.. math::
\text{{out}}_i = \text{floor} \left( \frac{{\text{{input}}_i}}{{\text{{other}}_i}} \right)
Supports broadcasting to a common shape, type promotion, and integer and float inputs.
Args:
input (Tensor or Number): the dividend
other (Tensor or Number): the divisor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([4.0, 3.0])
>>> b = torch.tensor([2.0, 2.0])
>>> torch.floor_divide(a, b)
tensor([2.0, 1.0])
>>> torch.floor_divide(a, 1.4)
tensor([2.0, 2.0])
torch.fmax
Python Library Documentation: built-in function fmax in module torch
fmax(...)
fmax(input, other, *, out=None) -> Tensor
Computes the element-wise maximum of :attr:`input` and :attr:`other`.
This is like :func:`torch.maximum` except it handles NaNs differently:
if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the maximum.
Only if both elements are NaN is NaN propagated.
This function is a wrapper around C++'s ``std::fmax`` and is similar to NumPy's ``fmax`` function.
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer and floating-point inputs.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([9.7, float('nan'), 3.1, float('nan')])
>>> b = torch.tensor([-2.2, 0.5, float('nan'), float('nan')])
>>> torch.fmax(a, b)
tensor([9.7000, 0.5000, 3.1000, nan])
torch.fmin
Python Library Documentation: built-in function fmin in module torch
fmin(...)
fmin(input, other, *, out=None) -> Tensor
Computes the element-wise minimum of :attr:`input` and :attr:`other`.
This is like :func:`torch.minimum` except it handles NaNs differently:
if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the minimum.
Only if both elements are NaN is NaN propagated.
This function is a wrapper around C++'s ``std::fmin`` and is similar to NumPy's ``fmin`` function.
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer and floating-point inputs.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([2.2, float('nan'), 2.1, float('nan')])
>>> b = torch.tensor([-9.3, 0.1, float('nan'), float('nan')])
>>> torch.fmin(a, b)
tensor([-9.3000, 0.1000, 2.1000, nan])
torch.fmod
Python Library Documentation: built-in function fmod in module torch
fmod(...)
fmod(input, other, *, out=None) -> Tensor
Applies C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_ entrywise.
The result has the same sign as the dividend :attr:`input` and its absolute value
is less than that of :attr:`other`.
This function may be defined in terms of :func:`torch.div` as
.. code:: python
torch.fmod(a, b) == a - a.div(b, rounding_mode="trunc") * b
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
.. note::
When the divisor is zero, returns ``NaN`` for floating point dtypes
on both CPU and GPU; raises ``RuntimeError`` for integer division by
zero on CPU; Integer division by zero on GPU may return any value.
.. note::
Complex inputs are not supported. In some cases, it is not mathematically
possible to satisfy the definition of a modulo operation with complex numbers.
.. seealso::
:func:`torch.remainder` which implements Python's modulus operator.
This one is defined using division rounding down the result.
Args:
input (Tensor): the dividend
other (Tensor or Scalar): the divisor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.fmod(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
tensor([-1., -0., -1., 1., 0., 1.])
>>> torch.fmod(torch.tensor([1, 2, 3, 4, 5]), -1.5)
tensor([1.0000, 0.5000, 0.0000, 1.0000, 0.5000])
torch.fork
Python Library Documentation: built-in function fork in module torch
fork(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
fork(*args, **kwargs) -> torch._C.Future
torch.frac
Python Library Documentation: built-in function frac in module torch
frac(...)
frac(input, *, out=None) -> Tensor
Computes the fractional portion of each element in :attr:`input`.
.. math::
\text{out}_{i} = \text{input}_{i} - \left\lfloor |\text{input}_{i}| \right\rfloor * \operatorname{sgn}(\text{input}_{i})
Example::
>>> torch.frac(torch.tensor([1, 2.5, -3.2]))
tensor([ 0.0000, 0.5000, -0.2000])
torch.frac_
Python Library Documentation: built-in function frac_ in module torch frac_(...)
torch.frexp
Python Library Documentation: built-in function frexp in module torch
frexp(...)
frexp(input, *, out=None) -> (Tensor mantissa, Tensor exponent)
Decomposes :attr:`input` into mantissa and exponent tensors
such that :math:`\text{input} = \text{mantissa} \times 2^{\text{exponent}}`.
The range of mantissa is the open interval (-1, 1).
Supports float inputs.
Args:
input (Tensor): the input tensor
Keyword args:
out (tuple, optional): the output tensors
Example::
>>> x = torch.arange(9.)
>>> mantissa, exponent = torch.frexp(x)
>>> mantissa
tensor([0.0000, 0.5000, 0.5000, 0.7500, 0.5000, 0.6250, 0.7500, 0.8750, 0.5000])
>>> exponent
tensor([0, 1, 2, 2, 3, 3, 3, 3, 4], dtype=torch.int32)
>>> torch.ldexp(mantissa, exponent)
tensor([0., 1., 2., 3., 4., 5., 6., 7., 8.])
torch.frobenius_norm
Python Library Documentation: built-in function frobenius_norm in module torch frobenius_norm(...)
torch.from_dlpack
Python Library Documentation: function from_dlpack in module torch.utils.dlpack
from_dlpack(ext_tensor: Any, *, device: torch.device | str | int | None = None, copy: bool | None = None) -> 'torch.Tensor'
from_dlpack(ext_tensor) -> Tensor
Converts a tensor from an external library into a ``torch.Tensor``.
The returned PyTorch tensor will share the memory with the input tensor
(which may have come from another library). Note that in-place operations
will therefore also affect the data of the input tensor. This may lead to
unexpected issues (e.g., other libraries may have read-only flags or
immutable data structures), so the user should only do this if they know
for sure that this is fine.
Args:
ext_tensor (object with ``__dlpack__`` attribute, or a DLPack capsule):
The tensor or DLPack capsule to convert.
If ``ext_tensor`` is a tensor (or ndarray) object, it must support
the ``__dlpack__`` protocol (i.e., have a ``ext_tensor.__dlpack__``
method). Otherwise ``ext_tensor`` may be a DLPack capsule, which is
an opaque ``PyCapsule`` instance, typically produced by a
``to_dlpack`` function or method.
device (torch.device or str or None): An optional PyTorch device
specifying where to place the new tensor. If None (default), the
new tensor will be on the same device as ``ext_tensor``.
copy (bool or None): An optional boolean indicating whether or not to copy
``self``. If None, PyTorch will copy only if necessary.
Examples::
>>> import torch.utils.dlpack
>>> t = torch.arange(4)
# Convert a tensor directly (supported in PyTorch >= 1.10)
>>> t2 = torch.from_dlpack(t)
>>> t2[:2] = -1 # show that memory is shared
>>> t2
tensor([-1, -1, 2, 3])
>>> t
tensor([-1, -1, 2, 3])
# The old-style DLPack usage, with an intermediate capsule object
>>> capsule = torch.utils.dlpack.to_dlpack(t)
>>> capsule
<capsule object "dltensor" at ...>
>>> t3 = torch.from_dlpack(capsule)
>>> t3
tensor([-1, -1, 2, 3])
>>> t3[0] = -9 # now we're sharing memory between 3 tensors
>>> t3
tensor([-9, -1, 2, 3])
>>> t2
tensor([-9, -1, 2, 3])
>>> t
tensor([-9, -1, 2, 3])
torch.from_file
Python Library Documentation: built-in function from_file in module torch
from_file(...)
from_file(filename, shared=None, size=0, *, dtype=None, layout=None, device=None, pin_memory=False)
Creates a CPU tensor with a storage backed by a memory-mapped file.
If ``shared`` is True, then memory is shared between processes. All changes are written to the file.
If ``shared`` is False, then changes to the tensor do not affect the file.
``size`` is the number of elements in the Tensor. If ``shared`` is ``False``, then the file must contain
at least ``size * sizeof(dtype)`` bytes. If ``shared`` is ``True`` the file will be created if needed.
.. note::
Only CPU tensors can be mapped to files.
.. note::
For now, tensors with storages backed by a memory-mapped file cannot be created in pinned memory.
Args:
filename (str): file name to map
shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
size (int): number of elements in the tensor
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> t = torch.randn(2, 5, dtype=torch.float64)
>>> t.numpy().tofile('storage.pt')
>>> t_mapped = torch.from_file('storage.pt', shared=False, size=10, dtype=torch.float64)
torch.from_numpy
Python Library Documentation: built-in function from_numpy in module torch
from_numpy(...)
from_numpy(ndarray) -> Tensor
Creates a :class:`Tensor` from a :class:`numpy.ndarray`.
The returned tensor and :attr:`ndarray` share the same memory. Modifications to
the tensor will be reflected in the :attr:`ndarray` and vice versa. The returned
tensor is not resizable.
It currently accepts :attr:`ndarray` with dtypes of ``numpy.float64``,
``numpy.float32``, ``numpy.float16``, ``numpy.complex64``, ``numpy.complex128``,
``numpy.int64``, ``numpy.int32``, ``numpy.int16``, ``numpy.int8``, ``numpy.uint8``,
and ``bool``.
.. warning::
Writing to a tensor created from a read-only NumPy array is not supported and will result in undefined behavior.
Example::
>>> a = numpy.array([1, 2, 3])
>>> t = torch.from_numpy(a)
>>> t
tensor([ 1, 2, 3])
>>> t[0] = -1
>>> a
array([-1, 2, 3])
torch.frombuffer
Python Library Documentation: built-in function frombuffer in module torch
frombuffer(...)
frombuffer(buffer, *, dtype, count=-1, offset=0, requires_grad=False) -> Tensor
Creates a 1-dimensional :class:`Tensor` from an object that implements
the Python buffer protocol.
Skips the first :attr:`offset` bytes in the buffer, and interprets the rest of
the raw bytes as a 1-dimensional tensor of type :attr:`dtype` with :attr:`count`
elements.
Note that either of the following must be true:
1. :attr:`count` is a positive non-zero number, and the total number of bytes
in the buffer is more than :attr:`offset` plus :attr:`count` times the size
(in bytes) of :attr:`dtype`.
2. :attr:`count` is negative, and the length (number of bytes) of the buffer
subtracted by the :attr:`offset` is a multiple of the size (in bytes) of
:attr:`dtype`.
The returned tensor and buffer share the same memory. Modifications to
the tensor will be reflected in the buffer and vice versa. The returned
tensor is not resizable.
.. note::
This function increments the reference count for the object that
owns the shared memory. Therefore, such memory will not be deallocated
before the returned tensor goes out of scope.
.. warning::
This function's behavior is undefined when passed an object implementing
the buffer protocol whose data is not on the CPU. Doing so is likely to
cause a segmentation fault.
.. warning::
This function does not try to infer the :attr:`dtype` (hence, it is not
optional). Passing a different :attr:`dtype` than its source may result
in unexpected behavior.
Args:
buffer (object): a Python object that exposes the buffer interface.
Keyword args:
dtype (:class:`torch.dtype`): the desired data type of returned tensor.
count (int, optional): the number of desired elements to be read.
If negative, all the elements (until the end of the buffer) will be
read. Default: -1.
offset (int, optional): the number of bytes to skip at the start of
the buffer. Default: 0.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> import array
>>> a = array.array('i', [1, 2, 3])
>>> t = torch.frombuffer(a, dtype=torch.int32)
>>> t
tensor([ 1, 2, 3])
>>> t[0] = -1
>>> a
array([-1, 2, 3])
>>> # Interprets the signed char bytes as 32-bit integers.
>>> # Each 4 signed char elements will be interpreted as
>>> # 1 signed 32-bit integer.
>>> import array
>>> a = array.array('b', [-1, 0, 0, 0])
>>> torch.frombuffer(a, dtype=torch.int32)
tensor([255], dtype=torch.int32)
torch.full
Python Library Documentation: built-in function full in module torch
full(...)
full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
tensor's dtype is inferred from :attr:`fill_value`.
Args:
size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
shape of the output tensor.
fill_value (Scalar): the value to fill the output tensor with.
Keyword args:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.full((2, 3), 3.141592)
tensor([[ 3.1416, 3.1416, 3.1416],
[ 3.1416, 3.1416, 3.1416]])
torch.full_like
Python Library Documentation: built-in function full_like in module torch
full_like(...)
full_like(input, fill_value, \*, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns a tensor with the same size as :attr:`input` filled with :attr:`fill_value`.
``torch.full_like(input, fill_value)`` is equivalent to
``torch.full(input.size(), fill_value, dtype=input.dtype, layout=input.layout, device=input.device)``.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
fill_value: the number to fill the output tensor with.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
Example::
>>> x = torch.ones(2, 3)
>>> torch.full_like(x, 3.141592)
tensor([[ 3.1416, 3.1416, 3.1416],
[ 3.1416, 3.1416, 3.1416]])
>>> torch.full_like(x, 7)
tensor([[7., 7., 7.],
[7., 7., 7.]])
>>> torch.full_like(x, 0.5, dtype=torch.int32)
tensor([[0, 0, 0],
[0, 0, 0]], dtype=torch.int32)
>>> y = torch.randn(3, 4, dtype=torch.float64)
>>> torch.full_like(y, -1.0)
tensor([[-1., -1., -1., -1.],
[-1., -1., -1., -1.],
[-1., -1., -1., -1.]], dtype=torch.float64)
torch.func
Python Library Documentation: package torch.func in torch
NAME
torch.func
PACKAGE CONTENTS
_random
FUNCTIONS
debug_unwrap(tensor: 'torch.Tensor', *, recurse: 'bool' = True) -> 'torch.Tensor'
Unwraps a functorch tensor (e.g. BatchedTensor, GradTrackingTensor) to its underlying tensor.
This function should only be used in a debug setting (e.g. trying to print the
value of a Tensor in a debugger). Otherwise, using the result of function
inside of a function being transformed will lead to undefined behavior.
functional_call(module: 'torch.nn.Module', parameter_and_buffer_dicts: 'dict[str, Tensor] | Sequence[dict[str, Tensor]]', args: 'Any' = None, kwargs: 'dict[str, Any] | None' = None, *, tie_weights: 'bool' = True, strict: 'bool' = False) -> 'Any'
Performs a functional call on the module by replacing the module parameters
and buffers with the provided ones.
.. note:: If the module has active parametrizations, passing a value in the
:attr:`parameter_and_buffer_dicts` argument with the name set to the regular parameter
name will completely disable the parametrization.
If you want to apply the parametrization function to the value passed
please set the key as ``{submodule_name}.parametrizations.{parameter_name}.original``.
.. note:: If the module performs in-place operations on parameters/buffers, these will be reflected
in the ``parameter_and_buffer_dicts`` input.
Example::
>>> a = {'foo': torch.zeros(())}
>>> # xdoctest: +SKIP
>>> mod = Foo() # does self.foo = self.foo + 1
>>> print(mod.foo) # tensor(0.)
>>> functional_call(mod, a, torch.ones(()))
>>> print(mod.foo) # tensor(0.)
>>> print(a['foo']) # tensor(1.)
.. note:: If the module has tied weights, whether or not functional_call respects the tying is determined by the
tie_weights flag.
Example::
>>> a = {'foo': torch.zeros(())}
>>> # xdoctest: +SKIP
>>> mod = Foo() # has both self.foo and self.foo_tied which are tied. Returns x + self.foo + self.foo_tied
>>> print(mod.foo) # tensor(1.)
>>> mod(torch.zeros(())) # tensor(2.)
>>> functional_call(mod, a, torch.zeros(())) # tensor(0.) since it will change self.foo_tied too
>>> functional_call(mod, a, torch.zeros(()), tie_weights=False) # tensor(1.)--self.foo_tied is not updated
>>> new_a = {'foo': torch.zeros(()), 'foo_tied': torch.zeros(())}
>>> functional_call(mod, new_a, torch.zeros()) # tensor(0.)
An example of passing multiple dictionaries
.. code-block:: python
a = (
{"weight": torch.ones(1, 1)},
{"buffer": torch.zeros(1)},
) # two separate dictionaries
mod = nn.Bar(1, 1) # return self.weight @ x + self.buffer
print(mod.weight) # tensor(...)
print(mod.buffer) # tensor(...)
x = torch.randn((1, 1))
print(x)
functional_call(mod, a, x) # same as x
print(mod.weight) # same as before functional_call
And here is an example of applying the grad transform over the parameters
of a model.
.. code-block:: python
import torch
import torch.nn as nn
from torch.func import functional_call, grad
x = torch.randn(4, 3)
t = torch.randn(4, 3)
model = nn.Linear(3, 3)
def compute_loss(params, x, t):
y = functional_call(model, params, x)
return nn.functional.mse_loss(y, t)
grad_weights = grad(compute_loss)(dict(model.named_parameters()), x, t)
.. note:: If the user does not need grad tracking outside of grad transforms, they can detach all of the
parameters for better performance and memory usage
Example::
>>> detached_params = {k: v.detach() for k, v in model.named_parameters()}
>>> grad_weights = grad(compute_loss)(detached_params, x, t)
>>> grad_weights.grad_fn # None--it's not tracking gradients outside of grad
This means that the user cannot call ``grad_weight.backward()``. However, if they don't need autograd tracking
outside of the transforms, this will result in less memory usage and faster speeds.
Args:
module (torch.nn.Module): the module to call
parameters_and_buffer_dicts (Dict[str, Tensor] or tuple of Dict[str, Tensor]): the parameters that will be used in
the module call. If given a tuple of dictionaries, they must have distinct keys so that all dictionaries can
be used together
args (Any or tuple): arguments to be passed to the module call. If not a tuple, considered a single argument.
kwargs (dict): keyword arguments to be passed to the module call
tie_weights (bool, optional): If True, then parameters and buffers tied in the original model will be treated as
tied in the reparameterized version. Therefore, if True and different values are passed for the tied
parameters and buffers, it will error. If False, it will not respect the originally tied parameters and
buffers unless the values passed for both weights are the same. Default: True.
strict (bool, optional): If True, then the parameters and buffers passed in must match the parameters and
buffers in the original module. Therefore, if True and there are any missing or unexpected keys, it will
error. Default: False.
Returns:
Any: the result of calling ``module``.
functionalize(func: 'Callable[..., Any]', *, remove: 'str' = 'mutations') -> 'Callable[..., Any]'
functionalize is a transform that can be used to remove (intermediate)
mutations and aliasing from a function, while preserving the function's
semantics.
``functionalize(func)`` returns a new function with the same semantics
as ``func``, but with all intermediate mutations removed.
Every inplace operation performed on an intermediate tensor:
``intermediate.foo_()``
gets replaced by its out-of-place equivalent:
``intermediate_updated = intermediate.foo()``.
functionalize is useful for shipping a pytorch program off to
backends or compilers that aren't able to easily represent
mutations or aliasing operators.
Args:
func (Callable[..., Any]): A Python function that takes one or more arguments.
remove (str): An optional string argument, that takes on either
the value 'mutations' or 'mutations_and_views'.
If 'mutations' is passed in then all mutating operators
will be replaced with their non-mutating equivalents.
If 'mutations_and_views' is passed in, then additionally, all aliasing
operators will be replaced with their non-aliasing equivalents.
Default: 'mutations'.
Returns:
Returns a new "functionalized" function. It takes the same inputs as
``func``, and has the same behavior, but any mutations
(and optionally aliasing) performed on intermediate tensors
in the function will be removed.
functionalize will also remove mutations (and views) that were performed on function inputs.
However to preserve semantics, functionalize will "fix up" the mutations after
the transform has finished running, by detecting if any tensor inputs "should have"
been mutated, and copying the new data back to the inputs if necessary.
Example::
>>> # xdoctest: +SKIP
>>> import torch
>>> from torch.fx.experimental.proxy_tensor import make_fx
>>> from torch.func import functionalize
>>>
>>> # A function that uses mutations and views, but only on intermediate tensors.
>>> def f(a):
... b = a + 1
... c = b.view(-1)
... c.add_(1)
... return b
...
>>> inpt = torch.randn(2)
>>>
>>> out1 = f(inpt)
>>> out2 = functionalize(f)(inpt)
>>>
>>> # semantics are the same (outputs are equivalent)
>>> print(torch.allclose(out1, out2))
True
>>>
>>> f_traced = make_fx(f)(inpt)
>>> f_no_mutations_traced = make_fx(functionalize(f))(inpt)
>>> f_no_mutations_and_views_traced = make_fx(functionalize(f, remove='mutations_and_views'))(inpt)
>>>
>>> print(f_traced.code)
def forward(self, a_1):
add = torch.ops.aten.add(a_1, 1); a_1 = None
view = torch.ops.aten.view(add, [-1])
add_ = torch.ops.aten.add_(view, 1); view = None
return add
>>> print(f_no_mutations_traced.code)
def forward(self, a_1):
add = torch.ops.aten.add(a_1, 1); a_1 = None
view = torch.ops.aten.view(add, [-1]); add = None
add_1 = torch.ops.aten.add(view, 1); view = None
view_1 = torch.ops.aten.view(add_1, [2]); add_1 = None
return view_1
>>> print(f_no_mutations_and_views_traced.code)
def forward(self, a_1):
add = torch.ops.aten.add(a_1, 1); a_1 = None
view_copy = torch.ops.aten.view_copy(add, [-1]); add = None
add_1 = torch.ops.aten.add(view_copy, 1); view_copy = None
view_copy_1 = torch.ops.aten.view_copy(add_1, [2]); add_1 = None
return view_copy_1
>>> # A function that mutates its input tensor
>>> def f(a):
... b = a.view(-1)
... b.add_(1)
... return a
...
>>> f_no_mutations_and_views_traced = make_fx(functionalize(f, remove='mutations_and_views'))(inpt)
>>> #
>>> # All mutations and views have been removed,
>>> # but there is an extra copy_ in the graph to correctly apply the mutation to the input
>>> # after the function has completed.
>>> print(f_no_mutations_and_views_traced.code)
def forward(self, a_1):
view_copy = torch.ops.aten.view_copy(a_1, [-1])
add = torch.ops.aten.add(view_copy, 1); view_copy = None
view_copy_1 = torch.ops.aten.view_copy(add, [2]); add = None
copy_ = torch.ops.aten.copy_(a_1, view_copy_1); a_1 = None
return view_copy_1
There are a few "failure modes" for functionalize that are worth calling out:
(1) Like other torch.func transforms, `functionalize()` doesn't work with functions
that directly use `.backward()`. The same is true for torch.autograd.grad.
If you want to use autograd, you can compute gradients directly
with `functionalize(grad(f))`.
(2) Like other torch.func transforms, `functionalize()` doesn't work with global state.
If you call `functionalize(f)` on a function that takes views / mutations of
non-local state, functionalization will simply no-op and pass the view/mutation
calls directly to the backend.
One way to work around this is to ensure that any non-local state creation
is wrapped into a larger function, which you then call functionalize on.
(3) `resize_()` has some limitations: functionalize will only work on programs
that use resize_()` as long as the tensor being resized is not a view.
(4) `as_strided()` has some limitations: functionalize will not work on
`as_strided()` calls that result in tensors with overlapping memory.
Finally, a helpful mental model for understanding functionalization is that
most user pytorch programs are writing with the public torch API.
When executed, torch operators are generally decomposed into
our internal C++ "ATen" API.
The logic for functionalization happens entirely at the level of ATen.
Functionalization knows how to take every aliasing operator in ATen,
and map it to its non-aliasing equivalent
(e.g. ``tensor.view({-1})`` -> ``at::view_copy(tensor, {-1})``),
and how to take every mutating operator in ATen,
and map it to its non-mutating equivalent
(e.g. ``tensor.add_(1)`` -> ``at::add(tensor, -1)``),
while tracking aliases and mutations out-of-line to know when to fix things up.
Information about which ATen operators are aliasing or mutating all comes from
https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/native_functions.yaml.
grad(func: 'Callable[_P, Any]', argnums: 'argnums_t' = 0, has_aux: 'bool' = False) -> 'Callable[_P, Any]'
``grad`` operator helps computing gradients of ``func`` with respect to the
input(s) specified by ``argnums``. This operator can be nested to
compute higher-order gradients.
Args:
func (Callable): A Python function that takes one or more arguments.
Must return a single-element Tensor. If specified ``has_aux`` equals ``True``,
function can return a tuple of single-element Tensor and other auxiliary objects:
``(output, aux)``.
argnums (int or Tuple[int]): Specifies arguments to compute gradients with respect to.
``argnums`` can be single integer or tuple of integers. Default: 0.
has_aux (bool): Flag indicating that ``func`` returns a tensor and other
auxiliary objects: ``(output, aux)``. Default: False.
Returns:
Function to compute gradients with respect to its inputs. By default, the output of
the function is the gradient tensor(s) with respect to the first argument.
If specified ``has_aux`` equals ``True``, tuple of gradients and output auxiliary objects
is returned. If ``argnums`` is a tuple of integers, a tuple of output gradients with
respect to each ``argnums`` value is returned.
Example of using ``grad``:
>>> # xdoctest: +SKIP
>>> from torch.func import grad
>>> x = torch.randn([])
>>> cos_x = grad(lambda x: torch.sin(x))(x)
>>> assert torch.allclose(cos_x, x.cos())
>>>
>>> # Second-order gradients
>>> neg_sin_x = grad(grad(lambda x: torch.sin(x)))(x)
>>> assert torch.allclose(neg_sin_x, -x.sin())
When composed with ``vmap``, ``grad`` can be used to compute per-sample-gradients:
>>> # xdoctest: +SKIP
>>> from torch.func import grad, vmap
>>> batch_size, feature_size = 3, 5
>>>
>>> def model(weights, feature_vec):
>>> # Very simple linear model with activation
>>> assert feature_vec.dim() == 1
>>> return feature_vec.dot(weights).relu()
>>>
>>> def compute_loss(weights, example, target):
>>> y = model(weights, example)
>>> return ((y - target) ** 2).mean() # MSELoss
>>>
>>> weights = torch.randn(feature_size, requires_grad=True)
>>> examples = torch.randn(batch_size, feature_size)
>>> targets = torch.randn(batch_size)
>>> inputs = (weights, examples, targets)
>>> grad_weight_per_example = vmap(grad(compute_loss), in_dims=(None, 0, 0))(
... *inputs
... )
Example of using ``grad`` with ``has_aux`` and ``argnums``:
>>> # xdoctest: +SKIP
>>> from torch.func import grad
>>> def my_loss_func(y, y_pred):
>>> loss_per_sample = (0.5 * y_pred - y) ** 2
>>> loss = loss_per_sample.mean()
>>> return loss, (y_pred, loss_per_sample)
>>>
>>> fn = grad(my_loss_func, argnums=(0, 1), has_aux=True)
>>> y_true = torch.rand(4)
>>> y_preds = torch.rand(4, requires_grad=True)
>>> out = fn(y_true, y_preds)
>>> # > output is ((grads w.r.t y_true, grads w.r.t y_preds), (y_pred, loss_per_sample))
.. note::
Using PyTorch ``torch.no_grad`` together with ``grad``.
Case 1: Using ``torch.no_grad`` inside a function:
>>> # xdoctest: +SKIP
>>> def f(x):
>>> with torch.no_grad():
>>> c = x ** 2
>>> return x - c
In this case, ``grad(f)(x)`` will respect the inner ``torch.no_grad``.
Case 2: Using ``grad`` inside ``torch.no_grad`` context manager:
>>> # xdoctest: +SKIP
>>> with torch.no_grad():
>>> grad(f)(x)
In this case, ``grad`` will respect the inner ``torch.no_grad``, but not the
outer one. This is because ``grad`` is a "function transform": its result
should not depend on the result of a context manager outside of ``f``.
grad_and_value(func: 'Callable[_P, Any]', argnums: 'argnums_t' = 0, has_aux: 'bool' = False) -> 'Callable[_P, tuple[Any, Any]]'
Returns a function to compute a tuple of the gradient and primal, or
forward, computation.
Args:
func (Callable): A Python function that takes one or more arguments.
Must return a single-element Tensor. If specified ``has_aux``
equals ``True``, function can return a tuple of single-element
Tensor and other auxiliary objects: ``(output, aux)``.
argnums (int or Tuple[int]): Specifies arguments to compute gradients
with respect to. ``argnums`` can be single integer or tuple of
integers. Default: 0.
has_aux (bool): Flag indicating that ``func`` returns a tensor and
other auxiliary objects: ``(output, aux)``. Default: False.
Returns:
Function to compute a tuple of gradients with respect to its inputs
and the forward computation. By default, the output of the function is
a tuple of the gradient tensor(s) with respect to the first argument
and the primal computation. If specified ``has_aux`` equals
``True``, tuple of gradients and tuple of the forward computation with
output auxiliary objects is returned. If ``argnums`` is a tuple of
integers, a tuple of a tuple of the output gradients with respect to
each ``argnums`` value and the forward computation is returned.
See :func:`grad` for examples
hessian(func: 'Callable[..., Any]', argnums: 'argnums_t' = 0) -> 'Callable[..., Any]'
Computes the Hessian of ``func`` with respect to the arg(s) at index
``argnum`` via a forward-over-reverse strategy.
The forward-over-reverse strategy (composing ``jacfwd(jacrev(func))``) is
a good default for good performance. It is possible to compute Hessians
through other compositions of :func:`jacfwd` and :func:`jacrev` like
``jacfwd(jacfwd(func))`` or ``jacrev(jacrev(func))``.
Args:
func (function): A Python function that takes one or more arguments,
one of which must be a Tensor, and returns one or more Tensors
argnums (int or tuple[int, ...]): Optional, integer or tuple of integers,
saying which arguments to get the Hessian with respect to.
Default: 0.
Returns:
Returns a function that takes in the same inputs as ``func`` and
returns the Hessian of ``func`` with respect to the arg(s) at
``argnums``.
.. note::
You may see this API error out with "forward-mode AD not implemented
for operator X". If so, please file a bug report and we will prioritize it.
An alternative is to use ``jacrev(jacrev(func))``, which has better
operator coverage.
A basic usage with a R^N -> R^1 function gives a N x N Hessian:
>>> from torch.func import hessian
>>> def f(x):
>>> return x.sin().sum()
>>>
>>> x = torch.randn(5)
>>> hess = hessian(f)(x) # equivalent to jacfwd(jacrev(f))(x)
>>> assert torch.allclose(hess, torch.diag(-x.sin()))
jacfwd(func: 'Callable[..., Any]', argnums: 'argnums_t' = 0, has_aux: 'bool' = False, *, randomness: 'str' = 'error') -> 'Callable[..., Any]'
Computes the Jacobian of ``func`` with respect to the arg(s) at index
``argnum`` using forward-mode autodiff
Args:
func (function): A Python function that takes one or more arguments,
one of which must be a Tensor, and returns one or more Tensors
argnums (int or tuple[int, ...]): Optional, integer or tuple of integers,
saying which arguments to get the Jacobian with respect to.
Default: 0.
has_aux (bool): Flag indicating that ``func`` returns a
``(output, aux)`` tuple where the first element is the output of
the function to be differentiated and the second element is
auxiliary objects that will not be differentiated.
Default: False.
randomness(str): Flag indicating what type of randomness to use.
See :func:`vmap` for more detail. Allowed: "different", "same", "error".
Default: "error"
Returns:
Returns a function that takes in the same inputs as ``func`` and
returns the Jacobian of ``func`` with respect to the arg(s) at
``argnums``. If ``has_aux is True``, then the returned function
instead returns a ``(jacobian, aux)`` tuple where ``jacobian``
is the Jacobian and ``aux`` is auxiliary objects returned by ``func``.
.. note::
You may see this API error out with "forward-mode AD not implemented
for operator X". If so, please file a bug report and we will prioritize it.
An alternative is to use :func:`jacrev`, which has better operator coverage.
A basic usage with a pointwise, unary operation will give a diagonal array
as the Jacobian
>>> from torch.func import jacfwd
>>> x = torch.randn(5)
>>> jacobian = jacfwd(torch.sin)(x)
>>> expected = torch.diag(torch.cos(x))
>>> assert torch.allclose(jacobian, expected)
:func:`jacfwd` can be composed with vmap to produce batched
Jacobians:
>>> from torch.func import jacfwd, vmap
>>> x = torch.randn(64, 5)
>>> jacobian = vmap(jacfwd(torch.sin))(x)
>>> assert jacobian.shape == (64, 5, 5)
If you would like to compute the output of the function as well as the
jacobian of the function, use the ``has_aux`` flag to return the output
as an auxiliary object:
>>> from torch.func import jacfwd
>>> x = torch.randn(5)
>>>
>>> def f(x):
>>> return x.sin()
>>>
>>> def g(x):
>>> result = f(x)
>>> return result, result
>>>
>>> jacobian_f, f_x = jacfwd(g, has_aux=True)(x)
>>> assert torch.allclose(f_x, f(x))
Additionally, :func:`jacrev` can be composed with itself or :func:`jacrev`
to produce Hessians
>>> from torch.func import jacfwd, jacrev
>>> def f(x):
>>> return x.sin().sum()
>>>
>>> x = torch.randn(5)
>>> hessian = jacfwd(jacrev(f))(x)
>>> assert torch.allclose(hessian, torch.diag(-x.sin()))
By default, :func:`jacfwd` computes the Jacobian with respect to the first
input. However, it can compute the Jacboian with respect to a different
argument by using ``argnums``:
>>> from torch.func import jacfwd
>>> def f(x, y):
>>> return x + y ** 2
>>>
>>> x, y = torch.randn(5), torch.randn(5)
>>> jacobian = jacfwd(f, argnums=1)(x, y)
>>> expected = torch.diag(2 * y)
>>> assert torch.allclose(jacobian, expected)
Additionally, passing a tuple to ``argnums`` will compute the Jacobian
with respect to multiple arguments
>>> from torch.func import jacfwd
>>> def f(x, y):
>>> return x + y ** 2
>>>
>>> x, y = torch.randn(5), torch.randn(5)
>>> jacobian = jacfwd(f, argnums=(0, 1))(x, y)
>>> expectedX = torch.diag(torch.ones_like(x))
>>> expectedY = torch.diag(2 * y)
>>> assert torch.allclose(jacobian[0], expectedX)
>>> assert torch.allclose(jacobian[1], expectedY)
jacrev(func: 'Callable[..., Any]', argnums: 'int | tuple[int, ...]' = 0, *, has_aux: 'bool' = False, chunk_size: 'int | None' = None, _preallocate_and_copy: 'bool' = False) -> 'Callable[..., Any]'
Computes the Jacobian of ``func`` with respect to the arg(s) at index
``argnum`` using reverse mode autodiff
.. note::
Using :attr:`chunk_size=1` is equivalent to computing the jacobian
row-by-row with a for-loop i.e. the constraints of :func:`vmap` are
not applicable.
Args:
func (function): A Python function that takes one or more arguments,
one of which must be a Tensor, and returns one or more Tensors
argnums (int or tuple[int, ...]): Optional, integer or tuple of integers,
saying which arguments to get the Jacobian with respect to.
Default: 0.
has_aux (bool): Flag indicating that ``func`` returns a
``(output, aux)`` tuple where the first element is the output of
the function to be differentiated and the second element is
auxiliary objects that will not be differentiated.
Default: False.
chunk_size (None or int): If None (default), use the maximum chunk size
(equivalent to doing a single vmap over vjp to compute the jacobian).
If 1, then compute the jacobian row-by-row with a for-loop.
If not None, then compute the jacobian :attr:`chunk_size` rows at a time
(equivalent to doing multiple vmap over vjp). If you run into memory issues computing
the jacobian, please try to specify a non-None chunk_size.
Returns:
Returns a function that takes in the same inputs as ``func`` and
returns the Jacobian of ``func`` with respect to the arg(s) at
``argnums``. If ``has_aux is True``, then the returned function
instead returns a ``(jacobian, aux)`` tuple where ``jacobian``
is the Jacobian and ``aux`` is auxiliary objects returned by ``func``.
A basic usage with a pointwise, unary operation will give a diagonal array
as the Jacobian
>>> from torch.func import jacrev
>>> x = torch.randn(5)
>>> jacobian = jacrev(torch.sin)(x)
>>> expected = torch.diag(torch.cos(x))
>>> assert torch.allclose(jacobian, expected)
If you would like to compute the output of the function as well as the
jacobian of the function, use the ``has_aux`` flag to return the output
as an auxiliary object:
>>> from torch.func import jacrev
>>> x = torch.randn(5)
>>>
>>> def f(x):
>>> return x.sin()
>>>
>>> def g(x):
>>> result = f(x)
>>> return result, result
>>>
>>> jacobian_f, f_x = jacrev(g, has_aux=True)(x)
>>> assert torch.allclose(f_x, f(x))
:func:`jacrev` can be composed with vmap to produce batched
Jacobians:
>>> from torch.func import jacrev, vmap
>>> x = torch.randn(64, 5)
>>> jacobian = vmap(jacrev(torch.sin))(x)
>>> assert jacobian.shape == (64, 5, 5)
Additionally, :func:`jacrev` can be composed with itself to produce
Hessians
>>> from torch.func import jacrev
>>> def f(x):
>>> return x.sin().sum()
>>>
>>> x = torch.randn(5)
>>> hessian = jacrev(jacrev(f))(x)
>>> assert torch.allclose(hessian, torch.diag(-x.sin()))
By default, :func:`jacrev` computes the Jacobian with respect to the first
input. However, it can compute the Jacboian with respect to a different
argument by using ``argnums``:
>>> from torch.func import jacrev
>>> def f(x, y):
>>> return x + y ** 2
>>>
>>> x, y = torch.randn(5), torch.randn(5)
>>> jacobian = jacrev(f, argnums=1)(x, y)
>>> expected = torch.diag(2 * y)
>>> assert torch.allclose(jacobian, expected)
Additionally, passing a tuple to ``argnums`` will compute the Jacobian
with respect to multiple arguments
>>> from torch.func import jacrev
>>> def f(x, y):
>>> return x + y ** 2
>>>
>>> x, y = torch.randn(5), torch.randn(5)
>>> jacobian = jacrev(f, argnums=(0, 1))(x, y)
>>> expectedX = torch.diag(torch.ones_like(x))
>>> expectedY = torch.diag(2 * y)
>>> assert torch.allclose(jacobian[0], expectedX)
>>> assert torch.allclose(jacobian[1], expectedY)
.. note::
Using PyTorch ``torch.no_grad`` together with ``jacrev``.
Case 1: Using ``torch.no_grad`` inside a function:
>>> def f(x):
>>> with torch.no_grad():
>>> c = x ** 2
>>> return x - c
In this case, ``jacrev(f)(x)`` will respect the inner ``torch.no_grad``.
Case 2: Using ``jacrev`` inside ``torch.no_grad`` context manager:
>>> with torch.no_grad():
>>> jacrev(f)(x)
In this case, ``jacrev`` will respect the inner ``torch.no_grad``, but not the
outer one. This is because ``jacrev`` is a "function transform": its result
should not depend on the result of a context manager outside of ``f``.
jvp(func: 'Callable[..., Any]', primals: 'Any', tangents: 'Any', *, strict: 'bool' = False, has_aux: 'bool' = False) -> 'tuple[Any, Any] | tuple[Any, Any, Any]'
Standing for the Jacobian-vector product, returns a tuple containing
the output of `func(*primals)` and the "Jacobian of ``func`` evaluated at
``primals``" times ``tangents``. This is also known as forward-mode autodiff.
Args:
func (function): A Python function that takes one or more arguments,
one of which must be a Tensor, and returns one or more Tensors
primals (Tensors): Positional arguments to ``func`` that must all be
Tensors. The returned function will also be computing the
derivative with respect to these arguments
tangents (Tensors): The "vector" for which Jacobian-vector-product is
computed. Must be the same structure and sizes as the inputs to
``func``.
has_aux (bool): Flag indicating that ``func`` returns a
``(output, aux)`` tuple where the first element is the output of
the function to be differentiated and the second element is
other auxiliary objects that will not be differentiated.
Default: False.
Returns:
Returns a ``(output, jvp_out)`` tuple containing the output of ``func``
evaluated at ``primals`` and the Jacobian-vector product.
If ``has_aux is True``, then instead returns a ``(output, jvp_out, aux)`` tuple.
.. note::
You may see this API error out with "forward-mode AD not implemented
for operator X". If so, please file a bug report and we will prioritize it.
jvp is useful when you wish to compute gradients of a function R^1 -> R^N
>>> from torch.func import jvp
>>> x = torch.randn([])
>>> f = lambda x: x * torch.tensor([1.0, 2.0, 3])
>>> value, grad = jvp(f, (x,), (torch.tensor(1.0),))
>>> assert torch.allclose(value, f(x))
>>> assert torch.allclose(grad, torch.tensor([1.0, 2, 3]))
:func:`jvp` can support functions with multiple inputs by passing in the
tangents for each of the inputs
>>> from torch.func import jvp
>>> x = torch.randn(5)
>>> y = torch.randn(5)
>>> f = lambda x, y: (x * y)
>>> _, output = jvp(f, (x, y), (torch.ones(5), torch.ones(5)))
>>> assert torch.allclose(output, x + y)
linearize(func: 'Callable[..., Any]', *primals: 'Any') -> 'tuple[Any, Callable[..., Any]]'
Returns the value of ``func`` at ``primals`` and linear approximation
at ``primals``.
Args:
func (Callable[..., Any]): A Python function that takes one or more arguments.
primals (Tensors): Positional arguments to ``func`` that must all be
Tensors. These are the values at which the function is linearly approximated.
Returns:
Returns a ``(output, jvp_fn)`` tuple containing the output of ``func``
applied to ``primals`` and a function that computes the jvp of
``func`` evaluated at ``primals``.
linearize is useful if jvp is to be computed multiple times at ``primals``. However,
to achieve this, linearize saves intermediate computation and has higher memory requirements
than directly applying `jvp`. So, if all the ``tangents`` are known, it maybe more efficient
to compute vmap(jvp) instead of using linearize.
.. note::
linearize evaluates ``func`` twice. Please file an issue for an implementation
with a single evaluation.
Example::
>>> import torch
>>> from torch.func import linearize
>>> def fn(x):
... return x.sin()
...
>>> output, jvp_fn = linearize(fn, torch.zeros(3, 3))
>>> jvp_fn(torch.ones(3, 3))
tensor([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]])
>>>
rearrange(tensor: 'torch.Tensor | list[torch.Tensor] | tuple[torch.Tensor, ...]', pattern: 'str', **axes_lengths: 'int') -> 'torch.Tensor'
A native implementation of `einops.rearrange`, a reader-friendly smart element reordering for multidimensional
tensors. This operation includes functionality of transpose (axes permutation), reshape (view), squeeze, unsqueeze,
stack, concatenate and other operations.
See: https://einops.rocks/api/rearrange/
Args:
tensor (Tensor or sequence of Tensor): the tensor(s) to rearrange
pattern (str): the rearrangement pattern
axes_lengths (int): any additional length specifications for dimensions
Returns:
Tensor: the rearranged tensor
Examples:
>>> from torch.func import rearrange
>>> # suppose we have a set of 32 images in "h w c" format (height-width-channel)
>>> images = torch.randn((32, 30, 40, 3))
>>> # stack along first (batch) axis, output is a single array
>>> rearrange(images, "b h w c -> b h w c").shape
torch.Size([32, 30, 40, 3])
>>> # concatenate images along height (vertical axis), 960 = 32 * 30
>>> rearrange(images, "b h w c -> (b h) w c").shape
torch.Size([960, 40, 3])
>>> # concatenated images along horizontal axis, 1280 = 32 * 40
>>> rearrange(images, "b h w c -> h (b w) c").shape
torch.Size([30, 1280, 3])
>>> # reordered axes to "b c h w" format for deep learning
>>> rearrange(images, "b h w c -> b c h w").shape
torch.Size([32, 3, 30, 40])
>>> # flattened each image into a vector, 3600 = 30 * 40 * 3
>>> rearrange(images, "b h w c -> b (c h w)").shape
torch.Size([32, 3600])
>>> # split each image into 4 smaller (top-left, top-right, bottom-left, bottom-right), 128 = 32 * 2 * 2
>>> rearrange(images, "b (h1 h) (w1 w) c -> (b h1 w1) h w c", h1=2, w1=2).shape
torch.Size([128, 15, 20, 3])
>>> # space-to-depth operation
>>> rearrange(images, "b (h h1) (w w1) c -> b h w (c h1 w1)", h1=2, w1=2).shape
torch.Size([32, 15, 20, 12])
replace_all_batch_norm_modules_(root: torch.nn.modules.module.Module) -> torch.nn.modules.module.Module
In place updates :attr:`root` by setting the ``running_mean`` and ``running_var`` to be None and
setting track_running_stats to be False for any nn.BatchNorm module in :attr:`root`
stack_module_state(models: 'Sequence[nn.Module] | nn.ModuleList') -> 'tuple[dict[str, Any], dict[str, Any]]'
stack_module_state(models) -> params, buffers
Prepares a list of torch.nn.Modules for ensembling with :func:`vmap`.
Given a list of ``M`` ``nn.Modules`` of the same class, returns two dictionaries
that stack all of their parameters and buffers together, indexed by name.
The stacked parameters are optimizable (i.e. they are new leaf nodes in the
autograd history that are unrelated to the original parameters and can be
passed directly to an optimizer).
Here's an example of how to ensemble over a very simple model:
.. code-block:: python
num_models = 5
batch_size = 64
in_features, out_features = 3, 3
models = [torch.nn.Linear(in_features, out_features) for i in range(num_models)]
data = torch.randn(batch_size, 3)
def wrapper(params, buffers, data):
return torch.func.functional_call(models[0], (params, buffers), data)
params, buffers = stack_module_state(models)
output = vmap(wrapper, (0, 0, None))(params, buffers, data)
assert output.shape == (num_models, batch_size, out_features)
When there's submodules, this follows state dict naming conventions
.. code-block:: python
import torch.nn as nn
class Foo(nn.Module):
def __init__(self, in_features, out_features):
super().__init__()
hidden = 4
self.l1 = nn.Linear(in_features, hidden)
self.l2 = nn.Linear(hidden, out_features)
def forward(self, x):
return self.l2(self.l1(x))
num_models = 5
in_features, out_features = 3, 3
models = [Foo(in_features, out_features) for i in range(num_models)]
params, buffers = stack_module_state(models)
print(list(params.keys())) # "l1.weight", "l1.bias", "l2.weight", "l2.bias"
.. warning::
All of the modules being stacked together must be the same (except for
the values of their parameters/buffers). For example, they should be in the
same mode (training vs eval).
vjp(func: 'Callable[..., Any]', *primals: 'Any', has_aux: 'bool' = False) -> 'tuple[Any, Callable[..., Any]] | tuple[Any, Callable[..., Any], Any]'
Standing for the vector-Jacobian product, returns a tuple containing the
results of ``func`` applied to ``primals`` and a function that, when
given ``cotangents``, computes the reverse-mode Jacobian of ``func`` with
respect to ``primals`` times ``cotangents``.
Args:
func (Callable[..., Any]): A Python function that takes one or more arguments. Must
return one or more Tensors.
primals (Tensors): Positional arguments to ``func`` that must all be
Tensors. The returned function will also be computing the
derivative with respect to these arguments
has_aux (bool): Flag indicating that ``func`` returns a
``(output, aux)`` tuple where the first element is the output of
the function to be differentiated and the second element is
other auxiliary objects that will not be differentiated.
Default: False.
Returns:
Returns a ``(output, vjp_fn)`` tuple containing the output of ``func``
applied to ``primals`` and a function that computes the vjp of
``func`` with respect to all ``primals`` using the cotangents passed
to the returned function. If ``has_aux is True``, then instead returns a
``(output, vjp_fn, aux)`` tuple.
The returned ``vjp_fn`` function will return a tuple of each VJP.
When used in simple cases, :func:`vjp` behaves the same as :func:`grad`
>>> x = torch.randn([5])
>>> f = lambda x: x.sin().sum()
>>> (_, vjpfunc) = torch.func.vjp(f, x)
>>> grad = vjpfunc(torch.tensor(1.0))[0]
>>> assert torch.allclose(grad, torch.func.grad(f)(x))
However, :func:`vjp` can support functions with multiple outputs by
passing in the cotangents for each of the outputs
>>> x = torch.randn([5])
>>> f = lambda x: (x.sin(), x.cos())
>>> (_, vjpfunc) = torch.func.vjp(f, x)
>>> vjps = vjpfunc((torch.ones([5]), torch.ones([5])))
>>> assert torch.allclose(vjps[0], x.cos() + -x.sin())
:func:`vjp` can even support outputs being Python structs
>>> x = torch.randn([5])
>>> f = lambda x: {"first": x.sin(), "second": x.cos()}
>>> (_, vjpfunc) = torch.func.vjp(f, x)
>>> cotangents = {"first": torch.ones([5]), "second": torch.ones([5])}
>>> vjps = vjpfunc(cotangents)
>>> assert torch.allclose(vjps[0], x.cos() + -x.sin())
The function returned by :func:`vjp` will compute the partials with
respect to each of the ``primals``
>>> x, y = torch.randn([5, 4]), torch.randn([4, 5])
>>> (_, vjpfunc) = torch.func.vjp(torch.matmul, x, y)
>>> cotangents = torch.randn([5, 5])
>>> vjps = vjpfunc(cotangents)
>>> assert len(vjps) == 2
>>> assert torch.allclose(vjps[0], torch.matmul(cotangents, y.transpose(0, 1)))
>>> assert torch.allclose(vjps[1], torch.matmul(x.transpose(0, 1), cotangents))
``primals`` are the positional arguments for ``f``. All kwargs use their
default value
>>> x = torch.randn([5])
>>> def f(x, scale=4.):
>>> return x * scale
>>>
>>> (_, vjpfunc) = torch.func.vjp(f, x)
>>> vjps = vjpfunc(torch.ones_like(x))
>>> assert torch.allclose(vjps[0], torch.full(x.shape, 4.0))
.. note::
Using PyTorch ``torch.no_grad`` together with ``vjp``.
Case 1: Using ``torch.no_grad`` inside a function:
>>> def f(x):
>>> with torch.no_grad():
>>> c = x ** 2
>>> return x - c
In this case, ``vjp(f)(x)`` will respect the inner ``torch.no_grad``.
Case 2: Using ``vjp`` inside ``torch.no_grad`` context manager:
>>> # xdoctest: +SKIP(failing)
>>> with torch.no_grad():
>>> vjp(f)(x)
In this case, ``vjp`` will respect the inner ``torch.no_grad``, but not the
outer one. This is because ``vjp`` is a "function transform": its result
should not depend on the result of a context manager outside of ``f``.
vmap(func: 'Callable[_P, _R]', in_dims: 'in_dims_t' = 0, out_dims: 'out_dims_t' = 0, randomness: 'str' = 'error', *, chunk_size: 'int | None' = None) -> 'Callable[_P, _R]'
vmap is the vectorizing map; ``vmap(func)`` returns a new function that
maps ``func`` over some dimension of the inputs. Semantically, vmap
pushes the map into PyTorch operations called by ``func``, effectively
vectorizing those operations.
vmap is useful for handling batch dimensions: one can write a function
``func`` that runs on examples and then lift it to a function that can
take batches of examples with ``vmap(func)``. vmap can also be used to
compute batched gradients when composed with autograd.
.. note::
:func:`torch.vmap` is aliased to :func:`torch.func.vmap` for
convenience. Use whichever one you'd like.
Args:
func (function): A Python function that takes one or more arguments.
Must return one or more Tensors.
in_dims (int or nested structure): Specifies which dimension of the
inputs should be mapped over. ``in_dims`` should have a
structure like the inputs. If the ``in_dim`` for a particular
input is None, then that indicates there is no map dimension.
Default: 0.
out_dims (int or Tuple[int]): Specifies where the mapped dimension
should appear in the outputs. If ``out_dims`` is a Tuple, then
it should have one element per output. Default: 0.
randomness (str): Specifies whether the randomness in this
vmap should be the same or different across batches. If 'different',
the randomness for each batch will be different. If 'same', the
randomness will be the same across batches. If 'error', any calls to
random functions will error. Default: 'error'. WARNING: this flag
only applies to random PyTorch operations and does not apply to
Python's random module or numpy randomness.
chunk_size (None or int): If None (default), apply a single vmap over inputs.
If not None, then compute the vmap :attr:`chunk_size` samples at a time.
Note that :attr:`chunk_size=1` is equivalent to computing the vmap with a for-loop.
If you run into memory issues computing the vmap, please try a non-None chunk_size.
Returns:
Returns a new "batched" function. It takes the same inputs as
``func``, except each input has an extra dimension at the index
specified by ``in_dims``. It takes returns the same outputs as
``func``, except each output has an extra dimension at the index
specified by ``out_dims``.
.. warning:
:func:`vmap` works best with functional-style code. Please do not
perform any side-effects in ``func``, with the exception of
in-place PyTorch operations. Examples of side-effects include mutating
Python data structures and assigning values to variables not captured
in ``func``.
One example of using :func:`vmap` is to compute batched dot products. PyTorch
doesn't provide a batched ``torch.dot`` API; instead of unsuccessfully
rummaging through docs, use :func:`vmap` to construct a new function.
>>> torch.dot # [D], [D] -> []
>>> batched_dot = torch.func.vmap(torch.dot) # [N, D], [N, D] -> [N]
>>> x, y = torch.randn(2, 5), torch.randn(2, 5)
>>> batched_dot(x, y)
:func:`vmap` can be helpful in hiding batch dimensions, leading to a simpler
model authoring experience.
>>> batch_size, feature_size = 3, 5
>>> weights = torch.randn(feature_size, requires_grad=True)
>>>
>>> def model(feature_vec):
>>> # Very simple linear model with activation
>>> return feature_vec.dot(weights).relu()
>>>
>>> examples = torch.randn(batch_size, feature_size)
>>> result = torch.vmap(model)(examples)
:func:`vmap` can also help vectorize computations that were previously difficult
or impossible to batch. One example is higher-order gradient computation.
The PyTorch autograd engine computes vjps (vector-Jacobian products).
Computing a full Jacobian matrix for some function f: R^N -> R^N usually
requires N calls to ``autograd.grad``, one per Jacobian row. Using :func:`vmap`,
we can vectorize the whole computation, computing the Jacobian in a single
call to ``autograd.grad``.
>>> # Setup
>>> N = 5
>>> f = lambda x: x**2
>>> x = torch.randn(N, requires_grad=True)
>>> y = f(x)
>>> I_N = torch.eye(N)
>>>
>>> # Sequential approach
>>> jacobian_rows = [torch.autograd.grad(y, x, v, retain_graph=True)[0]
>>> for v in I_N.unbind()]
>>> jacobian = torch.stack(jacobian_rows)
>>>
>>> # vectorized gradient computation
>>> def get_vjp(v):
>>> return torch.autograd.grad(y, x, v)
>>> jacobian = torch.vmap(get_vjp)(I_N)
:func:`vmap` can also be nested, producing an output with multiple batched dimensions
>>> torch.dot # [D], [D] -> []
>>> batched_dot = torch.vmap(
... torch.vmap(torch.dot)
... ) # [N1, N0, D], [N1, N0, D] -> [N1, N0]
>>> x, y = torch.randn(2, 3, 5), torch.randn(2, 3, 5)
>>> batched_dot(x, y) # tensor of size [2, 3]
If the inputs are not batched along the first dimension, ``in_dims`` specifies
the dimension that each inputs are batched along as
>>> torch.dot # [N], [N] -> []
>>> batched_dot = torch.vmap(torch.dot, in_dims=1) # [N, D], [N, D] -> [D]
>>> x, y = torch.randn(2, 5), torch.randn(2, 5)
>>> batched_dot(
... x, y
... ) # output is [5] instead of [2] if batched along the 0th dimension
If there are multiple inputs each of which is batched along different dimensions,
``in_dims`` must be a tuple with the batch dimension for each input as
>>> torch.dot # [D], [D] -> []
>>> batched_dot = torch.vmap(torch.dot, in_dims=(0, None)) # [N, D], [D] -> [N]
>>> x, y = torch.randn(2, 5), torch.randn(5)
>>> batched_dot(
... x, y
... ) # second arg doesn't have a batch dim because in_dim[1] was None
If the input is a Python struct, ``in_dims`` must be a tuple containing a struct
matching the shape of the input:
>>> f = lambda dict: torch.dot(dict["x"], dict["y"])
>>> x, y = torch.randn(2, 5), torch.randn(5)
>>> input = {"x": x, "y": y}
>>> batched_dot = torch.vmap(f, in_dims=({"x": 0, "y": None},))
>>> batched_dot(input)
By default, the output is batched along the first dimension. However, it can be batched
along any dimension by using ``out_dims``
>>> f = lambda x: x**2
>>> x = torch.randn(2, 5)
>>> batched_pow = torch.vmap(f, out_dims=1)
>>> batched_pow(x) # [5, 2]
For any function that uses kwargs, the returned function will not batch the kwargs but will
accept kwargs
>>> x = torch.randn([2, 5])
>>> def fn(x, scale=4.):
>>> return x * scale
>>>
>>> batched_pow = torch.vmap(fn)
>>> assert torch.allclose(batched_pow(x), x * 4)
>>> batched_pow(x, scale=x) # scale is not batched, output has shape [2, 2, 5]
.. note::
vmap does not provide general autobatching or handle variable-length
sequences out of the box.
DATA
__all__ = ['grad', 'grad_and_value', 'vmap', 'replace_all_batch_norm_m...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\func\__init__.py
torch.functional
Python Library Documentation: module torch.functional in torch
NAME
torch.functional - # mypy: allow-untyped-defs
FUNCTIONS
atleast_1d(*tensors)
Returns a 1-dimensional view of each input tensor with zero dimensions.
Input tensors with one or more dimensions are returned as-is.
Args:
input (Tensor or sequence of Tensors): tensor(s) to be converted to at least 1-dimensional.
Returns:
output (Tensor or tuple of Tensors)
Example::
>>> x = torch.arange(2)
>>> x
tensor([0, 1])
>>> torch.atleast_1d(x)
tensor([0, 1])
>>> x = torch.tensor(1.)
>>> x
tensor(1.)
>>> torch.atleast_1d(x)
tensor([1.])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.)
>>> torch.atleast_1d((x, y))
(tensor([0.5000]), tensor([1.]))
>>> torch.atleast_1d()
()
atleast_2d(*tensors)
Returns a 2-dimensional view of each input tensor with zero dimensions.
Input tensors with two or more dimensions are returned as-is.
Args:
input (Tensor or sequence of Tensors): tensor(s) to be converted to at least 2-dimensional.
Returns:
output (Tensor or tuple of Tensors)
Example::
>>> x = torch.tensor(1.)
>>> x
tensor(1.)
>>> torch.atleast_2d(x)
tensor([[1.]])
>>> x = torch.arange(4).view(2, 2)
>>> x
tensor([[0, 1],
[2, 3]])
>>> torch.atleast_2d(x)
tensor([[0, 1],
[2, 3]])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.)
>>> torch.atleast_2d((x, y))
(tensor([[0.5000]]), tensor([[1.]]))
>>> torch.atleast_2d()
()
atleast_3d(*tensors)
Returns a 3-dimensional view of each input tensor with zero dimensions.
Input tensors with three or more dimensions are returned as-is.
Args:
input (Tensor or sequence of Tensors): tensor(s) to be converted to at least 3-dimensional.
Returns:
output (Tensor or tuple of Tensors)
Example:
>>> x = torch.tensor(0.5)
>>> x
tensor(0.5000)
>>> torch.atleast_3d(x)
tensor([[[0.5000]]])
>>> y = torch.arange(4).view(2, 2)
>>> y
tensor([[0, 1],
[2, 3]])
>>> torch.atleast_3d(y)
tensor([[[0],
[1]],
<BLANKLINE>
[[2],
[3]]])
>>> x = torch.tensor(1).view(1, 1, 1)
>>> x
tensor([[[1]]])
>>> torch.atleast_3d(x)
tensor([[[1]]])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.0)
>>> torch.atleast_3d((x, y))
(tensor([[[0.5000]]]), tensor([[[1.]]]))
>>> torch.atleast_3d()
()
block_diag(*tensors)
Create a block diagonal matrix from provided tensors.
Args:
*tensors: One or more tensors with 0, 1, or 2 dimensions.
Returns:
Tensor: A 2 dimensional tensor with all the input tensors arranged in
order such that their upper left and lower right corners are
diagonally adjacent. All other elements are set to 0.
Example::
>>> import torch
>>> A = torch.tensor([[0, 1], [1, 0]])
>>> B = torch.tensor([[3, 4, 5], [6, 7, 8]])
>>> C = torch.tensor(7)
>>> D = torch.tensor([1, 2, 3])
>>> E = torch.tensor([[4], [5], [6]])
>>> torch.block_diag(A, B, C, D, E)
tensor([[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 3, 4, 5, 0, 0, 0, 0, 0],
[0, 0, 6, 7, 8, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 7, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 2, 3, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 5],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 6]])
broadcast_shapes(*shapes)
broadcast_shapes(*shapes) -> Size
Similar to :func:`broadcast_tensors` but for shapes.
This is equivalent to
``torch.broadcast_tensors(*map(torch.empty, shapes))[0].shape``
but avoids the need to create intermediate tensors. This is useful for
broadcasting tensors of common batch shape but different rightmost shape,
e.g. to broadcast mean vectors with covariance matrices.
Example::
>>> torch.broadcast_shapes((2,), (3, 1), (1, 1, 1))
torch.Size([1, 3, 2])
Args:
\*shapes (torch.Size): Shapes of tensors.
Returns:
shape (torch.Size): A shape compatible with all input shapes.
Raises:
RuntimeError: If shapes are incompatible.
broadcast_tensors(*tensors)
broadcast_tensors(*tensors) -> List of Tensors
Broadcasts the given tensors according to :ref:`broadcasting-semantics`.
Args:
*tensors: any number of tensors of the same type
.. warning::
More than one element of a broadcasted tensor may refer to a single
memory location. As a result, in-place operations (especially ones that
are vectorized) may result in incorrect behavior. If you need to write
to the tensors, please clone them first.
Example::
>>> x = torch.arange(3).view(1, 3)
>>> y = torch.arange(2).view(2, 1)
>>> a, b = torch.broadcast_tensors(x, y)
>>> a.size()
torch.Size([2, 3])
>>> a
tensor([[0, 1, 2],
[0, 1, 2]])
cartesian_prod(*tensors: torch.Tensor) -> torch.Tensor
Do cartesian product of the given sequence of tensors. The behavior is similar to
python's `itertools.product`.
Args:
*tensors: any number of 1 dimensional tensors.
Returns:
Tensor: A tensor equivalent to converting all the input tensors into lists,
do `itertools.product` on these lists, and finally convert the resulting list
into tensor.
Example::
>>> import itertools
>>> a = [1, 2, 3]
>>> b = [4, 5]
>>> list(itertools.product(a, b))
[(1, 4), (1, 5), (2, 4), (2, 5), (3, 4), (3, 5)]
>>> tensor_a = torch.tensor(a)
>>> tensor_b = torch.tensor(b)
>>> torch.cartesian_prod(tensor_a, tensor_b)
tensor([[1, 4],
[1, 5],
[2, 4],
[2, 5],
[3, 4],
[3, 5]])
cdist(x1, x2, p=2.0, compute_mode='use_mm_for_euclid_dist_if_necessary')
Computes batched the p-norm distance between each pair of the two collections of row vectors.
Args:
x1 (Tensor): input tensor where the last two dimensions represent the points and the feature dimension respectively.
The shape can be :math:`D_1 \times D_2 \times \cdots \times D_n \times P \times M`,
where :math:`P` is the number of points and :math:`M` is the feature dimension.
x2 (Tensor): input tensor where the last two dimensions also represent the points and the feature dimension respectively.
The shape can be :math:`D_1' \times D_2' \times \cdots \times D_m' \times R \times M`,
where :math:`R` is the number of points and :math:`M` is the feature dimension,
which should match the feature dimension of `x1`.
p: p value for the p-norm distance to calculate between each vector pair
:math:`\in [0, \infty]`.
compute_mode:
'use_mm_for_euclid_dist_if_necessary' - will use matrix multiplication approach to calculate
euclidean distance (p = 2) if P > 25 or R > 25
'use_mm_for_euclid_dist' - will always use matrix multiplication approach to calculate
euclidean distance (p = 2)
'donot_use_mm_for_euclid_dist' - will never use matrix multiplication approach to calculate
euclidean distance (p = 2)
Default: use_mm_for_euclid_dist_if_necessary.
If x1 has shape :math:`B \times P \times M` and x2 has shape :math:`B \times R \times M` then the
output will have shape :math:`B \times P \times R`.
This function is equivalent to `scipy.spatial.distance.cdist(input,'minkowski', p=p)`
if :math:`p \in (0, \infty)`. When :math:`p = 0` it is equivalent to
`scipy.spatial.distance.cdist(input, 'hamming') * M`. When :math:`p = \infty`, the closest
scipy function is `scipy.spatial.distance.cdist(xn, lambda x, y: np.abs(x - y).max())`.
Example:
>>> a = torch.tensor([[0.9041, 0.0196], [-0.3108, -2.4423], [-0.4821, 1.059]])
>>> a
tensor([[ 0.9041, 0.0196],
[-0.3108, -2.4423],
[-0.4821, 1.0590]])
>>> b = torch.tensor([[-2.1763, -0.4713], [-0.6986, 1.3702]])
>>> b
tensor([[-2.1763, -0.4713],
[-0.6986, 1.3702]])
>>> torch.cdist(a, b, p=2)
tensor([[3.1193, 2.0959],
[2.7138, 3.8322],
[2.2830, 0.3791]])
chain_matmul(*matrices, out=None)
Returns the matrix product of the :math:`N` 2-D tensors. This product is efficiently computed
using the matrix chain order algorithm which selects the order in which incurs the lowest cost in terms
of arithmetic operations (`[CLRS]`_). Note that since this is a function to compute the product, :math:`N`
needs to be greater than or equal to 2; if equal to 2 then a trivial matrix-matrix product is returned.
If :math:`N` is 1, then this is a no-op - the original matrix is returned as is.
.. warning::
:func:`torch.chain_matmul` is deprecated and will be removed in a future PyTorch release.
Use :func:`torch.linalg.multi_dot` instead, which accepts a list of two or more tensors
rather than multiple arguments.
Args:
matrices (Tensors...): a sequence of 2 or more 2-D tensors whose product is to be determined.
out (Tensor, optional): the output tensor. Ignored if :attr:`out` = ``None``.
Returns:
Tensor: if the :math:`i^{th}` tensor was of dimensions :math:`p_{i} \times p_{i + 1}`, then the product
would be of dimensions :math:`p_{1} \times p_{N + 1}`.
Example::
>>> # xdoctest: +SKIP
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> a = torch.randn(3, 4)
>>> b = torch.randn(4, 5)
>>> c = torch.randn(5, 6)
>>> d = torch.randn(6, 7)
>>> # will raise a deprecation warning
>>> torch.chain_matmul(a, b, c, d)
tensor([[ -2.3375, -3.9790, -4.1119, -6.6577, 9.5609, -11.5095, -3.2614],
[ 21.4038, 3.3378, -8.4982, -5.2457, -10.2561, -2.4684, 2.7163],
[ -0.9647, -5.8917, -2.3213, -5.2284, 12.8615, -12.2816, -2.5095]])
.. _`[CLRS]`: https://mitpress.mit.edu/books/introduction-algorithms-third-edition
einsum(*args: Any) -> torch.Tensor
einsum(equation, *operands) -> Tensor
Sums the product of the elements of the input :attr:`operands` along dimensions specified using a notation
based on the Einstein summation convention.
Einsum allows computing many common multi-dimensional linear algebraic array operations by representing them
in a short-hand format based on the Einstein summation convention, given by :attr:`equation`. The details of
this format are described below, but the general idea is to label every dimension of the input :attr:`operands`
with some subscript and define which subscripts are part of the output. The output is then computed by summing
the product of the elements of the :attr:`operands` along the dimensions whose subscripts are not part of the
output. For example, matrix multiplication can be computed using einsum as `torch.einsum("ij,jk->ik", A, B)`.
Here, j is the summation subscript and i and k the output subscripts (see section below for more details on why).
Equation:
The :attr:`equation` string specifies the subscripts (letters in `[a-zA-Z]`) for each dimension of
the input :attr:`operands` in the same order as the dimensions, separating subscripts for each operand by a
comma (','), e.g. `'ij,jk'` specify subscripts for two 2D operands. The dimensions labeled with the same subscript
must be broadcastable, that is, their size must either match or be `1`. The exception is if a subscript is
repeated for the same input operand, in which case the dimensions labeled with this subscript for this operand
must match in size and the operand will be replaced by its diagonal along these dimensions. The subscripts that
appear exactly once in the :attr:`equation` will be part of the output, sorted in increasing alphabetical order.
The output is computed by multiplying the input :attr:`operands` element-wise, with their dimensions aligned based
on the subscripts, and then summing out the dimensions whose subscripts are not part of the output.
Optionally, the output subscripts can be explicitly defined by adding an arrow ('->') at the end of the equation
followed by the subscripts for the output. For instance, the following equation computes the transpose of a
matrix multiplication: 'ij,jk->ki'. The output subscripts must appear at least once for some input operand and
at most once for the output.
Ellipsis ('...') can be used in place of subscripts to broadcast the dimensions covered by the ellipsis.
Each input operand may contain at most one ellipsis which will cover the dimensions not covered by subscripts,
e.g. for an input operand with 5 dimensions, the ellipsis in the equation `'ab...c'` cover the third and fourth
dimensions. The ellipsis does not need to cover the same number of dimensions across the :attr:`operands` but the
'shape' of the ellipsis (the size of the dimensions covered by them) must broadcast together. If the output is not
explicitly defined with the arrow ('->') notation, the ellipsis will come first in the output (left-most dimensions),
before the subscript labels that appear exactly once for the input operands. e.g. the following equation implements
batch matrix multiplication `'...ij,...jk'`.
A few final notes: the equation may contain whitespaces between the different elements (subscripts, ellipsis,
arrow and comma) but something like `'. . .'` is not valid. An empty string `''` is valid for scalar operands.
.. note::
``torch.einsum`` handles ellipsis ('...') differently from NumPy in that it allows dimensions
covered by the ellipsis to be summed over, that is, ellipsis are not required to be part of the output.
.. note::
Please install opt-einsum (https://optimized-einsum.readthedocs.io/en/stable/) in order to enroll into a more
performant einsum. You can install when installing torch like so: `pip install torch[opt-einsum]` or by itself
with `pip install opt-einsum`.
If opt-einsum is available, this function will automatically speed up computation and/or consume less memory
by optimizing contraction order through our opt_einsum backend :mod:`torch.backends.opt_einsum` (The _ vs - is
confusing, I know). This optimization occurs when there are at least three inputs, since the order does not matter
otherwise. Note that finding `the` optimal path is an NP-hard problem, thus, opt-einsum relies on different
heuristics to achieve near-optimal results. If opt-einsum is not available, the default order is to contract
from left to right.
To bypass this default behavior, add the following to disable opt_einsum and skip path calculation:
``torch.backends.opt_einsum.enabled = False``
To specify which strategy you'd like for opt_einsum to compute the contraction path, add the following line:
``torch.backends.opt_einsum.strategy = 'auto'``. The default strategy is 'auto', and we also support 'greedy' and
'optimal'. Disclaimer that the runtime of 'optimal' is factorial in the number of inputs! See more details in
the opt_einsum documentation (https://optimized-einsum.readthedocs.io/en/stable/path_finding.html).
.. note::
As of PyTorch 1.10 :func:`torch.einsum` also supports the sublist format (see examples below). In this format,
subscripts for each operand are specified by sublists, list of integers in the range [0, 52). These sublists
follow their operands, and an extra sublist can appear at the end of the input to specify the output's
subscripts., e.g. `torch.einsum(op1, sublist1, op2, sublist2, ..., [subslist_out])`. Python's `Ellipsis` object
may be provided in a sublist to enable broadcasting as described in the Equation section above.
Args:
equation (str): The subscripts for the Einstein summation.
operands (List[Tensor]): The tensors to compute the Einstein summation of.
Examples::
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # trace
>>> torch.einsum('ii', torch.randn(4, 4))
tensor(-1.2104)
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # diagonal
>>> torch.einsum('ii->i', torch.randn(4, 4))
tensor([-0.1034, 0.7952, -0.2433, 0.4545])
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # outer product
>>> x = torch.randn(5)
>>> y = torch.randn(4)
>>> torch.einsum('i,j->ij', x, y)
tensor([[ 0.1156, -0.2897, -0.3918, 0.4963],
[-0.3744, 0.9381, 1.2685, -1.6070],
[ 0.7208, -1.8058, -2.4419, 3.0936],
[ 0.1713, -0.4291, -0.5802, 0.7350],
[ 0.5704, -1.4290, -1.9323, 2.4480]])
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # batch matrix multiplication
>>> As = torch.randn(3, 2, 5)
>>> Bs = torch.randn(3, 5, 4)
>>> torch.einsum('bij,bjk->bik', As, Bs)
tensor([[[-1.0564, -1.5904, 3.2023, 3.1271],
[-1.6706, -0.8097, -0.8025, -2.1183]],
[[ 4.2239, 0.3107, -0.5756, -0.2354],
[-1.4558, -0.3460, 1.5087, -0.8530]],
[[ 2.8153, 1.8787, -4.3839, -1.2112],
[ 0.3728, -2.1131, 0.0921, 0.8305]]])
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # with sublist format and ellipsis
>>> torch.einsum(As, [..., 0, 1], Bs, [..., 1, 2], [..., 0, 2])
tensor([[[-1.0564, -1.5904, 3.2023, 3.1271],
[-1.6706, -0.8097, -0.8025, -2.1183]],
[[ 4.2239, 0.3107, -0.5756, -0.2354],
[-1.4558, -0.3460, 1.5087, -0.8530]],
[[ 2.8153, 1.8787, -4.3839, -1.2112],
[ 0.3728, -2.1131, 0.0921, 0.8305]]])
>>> # batch permute
>>> A = torch.randn(2, 3, 4, 5)
>>> torch.einsum('...ij->...ji', A).shape
torch.Size([2, 3, 5, 4])
>>> # equivalent to torch.nn.functional.bilinear
>>> A = torch.randn(3, 5, 4)
>>> l = torch.randn(2, 5)
>>> r = torch.randn(2, 4)
>>> torch.einsum('bn,anm,bm->ba', l, A, r)
tensor([[-0.3430, -5.2405, 0.4494],
[ 0.3311, 5.5201, -3.0356]])
istft(...)
istft(input, n_fft, hop_length=None, win_length=None, window=None, center=True, normalized=False, onesided=None, length=None, return_complex=False) -> Tensor:
Inverse short time Fourier Transform. This is expected to be the inverse of :func:`~torch.stft`.
.. warning::
From version 2.1, a warning will be provided if a :attr:`window` is
not specified. In a future release, this attribute will be required.
Please provide the same window used in the stft call.
It has the same parameters (+ additional optional parameter of :attr:`length`) and it should return the
least squares estimation of the original signal. The algorithm will check using the NOLA condition (
nonzero overlap).
Important consideration in the parameters :attr:`window` and :attr:`center` so that the envelope
created by the summation of all the windows is never zero at certain point in time. Specifically,
:math:`\sum_{t=-\infty}^{\infty} |w|^2[n-t\times hop\_length] \cancel{=} 0`.
Since :func:`~torch.stft` discards elements at the end of the signal if they do not fit in a frame,
``istft`` may return a shorter signal than the original signal (can occur if :attr:`center` is False
since the signal isn't padded). If `length` is given in the arguments and is longer than expected,
``istft`` will pad zeros to the end of the returned signal.
If :attr:`center` is ``True``, then there will be padding e.g. ``'constant'``, ``'reflect'``, etc.
Left padding can be trimmed off exactly because they can be calculated but right padding cannot be
calculated without additional information.
Example: Suppose the last window is:
``[17, 18, 0, 0, 0]`` vs ``[18, 0, 0, 0, 0]``
The :attr:`n_fft`, :attr:`hop_length`, :attr:`win_length` are all the same which prevents the calculation
of right padding. These additional values could be zeros or a reflection of the signal so providing
:attr:`length` could be useful. If :attr:`length` is ``None`` then padding will be aggressively removed
(some loss of signal).
[1] D. W. Griffin and J. S. Lim, "Signal estimation from modified short-time Fourier transform,"
IEEE Trans. ASSP, vol.32, no.2, pp.236-243, Apr. 1984.
Args:
input (Tensor): The input tensor. Expected to be in the format of :func:`~torch.stft`,
output. That is a complex tensor of shape `(B?, N, T)` where
- `B?` is an optional batch dimension
- `N` is the number of frequency samples, `(n_fft // 2) + 1`
for onesided input, or otherwise `n_fft`.
- `T` is the number of frames, `1 + length // hop_length` for centered stft,
or `1 + (length - n_fft) // hop_length` otherwise.
.. versionchanged:: 2.0
Real datatype inputs are no longer supported. Input must now have a
complex datatype, as returned by ``stft(..., return_complex=True)``.
n_fft (int): Size of Fourier transform
hop_length (Optional[int]): The distance between neighboring sliding window frames.
(Default: ``n_fft // 4``)
win_length (Optional[int]): The size of window frame and STFT filter. (Default: ``n_fft``)
window (Optional[torch.Tensor]): The optional window function.
Shape must be 1d and `<= n_fft`
(Default: ``torch.ones(win_length)``)
center (bool): Whether :attr:`input` was padded on both sides so that the :math:`t`-th frame is
centered at time :math:`t \times \text{hop\_length}`.
(Default: ``True``)
normalized (bool): Whether the STFT was normalized. (Default: ``False``)
onesided (Optional[bool]): Whether the STFT was onesided.
(Default: ``True`` if `n_fft != fft_size` in the input size)
length (Optional[int]): The amount to trim the signal by (i.e. the
original signal length). Defaults to `(T - 1) * hop_length` for
centered stft, or `n_fft + (T - 1) * hop_length` otherwise, where `T`
is the number of input frames.
return_complex (Optional[bool]):
Whether the output should be complex, or if the input should be
assumed to derive from a real signal and window.
Note that this is incompatible with ``onesided=True``.
(Default: ``False``)
Returns:
Tensor: Least squares estimation of the original signal of shape `(B?, length)` where
`B?` is an optional batch dimension from the input tensor.
lu(*args, **kwargs)
Computes the LU factorization of a matrix or batches of matrices
:attr:`A`. Returns a tuple containing the LU factorization and
pivots of :attr:`A`. Pivoting is done if :attr:`pivot` is set to
``True``.
.. warning::
:func:`torch.lu` is deprecated in favor of :func:`torch.linalg.lu_factor`
and :func:`torch.linalg.lu_factor_ex`. :func:`torch.lu` will be removed in a
future PyTorch release.
``LU, pivots, info = torch.lu(A, compute_pivots)`` should be replaced with
.. code:: python
LU, pivots = torch.linalg.lu_factor(A, compute_pivots)
``LU, pivots, info = torch.lu(A, compute_pivots, get_infos=True)`` should be replaced with
.. code:: python
LU, pivots, info = torch.linalg.lu_factor_ex(A, compute_pivots)
.. note::
* The returned permutation matrix for every matrix in the batch is
represented by a 1-indexed vector of size ``min(A.shape[-2], A.shape[-1])``.
``pivots[i] == j`` represents that in the ``i``-th step of the algorithm,
the ``i``-th row was permuted with the ``j-1``-th row.
* LU factorization with :attr:`pivot` = ``False`` is not available
for CPU, and attempting to do so will throw an error. However,
LU factorization with :attr:`pivot` = ``False`` is available for
CUDA.
* This function does not check if the factorization was successful
or not if :attr:`get_infos` is ``True`` since the status of the
factorization is present in the third element of the return tuple.
* In the case of batches of square matrices with size less or equal
to 32 on a CUDA device, the LU factorization is repeated for
singular matrices due to the bug in the MAGMA library
(see magma issue 13).
* ``L``, ``U``, and ``P`` can be derived using :func:`torch.lu_unpack`.
.. warning::
The gradients of this function will only be finite when :attr:`A` is full rank.
This is because the LU decomposition is just differentiable at full rank matrices.
Furthermore, if :attr:`A` is close to not being full rank,
the gradient will be numerically unstable as it depends on the computation of :math:`L^{-1}` and :math:`U^{-1}`.
Args:
A (Tensor): the tensor to factor of size :math:`(*, m, n)`
pivot (bool, optional): Whether to compute the LU decomposition with partial pivoting, or the regular LU
decomposition. :attr:`pivot`\ `= False` not supported on CPU. Default: `True`.
get_infos (bool, optional): if set to ``True``, returns an info IntTensor.
Default: ``False``
out (tuple, optional): optional output tuple. If :attr:`get_infos` is ``True``,
then the elements in the tuple are Tensor, IntTensor,
and IntTensor. If :attr:`get_infos` is ``False``, then the
elements in the tuple are Tensor, IntTensor. Default: ``None``
Returns:
(Tensor, IntTensor, IntTensor (optional)): A tuple of tensors containing
- **factorization** (*Tensor*): the factorization of size :math:`(*, m, n)`
- **pivots** (*IntTensor*): the pivots of size :math:`(*, \text{min}(m, n))`.
``pivots`` stores all the intermediate transpositions of rows.
The final permutation ``perm`` could be reconstructed by
applying ``swap(perm[i], perm[pivots[i] - 1])`` for ``i = 0, ..., pivots.size(-1) - 1``,
where ``perm`` is initially the identity permutation of :math:`m` elements
(essentially this is what :func:`torch.lu_unpack` is doing).
- **infos** (*IntTensor*, *optional*): if :attr:`get_infos` is ``True``, this is a tensor of
size :math:`(*)` where non-zero values indicate whether factorization for the matrix or
each minibatch has succeeded or failed
Example::
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_LAPACK)
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> A = torch.randn(2, 3, 3)
>>> A_LU, pivots = torch.lu(A)
>>> A_LU
tensor([[[ 1.3506, 2.5558, -0.0816],
[ 0.1684, 1.1551, 0.1940],
[ 0.1193, 0.6189, -0.5497]],
[[ 0.4526, 1.2526, -0.3285],
[-0.7988, 0.7175, -0.9701],
[ 0.2634, -0.9255, -0.3459]]])
>>> pivots
tensor([[ 3, 3, 3],
[ 3, 3, 3]], dtype=torch.int32)
>>> A_LU, pivots, info = torch.lu(A, get_infos=True)
>>> if info.nonzero().size(0) == 0:
... print('LU factorization succeeded for all samples!')
LU factorization succeeded for all samples!
meshgrid(*tensors, indexing: str | None = None) -> tuple[torch.Tensor, ...]
Creates grids of coordinates specified by the 1D inputs in `attr`:tensors.
This is helpful when you want to visualize data over some
range of inputs. See below for a plotting example.
Given :math:`N` 1D tensors :math:`T_0 \ldots T_{N-1}` as
inputs with corresponding sizes :math:`S_0 \ldots S_{N-1}`,
this creates :math:`N` N-dimensional tensors :math:`G_0 \ldots
G_{N-1}`, each with shape :math:`(S_0, ..., S_{N-1})` where
the output :math:`G_i` is constructed by expanding :math:`T_i`
to the result shape.
.. note::
0D inputs are treated equivalently to 1D inputs of a
single element.
.. warning::
`torch.meshgrid(*tensors)` currently has the same behavior
as calling `numpy.meshgrid(*arrays, indexing='ij')`.
In the future `torch.meshgrid` will transition to
`indexing='xy'` as the default.
https://github.com/pytorch/pytorch/issues/50276 tracks
this issue with the goal of migrating to NumPy's behavior.
.. seealso::
:func:`torch.cartesian_prod` has the same effect but it
collects the data in a tensor of vectors.
Args:
tensors (list of Tensor): list of scalars or 1 dimensional tensors. Scalars will be
treated as tensors of size :math:`(1,)` automatically
indexing: (str, optional): the indexing mode, either "xy"
or "ij", defaults to "ij". See warning for future changes.
If "xy" is selected, the first dimension corresponds
to the cardinality of the second input and the second
dimension corresponds to the cardinality of the first
input.
If "ij" is selected, the dimensions are in the same
order as the cardinality of the inputs.
Returns:
seq (sequence of Tensors): If the input has :math:`N`
tensors of size :math:`S_0 \ldots S_{N-1}``, then the
output will also have :math:`N` tensors, where each tensor
is of shape :math:`(S_0, ..., S_{N-1})`.
Example::
>>> x = torch.tensor([1, 2, 3])
>>> y = torch.tensor([4, 5, 6])
Observe the element-wise pairings across the grid, (1, 4),
(1, 5), ..., (3, 6). This is the same thing as the
cartesian product.
>>> grid_x, grid_y = torch.meshgrid(x, y, indexing='ij')
>>> grid_x
tensor([[1, 1, 1],
[2, 2, 2],
[3, 3, 3]])
>>> grid_y
tensor([[4, 5, 6],
[4, 5, 6],
[4, 5, 6]])
This correspondence can be seen when these grids are
stacked properly.
>>> torch.equal(torch.cat(tuple(torch.dstack([grid_x, grid_y]))),
... torch.cartesian_prod(x, y))
True
`torch.meshgrid` is commonly used to produce a grid for
plotting.
>>> # xdoctest: +REQUIRES(module:matplotlib)
>>> # xdoctest: +REQUIRES(env:DOCTEST_SHOW)
>>> import matplotlib.pyplot as plt
>>> xs = torch.linspace(-5, 5, steps=100)
>>> ys = torch.linspace(-5, 5, steps=100)
>>> x, y = torch.meshgrid(xs, ys, indexing='xy')
>>> z = torch.sin(torch.sqrt(x * x + y * y))
>>> ax = plt.axes(projection='3d')
>>> ax.plot_surface(x.numpy(), y.numpy(), z.numpy())
>>> plt.show()
.. image:: ../_static/img/meshgrid.png
:width: 512
norm(input, p: float | str | None = 'fro', dim=None, keepdim=False, out=None, dtype=None)
Returns the matrix norm or vector norm of a given tensor.
.. warning::
torch.norm is deprecated and may be removed in a future PyTorch release.
Its documentation and behavior may be incorrect, and it is no longer
actively maintained.
Use :func:`torch.linalg.vector_norm` when computing vector norms and
:func:`torch.linalg.matrix_norm` when computing matrix norms.
For a function with a similar behavior as this one see :func:`torch.linalg.norm`.
Note, however, the signature for these functions is slightly different than the
signature for ``torch.norm``.
Args:
input (Tensor): The input tensor. Its data type must be either a floating
point or complex type. For complex inputs, the norm is calculated using the
absolute value of each element. If the input is complex and neither
:attr:`dtype` nor :attr:`out` is specified, the result's data type will
be the corresponding floating point type (e.g. float if :attr:`input` is
complexfloat).
p (int, float, inf, -inf, 'fro', 'nuc', optional): the order of norm. Default: ``'fro'``
The following norms can be calculated:
====== ============== ==========================
ord matrix norm vector norm
====== ============== ==========================
'fro' Frobenius norm --
'nuc' nuclear norm --
Number -- sum(abs(x)**ord)**(1./ord)
====== ============== ==========================
The vector norm can be calculated across any number of dimensions.
The corresponding dimensions of :attr:`input` are flattened into
one dimension, and the norm is calculated on the flattened
dimension.
Frobenius norm produces the same result as ``p=2`` in all cases
except when :attr:`dim` is a list of three or more dims, in which
case Frobenius norm throws an error.
Nuclear norm can only be calculated across exactly two dimensions.
dim (int, tuple of ints, list of ints, optional):
Specifies which dimension or dimensions of :attr:`input` to
calculate the norm across. If :attr:`dim` is ``None``, the norm will
be calculated across all dimensions of :attr:`input`. If the norm
type indicated by :attr:`p` does not support the specified number of
dimensions, an error will occur.
keepdim (bool, optional): whether the output tensors have :attr:`dim`
retained or not. Ignored if :attr:`dim` = ``None`` and
:attr:`out` = ``None``. Default: ``False``
out (Tensor, optional): the output tensor. Ignored if
:attr:`dim` = ``None`` and :attr:`out` = ``None``.
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. If specified, the input tensor is casted to
:attr:`dtype` while performing the operation. Default: None.
.. note::
Even though ``p='fro'`` supports any number of dimensions, the true
mathematical definition of Frobenius norm only applies to tensors with
exactly two dimensions. :func:`torch.linalg.matrix_norm` with ``ord='fro'``
aligns with the mathematical definition, since it can only be applied across
exactly two dimensions.
Example::
>>> import torch
>>> a = torch.arange(9, dtype= torch.float) - 4
>>> b = a.reshape((3, 3))
>>> torch.norm(a)
tensor(7.7460)
>>> torch.norm(b)
tensor(7.7460)
>>> torch.norm(a, float('inf'))
tensor(4.)
>>> torch.norm(b, float('inf'))
tensor(4.)
>>> c = torch.tensor([[ 1, 2, 3], [-1, 1, 4]] , dtype=torch.float)
>>> torch.norm(c, dim=0)
tensor([1.4142, 2.2361, 5.0000])
>>> torch.norm(c, dim=1)
tensor([3.7417, 4.2426])
>>> torch.norm(c, p=1, dim=1)
tensor([6., 6.])
>>> d = torch.arange(8, dtype=torch.float).reshape(2, 2, 2)
>>> torch.norm(d, dim=(1, 2))
tensor([ 3.7417, 11.2250])
>>> torch.norm(d[0, :, :]), torch.norm(d[1, :, :])
(tensor(3.7417), tensor(11.2250))
pca_lowrank(A: torch.Tensor, q: int | None = None, center: bool = True, niter: int = 2) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]
Performs linear Principal Component Analysis (PCA) on a low-rank
matrix, batches of such matrices, or sparse matrix.
This function returns a namedtuple ``(U, S, V)`` which is the
nearly optimal approximation of a singular value decomposition of
a centered matrix :math:`A` such that :math:`A \approx U \operatorname{diag}(S) V^{\text{H}}`
.. note:: The relation of ``(U, S, V)`` to PCA is as follows:
- :math:`A` is a data matrix with ``m`` samples and
``n`` features
- the :math:`V` columns represent the principal directions
- :math:`S ** 2 / (m - 1)` contains the eigenvalues of
:math:`A^T A / (m - 1)` which is the covariance of
``A`` when ``center=True`` is provided.
- ``matmul(A, V[:, :k])`` projects data to the first k
principal components
.. note:: Different from the standard SVD, the size of returned
matrices depend on the specified rank and q
values as follows:
- :math:`U` is m x q matrix
- :math:`S` is q-vector
- :math:`V` is n x q matrix
.. note:: To obtain repeatable results, reset the seed for the
pseudorandom number generator
Args:
A (Tensor): the input tensor of size :math:`(*, m, n)`
q (int, optional): a slightly overestimated rank of
:math:`A`. By default, ``q = min(6, m,
n)``.
center (bool, optional): if True, center the input tensor,
otherwise, assume that the input is
centered.
niter (int, optional): the number of subspace iterations to
conduct; niter must be a nonnegative
integer, and defaults to 2.
References::
- Nathan Halko, Per-Gunnar Martinsson, and Joel Tropp, Finding
structure with randomness: probabilistic algorithms for
constructing approximate matrix decompositions,
arXiv:0909.4061 [math.NA; math.PR], 2009 (available at
`arXiv <http://arxiv.org/abs/0909.4061>`_).
split(tensor: torch.Tensor, split_size_or_sections: int | list[int], dim: int = 0) -> tuple[torch.Tensor, ...]
Splits the tensor into chunks. Each chunk is a view of the original tensor.
If :attr:`split_size_or_sections` is an integer type, then :attr:`tensor` will
be split into equally sized chunks (if possible). Last chunk will be smaller if
the tensor size along the given dimension :attr:`dim` is not divisible by
:attr:`split_size`.
If :attr:`split_size_or_sections` is a list, then :attr:`tensor` will be split
into ``len(split_size_or_sections)`` chunks with sizes in :attr:`dim` according
to :attr:`split_size_or_sections`.
Args:
tensor (Tensor): tensor to split.
split_size_or_sections (int) or (list(int)): size of a single chunk or
list of sizes for each chunk
dim (int): dimension along which to split the tensor.
Example::
>>> a = torch.arange(10).reshape(5, 2)
>>> a
tensor([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
>>> torch.split(a, 2)
(tensor([[0, 1],
[2, 3]]),
tensor([[4, 5],
[6, 7]]),
tensor([[8, 9]]))
>>> torch.split(a, [1, 4])
(tensor([[0, 1]]),
tensor([[2, 3],
[4, 5],
[6, 7],
[8, 9]]))
stft(input: torch.Tensor, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: torch.Tensor | None = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) -> torch.Tensor
Short-time Fourier transform (STFT).
.. warning::
From version 1.8.0, :attr:`return_complex` must always be given
explicitly for real inputs and `return_complex=False` has been
deprecated. Strongly prefer `return_complex=True` as in a future
pytorch release, this function will only return complex tensors.
Note that :func:`torch.view_as_real` can be used to recover a real
tensor with an extra last dimension for real and imaginary components.
.. warning::
From version 2.1, a warning will be provided if a :attr:`window` is
not specified. In a future release, this attribute will be required.
Not providing a window currently defaults to using a rectangular window,
which may result in undesirable artifacts. Consider using tapered windows,
such as :func:`torch.hann_window`.
The STFT computes the Fourier transform of short overlapping windows of the
input. This giving frequency components of the signal as they change over
time. The interface of this function is modeled after (but *not* a drop-in
replacement for) librosa_ stft function.
.. _librosa: https://librosa.org/doc/latest/generated/librosa.stft.html
Ignoring the optional batch dimension, this method computes the following
expression:
.. math::
X[\omega, m] = \sum_{k = 0}^{\text{win\_length-1}}%
\text{window}[k]\ \text{input}[m \times \text{hop\_length} + k]\ %
\exp\left(- j \frac{2 \pi \cdot \omega k}{\text{n\_fft}}\right),
where :math:`m` is the index of the sliding window, and :math:`\omega` is
the frequency :math:`0 \leq \omega < \text{n\_fft}` for ``onesided=False``,
or :math:`0 \leq \omega < \lfloor \text{n\_fft} / 2 \rfloor + 1` for ``onesided=True``.
* :attr:`input` must be either a 1-D time sequence or a 2-D batch of time
sequences.
* If :attr:`hop_length` is ``None`` (default), it is treated as equal to
``floor(n_fft / 4)``.
* If :attr:`win_length` is ``None`` (default), it is treated as equal to
:attr:`n_fft`.
* :attr:`window` can be a 1-D tensor of size :attr:`win_length`, e.g., from
:meth:`torch.hann_window`. If :attr:`window` is ``None`` (default), it is
treated as if having :math:`1` everywhere in the window. If
:math:`\text{win\_length} < \text{n\_fft}`, :attr:`window` will be padded on
both sides to length :attr:`n_fft` before being applied.
* If :attr:`center` is ``True`` (default), :attr:`input` will be padded on
both sides so that the :math:`t`-th frame is centered at time
:math:`t \times \text{hop\_length}`. Otherwise, the :math:`t`-th frame
begins at time :math:`t \times \text{hop\_length}`.
* :attr:`pad_mode` determines the padding method used on :attr:`input` when
:attr:`center` is ``True``. See :meth:`torch.nn.functional.pad` for
all available options. Default is ``"reflect"``.
* If :attr:`onesided` is ``True`` (default for real input), only values for
:math:`\omega` in :math:`\left[0, 1, 2, \dots, \left\lfloor
\frac{\text{n\_fft}}{2} \right\rfloor + 1\right]` are returned because
the real-to-complex Fourier transform satisfies the conjugate symmetry,
i.e., :math:`X[m, \omega] = X[m, \text{n\_fft} - \omega]^*`.
Note if the input or window tensors are complex, then :attr:`onesided`
output is not possible.
* If :attr:`normalized` is ``True`` (default is ``False``), the function
returns the normalized STFT results, i.e., multiplied by :math:`(\text{frame\_length})^{-0.5}`.
* If :attr:`return_complex` is ``True`` (default if input is complex), the
return is a ``input.dim() + 1`` dimensional complex tensor. If ``False``,
the output is a ``input.dim() + 2`` dimensional real tensor where the last
dimension represents the real and imaginary components.
Returns either a complex tensor of size :math:`(* \times N \times T)` if
:attr:`return_complex` is true, or a real tensor of size :math:`(* \times N
\times T \times 2)`. Where :math:`*` is the optional batch size of
:attr:`input`, :math:`N` is the number of frequencies where STFT is applied
and :math:`T` is the total number of frames used.
.. warning::
This function changed signature at version 0.4.1. Calling with the
previous signature may cause error or return incorrect result.
Args:
input (Tensor): the input tensor of shape `(B?, L)` where `B?` is an optional
batch dimension
n_fft (int): size of Fourier transform
hop_length (int, optional): the distance between neighboring sliding window
frames. Default: ``None`` (treated as equal to ``floor(n_fft / 4)``)
win_length (int, optional): the size of window frame and STFT filter.
Default: ``None`` (treated as equal to :attr:`n_fft`)
window (Tensor, optional): the optional window function.
Shape must be 1d and `<= n_fft`
Default: ``None`` (treated as window of all :math:`1` s)
center (bool, optional): whether to pad :attr:`input` on both sides so
that the :math:`t`-th frame is centered at time :math:`t \times \text{hop\_length}`.
Default: ``True``
pad_mode (str, optional): controls the padding method used when
:attr:`center` is ``True``. Default: ``"reflect"``
normalized (bool, optional): controls whether to return the normalized STFT results
Default: ``False``
onesided (bool, optional): controls whether to return half of results to
avoid redundancy for real inputs.
Default: ``True`` for real :attr:`input` and :attr:`window`, ``False`` otherwise.
return_complex (bool, optional): whether to return a complex tensor, or
a real tensor with an extra last dimension for the real and
imaginary components.
.. versionchanged:: 2.0
``return_complex`` is now a required argument for real inputs,
as the default is being transitioned to ``True``.
.. deprecated:: 2.0
``return_complex=False`` is deprecated, instead use ``return_complex=True``
Note that calling :func:`torch.view_as_real` on the output will
recover the deprecated output format.
Returns:
Tensor: A tensor containing the STFT result with shape `(B?, N, T, C?)` where
- `B?` is an optional batch dimension from the input.
- `N` is the number of frequency samples, `(n_fft // 2) + 1` for
`onesided=True`, or otherwise `n_fft`.
- `T` is the number of frames, `1 + L // hop_length`
for `center=True`, or `1 + (L - n_fft) // hop_length` otherwise.
- `C?` is an optional length-2 dimension of real and imaginary
components, present when `return_complex=False`.
svd_lowrank(A: torch.Tensor, q: int | None = 6, niter: int | None = 2, M: torch.Tensor | None = None) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]
Return the singular value decomposition ``(U, S, V)`` of a matrix,
batches of matrices, or a sparse matrix :math:`A` such that
:math:`A \approx U \operatorname{diag}(S) V^{\text{H}}`. In case :math:`M` is given, then
SVD is computed for the matrix :math:`A - M`.
.. note:: The implementation is based on the Algorithm 5.1 from
Halko et al., 2009.
.. note:: For an adequate approximation of a k-rank matrix
:math:`A`, where k is not known in advance but could be
estimated, the number of :math:`Q` columns, q, can be
chosen according to the following criteria: in general,
:math:`k <= q <= min(2*k, m, n)`. For large low-rank
matrices, take :math:`q = k + 5..10`. If k is
relatively small compared to :math:`min(m, n)`, choosing
:math:`q = k + 0..2` may be sufficient.
.. note:: This is a randomized method. To obtain repeatable results,
set the seed for the pseudorandom number generator
.. note:: In general, use the full-rank SVD implementation
:func:`torch.linalg.svd` for dense matrices due to its 10x
higher performance characteristics. The low-rank SVD
will be useful for huge sparse matrices that
:func:`torch.linalg.svd` cannot handle.
Args::
A (Tensor): the input tensor of size :math:`(*, m, n)`
q (int, optional): a slightly overestimated rank of A.
niter (int, optional): the number of subspace iterations to
conduct; niter must be a nonnegative
integer, and defaults to 2
M (Tensor, optional): the input tensor's mean of size
:math:`(*, m, n)`, which will be broadcasted
to the size of A in this function.
References::
- Nathan Halko, Per-Gunnar Martinsson, and Joel Tropp, Finding
structure with randomness: probabilistic algorithms for
constructing approximate matrix decompositions,
arXiv:0909.4061 [math.NA; math.PR], 2009 (available at
`arXiv <https://arxiv.org/abs/0909.4061>`_).
tensordot(a, b, dims=2, out: torch.Tensor | None = None)
Returns a contraction of a and b over multiple dimensions.
:attr:`tensordot` implements a generalized matrix product.
Args:
a (Tensor): Left tensor to contract
b (Tensor): Right tensor to contract
dims (int or Tuple[List[int], List[int]] or List[List[int]] containing two lists or Tensor): number of dimensions to
contract or explicit lists of dimensions for :attr:`a` and
:attr:`b` respectively
When called with a non-negative integer argument :attr:`dims` = :math:`d`, and
the number of dimensions of :attr:`a` and :attr:`b` is :math:`m` and :math:`n`,
respectively, :func:`~torch.tensordot` computes the tensor :math:`r` of shape
``a.shape[:-dims] + b.shape[dims:]`` given by:
.. math::
r_{i_1,...,i_{m-d}, j_1,...,j_{n-d}}
= \sum_{k_1,...,k_d} a_{i_1,...,i_{m-d},k_1,...,k_d} \times b_{k_1,...,k_d, j_1,...,j_{n-d}}.
When called with :attr:`dims` of the list form, the given dimensions will be contracted
in place of the last :math:`d` of :attr:`a` and the first :math:`d` of :math:`b`. The sizes
in these dimensions must match, but :func:`~torch.tensordot` will deal with broadcasted
dimensions.
Examples::
>>> a = torch.arange(60.).reshape(3, 4, 5)
>>> b = torch.arange(24.).reshape(4, 3, 2)
>>> torch.tensordot(a, b, dims=([1, 0], [0, 1]))
tensor([[4400., 4730.],
[4532., 4874.],
[4664., 5018.],
[4796., 5162.],
[4928., 5306.]])
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
>>> a = torch.randn(3, 4, 5, device='cuda')
>>> b = torch.randn(4, 5, 6, device='cuda')
>>> c = torch.tensordot(a, b, dims=2).cpu()
tensor([[ 8.3504, -2.5436, 6.2922, 2.7556, -1.0732, 3.2741],
[ 3.3161, 0.0704, 5.0187, -0.4079, -4.3126, 4.8744],
[ 0.8223, 3.9445, 3.2168, -0.2400, 3.4117, 1.7780]])
>>> a = torch.randn(3, 5, 4, 6)
>>> b = torch.randn(6, 4, 5, 3)
>>> torch.tensordot(a, b, dims=([2, 1, 3], [1, 2, 0]))
tensor([[ 7.7193, -2.4867, -10.3204],
[ 1.5513, -14.4737, -6.5113],
[ -0.2850, 4.2573, -3.5997]])
unique(*args, **kwargs)
unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None) -> tuple[Tensor, Tensor, Tensor]
Returns the unique elements of the input tensor.
.. note:: This function is different from :func:`torch.unique_consecutive` in the sense that
this function also eliminates non-consecutive duplicate values.
.. note:: Currently in the CUDA implementation and the CPU implementation,
`torch.unique` always sort the tensor at the beginning regardless of the `sort` argument.
Sorting could be slow, so if your input tensor is already sorted, it is recommended to use
:func:`torch.unique_consecutive` which avoids the sorting.
Args:
input (Tensor): the input tensor
sorted (bool): Whether to sort the unique elements in ascending order
before returning as output.
return_inverse (bool): Whether to also return the indices for where
elements in the original input ended up in the returned unique list.
return_counts (bool): Whether to also return the counts for each unique
element.
dim (int, optional): the dimension to operate upon. If ``None``, the
unique of the flattened input is returned. Otherwise, each of the
tensors indexed by the given dimension is treated as one of the
elements to apply the unique operation upon. **Important:** when ``dim``
is specified, the operation finds unique sub-tensors (e.g., unique rows
or columns), not unique scalar values. This means individual values may
appear multiple times in the output if they exist in different sub-tensors.
See examples for more details. Default: ``None``
Returns:
(Tensor, Tensor (optional), Tensor (optional)): A tensor or a tuple of tensors containing
- **output** (*Tensor*): the output list of unique scalar elements if :attr:`dim`
is ``None``; otherwise, the unique sub-tensors along the specified dimension.
Note that when :attr:`dim` is specified, scalar values may repeat in the output.
- **inverse_indices** (*Tensor*): (optional) if
:attr:`return_inverse` is True, there will be an additional
returned tensor (same shape as input) representing the indices
for where elements in the original input map to in the output;
otherwise, this function will only return a single tensor.
- **counts** (*Tensor*): (optional) if
:attr:`return_counts` is True, there will be an additional
returned tensor (same shape as output or output.size(dim),
if dim was specified) representing the number of occurrences
for each unique value or tensor.
Example::
>>> output = torch.unique(torch.tensor([1, 3, 2, 3], dtype=torch.long))
>>> output
tensor([1, 2, 3])
>>> output, inverse_indices = torch.unique(
... torch.tensor([1, 3, 2, 3], dtype=torch.long), sorted=True, return_inverse=True)
>>> output
tensor([1, 2, 3])
>>> inverse_indices
tensor([0, 2, 1, 2])
>>> output, inverse_indices = torch.unique(
... torch.tensor([[1, 3], [2, 3]], dtype=torch.long), sorted=True, return_inverse=True)
>>> output
tensor([1, 2, 3])
>>> inverse_indices
tensor([[0, 2],
[1, 2]])
>>> # When using dim, the operation finds unique sub-tensors, not unique values.
>>> # Notice how values can repeat in the output:
>>> x = torch.tensor([[1, 3, 2, 3], [1, 2, 1, 2]], dtype=torch.long)
>>> torch.unique(x, dim=0) # unique rows
tensor([[1, 2, 1, 2],
[1, 3, 2, 3]])
>>> # Both rows are kept because they're different from each other,
>>> # even though values 1, 2, 3 appear multiple times in the output.
>>> torch.unique(x, dim=1) # unique columns
tensor([[1, 2, 3],
[1, 1, 2]])
>>> # The value 1 appears twice because we're comparing columns, not values.
>>> # Compare with flattened (no dim):
>>> torch.unique(x)
tensor([1, 2, 3])
>>> a = torch.tensor([
... [
... [1, 1, 0, 0],
... [1, 1, 0, 0],
... [0, 0, 1, 1],
... ],
... [
... [0, 0, 1, 1],
... [0, 0, 1, 1],
... [1, 1, 1, 1],
... ],
... [
... [1, 1, 0, 0],
... [1, 1, 0, 0],
... [0, 0, 1, 1],
... ],
... ])
>>> # If we call `torch.unique(a, dim=0)`, each of the tensors `a[idx, :, :]`
>>> # will be compared. We can see that `a[0, :, :]` and `a[2, :, :]` match
>>> # each other, so one of them will be removed.
>>> (a[0, :, :] == a[2, :, :]).all()
tensor(True)
>>> a_unique_dim0 = torch.unique(a, dim=0)
>>> a_unique_dim0
tensor([[[0, 0, 1, 1],
[0, 0, 1, 1],
[1, 1, 1, 1]],
[[1, 1, 0, 0],
[1, 1, 0, 0],
[0, 0, 1, 1]]])
>>> # Notice which sub-tensors from `a` match with the sub-tensors from
>>> # `a_unique_dim0`:
>>> (a_unique_dim0[0, :, :] == a[1, :, :]).all()
tensor(True)
>>> (a_unique_dim0[1, :, :] == a[0, :, :]).all()
tensor(True)
>>> # For `torch.unique(a, dim=1)`, each of the tensors `a[:, idx, :]` are
>>> # compared. `a[:, 0, :]` and `a[:, 1, :]` match each other, so one of
>>> # them will be removed.
>>> (a[:, 0, :] == a[:, 1, :]).all()
tensor(True)
>>> torch.unique(a, dim=1)
tensor([[[0, 0, 1, 1],
[1, 1, 0, 0]],
[[1, 1, 1, 1],
[0, 0, 1, 1]],
[[0, 0, 1, 1],
[1, 1, 0, 0]]])
>>> # For `torch.unique(a, dim=2)`, the tensors `a[:, :, idx]` are compared.
>>> # `a[:, :, 0]` and `a[:, :, 1]` match each other. Also, `a[:, :, 2]` and
>>> # `a[:, :, 3]` match each other as well. So in this case, two of the
>>> # sub-tensors will be removed.
>>> (a[:, :, 0] == a[:, :, 1]).all()
tensor(True)
>>> (a[:, :, 2] == a[:, :, 3]).all()
tensor(True)
>>> torch.unique(a, dim=2)
tensor([[[0, 1],
[0, 1],
[1, 0]],
[[1, 0],
[1, 0],
[1, 1]],
[[0, 1],
[0, 1],
[1, 0]]])
unique_consecutive(*args, **kwargs)
Eliminates all but the first element from every consecutive group of equivalent elements.
.. note:: This function is different from :func:`torch.unique` in the sense that this function
only eliminates consecutive duplicate values. This semantics is similar to `std::unique`
in C++.
Args:
input (Tensor): the input tensor
return_inverse (bool): Whether to also return the indices for where
elements in the original input ended up in the returned unique list.
return_counts (bool): Whether to also return the counts for each unique
element.
dim (int): the dimension to apply unique. If ``None``, the unique of the
flattened input is returned. default: ``None``
Returns:
(Tensor, Tensor (optional), Tensor (optional)): A tensor or a tuple of tensors containing
- **output** (*Tensor*): the output list of unique scalar elements.
- **inverse_indices** (*Tensor*): (optional) if
:attr:`return_inverse` is True, there will be an additional
returned tensor (same shape as input) representing the indices
for where elements in the original input map to in the output;
otherwise, this function will only return a single tensor.
- **counts** (*Tensor*): (optional) if
:attr:`return_counts` is True, there will be an additional
returned tensor (same shape as output or output.size(dim),
if dim was specified) representing the number of occurrences
for each unique value or tensor.
Example::
>>> x = torch.tensor([1, 1, 2, 2, 3, 1, 1, 2])
>>> output = torch.unique_consecutive(x)
>>> output
tensor([1, 2, 3, 1, 2])
>>> output, inverse_indices = torch.unique_consecutive(x, return_inverse=True)
>>> output
tensor([1, 2, 3, 1, 2])
>>> inverse_indices
tensor([0, 0, 1, 1, 2, 3, 3, 4])
>>> output, counts = torch.unique_consecutive(x, return_counts=True)
>>> output
tensor([1, 2, 3, 1, 2])
>>> counts
tensor([2, 2, 1, 2, 1])
unravel_index(indices: torch.Tensor, shape: int | collections.abc.Sequence[int] | torch.Size) -> tuple[torch.Tensor, ...]
Converts a tensor of flat indices into a tuple of coordinate tensors that
index into an arbitrary tensor of the specified shape.
Args:
indices (Tensor): An integer tensor containing indices into the
flattened version of an arbitrary tensor of shape :attr:`shape`.
All elements must be in the range ``[0, prod(shape) - 1]``.
shape (int, sequence of ints, or torch.Size): The shape of the arbitrary
tensor. All elements must be non-negative.
Returns:
tuple of Tensors: Each ``i``-th tensor in the output corresponds with
dimension ``i`` of :attr:`shape`. Each tensor has the same shape as
``indices`` and contains one index into dimension ``i`` for each of the
flat indices given by ``indices``.
Example::
>>> import torch
>>> torch.unravel_index(torch.tensor(4), (3, 2))
(tensor(2),
tensor(0))
>>> torch.unravel_index(torch.tensor([4, 1]), (3, 2))
(tensor([2, 0]),
tensor([0, 1]))
>>> torch.unravel_index(torch.tensor([0, 1, 2, 3, 4, 5]), (3, 2))
(tensor([0, 0, 1, 1, 2, 2]),
tensor([0, 1, 0, 1, 0, 1]))
>>> torch.unravel_index(torch.tensor([1234, 5678]), (10, 10, 10, 10))
(tensor([1, 5]),
tensor([2, 6]),
tensor([3, 7]),
tensor([4, 8]))
>>> torch.unravel_index(torch.tensor([[1234], [5678]]), (10, 10, 10, 10))
(tensor([[1], [5]]),
tensor([[2], [6]]),
tensor([[3], [7]]),
tensor([[4], [8]]))
>>> torch.unravel_index(torch.tensor([[1234], [5678]]), (100, 100))
(tensor([[12], [56]]),
tensor([[34], [78]]))
DATA
__all__ = ['atleast_1d', 'atleast_2d', 'atleast_3d', 'broadcast_shapes...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\functional.py
torch.functools
Python Library Documentation: module functools
NAME
functools - functools.py - Tools for working with functions and callable objects
MODULE REFERENCE
https://docs.python.org/3.12/library/functools.html
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
CLASSES
builtins.object
cached_property
partial
partialmethod
singledispatchmethod
class cached_property(builtins.object)
| cached_property(func)
|
| Methods defined here:
|
| __get__(self, instance, owner=None)
|
| __init__(self, func)
| Initialize self. See help(type(self)) for accurate signature.
|
| __set_name__(self, owner, name)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class partial(builtins.object)
| partial(func, *args, **keywords) - new function with partial application
| of the given arguments and keywords.
|
| Methods defined here:
|
| __call__(self, /, *args, **kwargs)
| Call self as a function.
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __setstate__(...)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__(...)
| See PEP 585
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
|
| __vectorcalloffset__
|
| args
| tuple of arguments to future partial calls
|
| func
| function object to use in future partial calls
|
| keywords
| dictionary of keyword arguments to future partial calls
class partialmethod(builtins.object)
| partialmethod(func, /, *args, **keywords)
|
| Method descriptor with partial application of the given arguments
| and keywords.
|
| Supports wrapping existing descriptors and handles non-descriptor
| callables as instance methods.
|
| Methods defined here:
|
| __get__(self, obj, cls=None)
|
| __init__(self, func, /, *args, **keywords)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__ = GenericAlias(...)
| Represent a PEP 585 generic type
|
| E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __isabstractmethod__
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class singledispatchmethod(builtins.object)
| singledispatchmethod(func)
|
| Single-dispatch generic method descriptor.
|
| Supports wrapping existing descriptors and handles non-descriptor
| callables as instance methods.
|
| Methods defined here:
|
| __get__(self, obj, cls=None)
|
| __init__(self, func)
| Initialize self. See help(type(self)) for accurate signature.
|
| register(self, cls, method=None)
| generic_method.register(cls, func) -> func
|
| Registers a new implementation for the given *cls* on a *generic_method*.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __isabstractmethod__
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
cache(user_function, /)
Simple lightweight unbounded cache. Sometimes called "memoize".
cmp_to_key(mycmp)
Convert a cmp= function into a key= function.
mycmp
Function that compares two objects.
lru_cache(maxsize=128, typed=False)
Least-recently-used cache decorator.
If *maxsize* is set to None, the LRU features are disabled and the cache
can grow without bound.
If *typed* is True, arguments of different types will be cached separately.
For example, f(3.0) and f(3) will be treated as distinct calls with
distinct results.
Arguments to the cached function must be hashable.
View the cache statistics named tuple (hits, misses, maxsize, currsize)
with f.cache_info(). Clear the cache and statistics with f.cache_clear().
Access the underlying function with f.__wrapped__.
See: https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)
reduce(...)
reduce(function, iterable[, initial]) -> value
Apply a function of two arguments cumulatively to the items of a sequence
or iterable, from left to right, so as to reduce the iterable to a single
value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
((((1+2)+3)+4)+5). If initial is present, it is placed before the items
of the iterable in the calculation, and serves as a default when the
iterable is empty.
singledispatch(func)
Single-dispatch generic function decorator.
Transforms a function into a generic function, which can have different
behaviours depending upon the type of its first argument. The decorated
function acts as the default implementation, and additional
implementations can be registered using the register() attribute of the
generic function.
total_ordering(cls)
Class decorator that fills in missing ordering methods
update_wrapper(wrapper, wrapped, assigned=('__module__', '__name__', '__qualname__', '__doc__', '__annotations__', '__type_params__'), updated=('__dict__',))
Update a wrapper function to look like the wrapped function
wrapper is the function to be updated
wrapped is the original function
assigned is a tuple naming the attributes assigned directly
from the wrapped function to the wrapper function (defaults to
functools.WRAPPER_ASSIGNMENTS)
updated is a tuple naming the attributes of the wrapper that
are updated with the corresponding attribute from the wrapped
function (defaults to functools.WRAPPER_UPDATES)
wraps(wrapped, assigned=('__module__', '__name__', '__qualname__', '__doc__', '__annotations__', '__type_params__'), updated=('__dict__',))
Decorator factory to apply update_wrapper() to a wrapper function
Returns a decorator that invokes update_wrapper() with the decorated
function as the wrapper argument and the arguments to wraps() as the
remaining arguments. Default arguments are as for update_wrapper().
This is a convenience function to simplify applying partial() to
update_wrapper().
DATA
WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__qualname__', '__do...
WRAPPER_UPDATES = ('__dict__',)
__all__ = ['update_wrapper', 'wraps', 'WRAPPER_ASSIGNMENTS', 'WRAPPER_...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\functools.py
torch.fused_moving_avg_obs_fake_quant
Python Library Documentation: built-in function fused_moving_avg_obs_fake_quant in module torch fused_moving_avg_obs_fake_quant(...)
torch.futures
Python Library Documentation: package torch.futures in torch
NAME
torch.futures
DESCRIPTION
# mypy: allow-untyped-defs
# pylint: disable=useless-parent-delegation
PACKAGE CONTENTS
CLASSES
torch.Future(pybind11_builtins.pybind11_object)
torch.jit.Future(torch.Future, typing.Generic)
typing.Generic(builtins.object)
torch.jit.Future(torch.Future, typing.Generic)
class Future(torch.Future, typing.Generic)
| Future(*, devices: 'list[int | str | torch.device] | None' = None)
|
| Wrapper around a ``torch._C.Future`` which encapsulates an asynchronous
| execution of a callable, e.g. :meth:`~torch.distributed.rpc.rpc_async`. It
| also exposes a set of APIs to add callback functions and set results.
|
| .. warning:: GPU support is a beta feature, subject to changes.
|
| Method resolution order:
| Future
| torch.Future
| pybind11_builtins.pybind11_object
| typing.Generic
| builtins.object
|
| Methods defined here:
|
| __init__(self, *, devices: 'list[int | str | torch.device] | None' = None) from Future
| Create an empty unset ``Future``. If the future is intended to hold
| values containing CUDA tensors, (a superset of) their CUDA devices must
| be specified at construction. (This is only supported if
| ``torch.cuda.is_available()`` returns ``True``). This is needed to
| ensure proper CUDA stream synchronization. The child futures, returned
| by the ``then`` method, will inherit these devices.
|
| Args:
| devices(``List[Union[int, str, torch.device]]``, optional): the set
| of devices on which tensors contained in this future's value are
| allowed to reside and on which callbacks are allowed to operate.
|
| add_done_callback(self, callback: 'Callable[[Future[T]], None]') -> 'None' from Future
| Append the given callback function to this ``Future``, which will be run
| when the ``Future`` is completed. Multiple callbacks can be added to
| the same ``Future``, but the order in which they will be executed cannot
| be guaranteed. The callback must take one argument, which is the
| reference to this ``Future``. The callback function can use the
| :meth:`value` method to get the value. Note that if this ``Future`` is
| already completed, the given callback will be run inline.
|
| We recommend that you use the :meth:`then` method as it provides a way
| to synchronize after your callback has completed. ``add_done_callback``
| can be cheaper if your callback does not return anything. But both
| :meth:`then` and ``add_done_callback`` use the same callback
| registration API under the hood.
|
| With respect to GPU tensors, this method behaves in the same way as
| :meth:`then`.
|
| Args:
| callback(``Future``): a ``Callable`` that takes in one argument,
| which is the reference to this ``Future``.
|
| .. note:: Note that if the callback function throws, either
| through the original future being completed with an exception and
| calling ``fut.wait()``, or through other code in the callback,
| error handling must be carefully taken care of. For example, if
| this callback later completes additional futures, those futures are
| not marked as completed with an error and the user is responsible
| for handling completion/waiting on those futures independently.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_FUTURES)
| >>> def callback(fut):
| ... print("This will run after the future has finished.")
| ... print(fut.wait())
| >>> fut = torch.futures.Future()
| >>> fut.add_done_callback(callback)
| >>> fut.set_result(5)
| This will run after the future has finished.
| 5
|
| done(self) -> 'bool' from Future
| Return ``True`` if this ``Future`` is done. A ``Future`` is done if it
| has a result or an exception.
|
| If the value contains tensors that reside on GPUs, ``Future.done()``
| will return ``True`` even if the asynchronous kernels that are
| populating those tensors haven't yet completed running on the device,
| because at such stage the result is already usable, provided one
| performs the appropriate synchronizations (see :meth:`wait`).
|
| set_exception(self, result: 'T') -> 'None' from Future
| Set an exception for this ``Future``, which will mark this ``Future`` as
| completed with an error and trigger all attached callbacks. Note that
| when calling wait()/value() on this ``Future``, the exception set here
| will be raised inline.
|
| Args:
| result (BaseException): the exception for this ``Future``.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_FUTURES)
| >>> fut = torch.futures.Future()
| >>> fut.set_exception(ValueError("foo"))
| >>> fut.wait()
| Traceback (most recent call last):
| ...
| ValueError: foo
|
| set_result(self, result: 'T') -> 'None' from Future
| Set the result for this ``Future``, which will mark this ``Future`` as
| completed and trigger all attached callbacks. Note that a ``Future``
| cannot be marked completed twice.
|
| If the result contains tensors that reside on GPUs, this method can be
| called even if the asynchronous kernels that are populating those
| tensors haven't yet completed running on the device, provided that the
| streams on which those kernels were enqueued are set as the current ones
| when this method is called. Put simply, it's safe to call this method
| immediately after launching those kernels, without any additional
| synchronization, as long as one doesn't change streams in between. This
| method will record events on all the relevant current streams and will
| use them to ensure proper scheduling for all the consumers of this
| ``Future``.
|
| Args:
| result (object): the result object of this ``Future``.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_FUTURES)
| >>> import threading
| >>> import time
| >>> def slow_set_future(fut, value):
| ... time.sleep(0.5)
| ... fut.set_result(value)
| >>> fut = torch.futures.Future()
| >>> t = threading.Thread(
| ... target=slow_set_future,
| ... args=(fut, torch.ones(2) * 3)
| ... )
| >>> t.start()
| >>> print(fut.wait())
| tensor([3., 3.])
| >>> t.join()
|
| then(self, callback: 'Callable[[Future[T]], S]') -> 'Future[S]' from Future
| Append the given callback function to this ``Future``, which will be run
| when the ``Future`` is completed. Multiple callbacks can be added to
| the same ``Future``, but the order in which they will be executed cannot
| be guaranteed (to enforce a certain order consider chaining:
| ``fut.then(cb1).then(cb2)``). The callback must take one argument, which
| is the reference to this ``Future``. The callback function can use the
| :meth:`value` method to get the value. Note that if this ``Future`` is
| already completed, the given callback will be run immediately inline.
|
| If the ``Future``'s value contains tensors that reside on GPUs, the
| callback might be invoked while the async kernels that are populating
| those tensors haven't yet finished executing on the device. However, the
| callback will be invoked with some dedicated streams set as current
| (fetched from a global pool) which will be synchronized with those
| kernels. Hence any operation performed by the callback on these tensors
| will be scheduled on the device after the kernels complete. In other
| words, as long as the callback doesn't switch streams, it can safely
| manipulate the result without any additional synchronization. This is
| similar to the non-blocking behavior of :meth:`wait`.
|
| Similarly, if the callback returns a value that contains tensors that
| reside on a GPU, it can do so even if the kernels that are producing
| these tensors are still running on the device, as long as the callback
| didn't change streams during its execution. If one wants to change
| streams, one must be careful to re-synchronize them with the original
| streams, that is, those that were current when the callback was invoked.
|
| Args:
| callback(``Callable``): a ``Callable`` that takes this ``Future`` as
| the only argument.
|
| Returns:
| A new ``Future`` object that holds the return value of the
| ``callback`` and will be marked as completed when the given
| ``callback`` finishes.
|
| .. note:: Note that if the callback function throws, either
| through the original future being completed with an exception and
| calling ``fut.wait()``, or through other code in the callback, the
| future returned by ``then`` will be marked appropriately with the
| encountered error. However, if this callback later completes
| additional futures, those futures are not marked as completed with
| an error and the user is responsible for handling completion/waiting
| on those futures independently.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_FUTURES)
| >>> def callback(fut):
| ... print(f"RPC return value is {fut.wait()}.")
| >>> fut = torch.futures.Future()
| >>> # The inserted callback will print the return value when
| >>> # receiving the response from "worker1"
| >>> cb_fut = fut.then(callback)
| >>> chain_cb_fut = cb_fut.then(
| ... lambda x : print(f"Chained cb done. {x.wait()}")
| ... )
| >>> fut.set_result(5)
| RPC return value is 5.
| Chained cb done. None
|
| value(self) -> 'T' from Future
| Obtain the value of an already-completed future.
|
| This method should only be called after a call to :meth:`wait` has
| completed, or inside a callback function passed to :meth:`then`. In
| other cases this ``Future`` may not yet hold a value and calling
| ``value()`` could fail.
|
| If the value contains tensors that reside on GPUs, then this method will
| *not* perform any additional synchronization. This should be done
| beforehand, separately, through a call to :meth:`wait` (except within
| callbacks, for which it's already being taken care of by :meth:`then`).
|
| Returns:
| The value held by this ``Future``. If the function (callback or RPC)
| creating the value has thrown an error, this ``value()`` method will
| also throw an error.
|
| wait(self) -> 'T' from Future
| Block until the value of this ``Future`` is ready.
|
| If the value contains tensors that reside on GPUs, then an additional
| synchronization is performed with the kernels (executing on the device)
| which may be asynchronously populating those tensors. Such sync is
| non-blocking, which means that ``wait()`` will insert the necessary
| instructions in the current streams to ensure that further operations
| enqueued on those streams will be properly scheduled after the async
| kernels but, once that is done, ``wait()`` will return, even if those
| kernels are still running. No further synchronization is required when
| accessing and using the values, as long as one doesn't change streams.
|
| Returns:
| The value held by this ``Future``. If the function (callback or RPC)
| creating the value has thrown an error, this ``wait`` method will
| also throw an error.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __orig_bases__ = (<class 'torch.Future'>, typing.Generic[~T])
|
| __parameters__ = (~T,)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.Future:
|
| __getstate__(...)
| __getstate__(self: torch._C.Future, /) -> tuple
|
| __setstate__(...)
| __setstate__(self: torch._C.Future, arg0: tuple) -> None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Class methods inherited from typing.Generic:
|
| __class_getitem__(...)
| Parameterizes a generic class.
|
| At least, parameterizing a generic class is the *main* thing this
| method does. For example, for some generic class `Foo`, this is called
| when we do `Foo[int]` - there, with `cls=Foo` and `params=int`.
|
| However, note that this method is also called when defining generic
| classes in the first place with `class Foo[T]: ...`.
|
| __init_subclass__(...)
| Function to initialize subclasses.
FUNCTIONS
collect_all(futures: 'list[Future]') -> 'Future[list[Future]]'
Collects the provided :class:`~torch.futures.Future` objects into a single
combined :class:`~torch.futures.Future` that is completed when all of the
sub-futures are completed.
Args:
futures (list): a list of :class:`~torch.futures.Future` objects.
Returns:
Returns a :class:`~torch.futures.Future` object to a list of the passed
in Futures.
Example::
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_FUTURES)
>>> fut0 = torch.futures.Future()
>>> fut1 = torch.futures.Future()
>>> fut = torch.futures.collect_all([fut0, fut1])
>>> fut0.set_result(0)
>>> fut1.set_result(1)
>>> fut_list = fut.wait()
>>> print(f"fut0 result = {fut_list[0].wait()}")
fut0 result = 0
>>> print(f"fut1 result = {fut_list[1].wait()}")
fut1 result = 1
wait_all(futures: 'list[Future]') -> 'list'
Waits for all provided futures to be complete, and returns
the list of completed values. If any of the futures encounters an error,
the method will exit early and report the error not waiting for other
futures to complete.
Args:
futures (list): a list of :class:`~torch.futures.Future` object.
Returns:
A list of the completed :class:`~torch.futures.Future` results. This
method will throw an error if ``wait`` on any
:class:`~torch.futures.Future` throws.
DATA
__all__ = ['Future', 'collect_all', 'wait_all']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\futures\__init__.py
torch.fx
Python Library Documentation: package torch.fx in torch
NAME
torch.fx
DESCRIPTION
FX is a toolkit for developers to use to transform ``nn.Module``
instances. FX consists of three main components: a **symbolic tracer,**
an **intermediate representation**, and **Python code generation**. A
demonstration of these components in action:
::
import torch
# Simple module for demonstration
class MyModule(torch.nn.Module):
def __init__(self) -> None:
super().__init__()
self.param = torch.nn.Parameter(torch.rand(3, 4))
self.linear = torch.nn.Linear(4, 5)
def forward(self, x):
return self.linear(x + self.param).clamp(min=0.0, max=1.0)
module = MyModule()
from torch.fx import symbolic_trace
# Symbolic tracing frontend - captures the semantics of the module
symbolic_traced: torch.fx.GraphModule = symbolic_trace(module)
# High-level intermediate representation (IR) - Graph representation
print(symbolic_traced.graph)
"""
graph():
%x : [num_users=1] = placeholder[target=x]
%param : [num_users=1] = get_attr[target=param]
%add : [num_users=1] = call_function[target=operator.add](args = (%x, %param), kwargs = {})
%linear : [num_users=1] = call_module[target=linear](args = (%add,), kwargs = {})
%clamp : [num_users=1] = call_method[target=clamp](args = (%linear,), kwargs = {min: 0.0, max: 1.0})
return clamp
"""
# Code generation - valid Python code
print(symbolic_traced.code)
"""
def forward(self, x):
param = self.param
add = x + param; x = param = None
linear = self.linear(add); add = None
clamp = linear.clamp(min = 0.0, max = 1.0); linear = None
return clamp
"""
The **symbolic tracer** performs "symbolic execution" of the Python
code. It feeds fake values, called Proxies, through the code. Operations
on these Proxies are recorded. More information about symbolic tracing
can be found in the :func:`symbolic_trace` and :class:`Tracer`
documentation.
The **intermediate representation** is the container for the operations
that were recorded during symbolic tracing. It consists of a list of
Nodes that represent function inputs, callsites (to functions, methods,
or :class:`torch.nn.Module` instances), and return values. More information
about the IR can be found in the documentation for :class:`Graph`. The
IR is the format on which transformations are applied.
**Python code generation** is what makes FX a Python-to-Python (or
Module-to-Module) transformation toolkit. For each Graph IR, we can
create valid Python code matching the Graph's semantics. This
functionality is wrapped up in :class:`GraphModule`, which is a
:class:`torch.nn.Module` instance that holds a :class:`Graph` as well as a
``forward`` method generated from the Graph.
Taken together, this pipeline of components (symbolic tracing ->
intermediate representation -> transforms -> Python code generation)
constitutes the Python-to-Python transformation pipeline of FX. In
addition, these components can be used separately. For example,
symbolic tracing can be used in isolation to capture a form of
the code for analysis (and not transformation) purposes. Code
generation can be used for programmatically generating models, for
example from a config file. There are many uses for FX!
Several example transformations can be found at the
`examples <https://github.com/pytorch/examples/tree/master/fx>`__
repository.
PACKAGE CONTENTS
_compatibility
_graph_pickler
_lazy_graph_module
_pytree
_symbolic_trace
_utils
annotate
config
experimental (package)
graph
graph_module
immutable_collections
interpreter
node
operator_schemas
passes (package)
proxy
subgraph_rewriter
tensor_type
traceback
CLASSES
builtins.object
torch.fx.graph.Graph
torch.fx.interpreter.Interpreter
torch.fx.interpreter.Transformer
torch.fx.proxy.Proxy
torch._C._NodeBase(builtins.object)
torch.fx.node.Node
torch.fx.proxy.TracerBase(builtins.object)
torch.fx._symbolic_trace.Tracer
torch.nn.modules.module.Module(builtins.object)
torch.fx.graph_module.GraphModule
class Graph(builtins.object)
| Graph(owning_module: 'GraphModule | None' = None, tracer_cls: 'type[Tracer] | None' = None, tracer_extras: 'dict[str, Any] | None' = None) -> 'None'
|
| ``Graph`` is the main data structure used in the FX Intermediate Representation.
| It consists of a series of ``Node`` s, each representing callsites (or other
| syntactic constructs). The list of ``Node`` s, taken together, constitute a
| valid Python function.
|
| For example, the following code
|
| .. code-block:: python
|
| import torch
| import torch.fx
|
|
| class MyModule(torch.nn.Module):
| def __init__(self):
| super().__init__()
| self.param = torch.nn.Parameter(torch.rand(3, 4))
| self.linear = torch.nn.Linear(4, 5)
|
| def forward(self, x):
| return torch.topk(
| torch.sum(self.linear(x + self.linear.weight).relu(), dim=-1), 3
| )
|
|
| m = MyModule()
| gm = torch.fx.symbolic_trace(m)
|
| Will produce the following Graph::
|
| print(gm.graph)
|
| .. code-block:: text
|
| graph(x):
| %linear_weight : [num_users=1] = self.linear.weight
| %add_1 : [num_users=1] = call_function[target=operator.add](args = (%x, %linear_weight), kwargs = {})
| %linear_1 : [num_users=1] = call_module[target=linear](args = (%add_1,), kwargs = {})
| %relu_1 : [num_users=1] = call_method[target=relu](args = (%linear_1,), kwargs = {})
| %sum_1 : [num_users=1] = call_function[target=torch.sum](args = (%relu_1,), kwargs = {dim: -1})
| %topk_1 : [num_users=1] = call_function[target=torch.topk](args = (%sum_1, 3), kwargs = {})
| return topk_1
|
| For the semantics of operations represented in the ``Graph``, please see :class:`Node`.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| Methods defined here:
|
| __deepcopy__(self, memo: 'dict[int, Any] | None' = None) -> 'Graph'
| Explicitly implement __deepcopy__ to prevent excessive recursion depth
| from the default implementation. This uses graph_copy to copy the nodes
| in an iterative way, rather than recursive. It also populates the
| memoization table to prevent unnecessary copies (e.g. references to
| nodes or other parts of the Graph from a custom GraphModule implementation.
|
| __init__(self, owning_module: 'GraphModule | None' = None, tracer_cls: 'type[Tracer] | None' = None, tracer_extras: 'dict[str, Any] | None' = None) -> 'None'
| Construct an empty Graph.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| __str__(self) -> 'str'
| Return a human-readable (not machine-readable) string representation
| of this Graph
|
| call_function(self, the_function: 'Callable[..., Any]', args: 'tuple[Argument, ...] | None' = None, kwargs: 'dict[str, Argument] | None' = None, type_expr: 'Any | None' = None, name: 'str | None' = None) -> 'Node'
| Insert a ``call_function`` ``Node`` into the ``Graph``. A ``call_function`` node
| represents a call to a Python callable, specified by ``the_function``.
|
| Args:
|
| the_function (Callable[..., Any]): The function to be called. Can be any PyTorch
| operator, Python function, or member of the ``builtins`` or ``operator``
| namespaces.
|
| args (Optional[Tuple[Argument, ...]]): The positional arguments to be passed
| to the called function.
|
| kwargs (Optional[Dict[str, Argument]]): The keyword arguments to be passed
| to the called function
|
| type_expr (Optional[Any]): an optional type annotation representing the
| Python type the output of this node will have.
|
| name (Optional[str]): The name of the node. If not specified, set to None
|
| Returns:
|
| The newly created and inserted ``call_function`` node.
|
| .. note::
| The same insertion point and type expression rules apply for this method
| as :meth:`Graph.create_node`.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| call_method(self, method_name: 'str', args: 'tuple[Argument, ...] | None' = None, kwargs: 'dict[str, Argument] | None' = None, type_expr: 'Any | None' = None) -> 'Node'
| Insert a ``call_method`` ``Node`` into the ``Graph``. A ``call_method`` node
| represents a call to a given method on the 0th element of ``args``.
|
| Args:
|
| method_name (str): The name of the method to apply to the self argument.
| For example, if args[0] is a ``Node`` representing a ``Tensor``,
| then to call ``relu()`` on that ``Tensor``, pass ``relu`` to ``method_name``.
|
| args (Optional[Tuple[Argument, ...]]): The positional arguments to be passed
| to the called method. Note that this *should* include a ``self`` argument.
|
| kwargs (Optional[Dict[str, Argument]]): The keyword arguments to be passed
| to the called method
|
| type_expr (Optional[Any]): an optional type annotation representing the
| Python type the output of this node will have.
|
| Returns:
|
| The newly created and inserted ``call_method`` node.
|
| .. note::
| The same insertion point and type expression rules apply for this method
| as :meth:`Graph.create_node`.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| call_module(self, module_name: 'str', args: 'tuple[Argument, ...] | None' = None, kwargs: 'dict[str, Argument] | None' = None, type_expr: 'Any | None' = None) -> 'Node'
| Insert a ``call_module`` ``Node`` into the ``Graph``. A ``call_module`` node
| represents a call to the forward() function of a ``Module`` in the ``Module``
| hierarchy.
|
| Args:
|
| module_name (str): The qualified name of the ``Module`` in the ``Module``
| hierarchy to be called. For example, if the traced ``Module`` has a
| submodule named ``foo``, which has a submodule named ``bar``, the
| qualified name ``foo.bar`` should be passed as ``module_name`` to
| call that module.
|
| args (Optional[Tuple[Argument, ...]]): The positional arguments to be passed
| to the called method. Note that this should *not* include a ``self`` argument.
|
| kwargs (Optional[Dict[str, Argument]]): The keyword arguments to be passed
| to the called method
|
| type_expr (Optional[Any]): an optional type annotation representing the
| Python type the output of this node will have.
|
| Returns:
|
| The newly-created and inserted ``call_module`` node.
|
| .. note::
| The same insertion point and type expression rules apply for this method
| as :meth:`Graph.create_node`.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| create_node(self, op: 'str', target: 'Target', args: 'tuple[Argument, ...] | None' = None, kwargs: 'dict[str, Argument] | None' = None, name: 'str | None' = None, type_expr: 'Any | None' = None) -> 'Node'
| Create a ``Node`` and add it to the ``Graph`` at the current insert-point.
| Note that the current insert-point can be set via :meth:`Graph.inserting_before`
| and :meth:`Graph.inserting_after`.
|
| Args:
| op (str): the opcode for this Node. One of 'call_function', 'call_method', 'get_attr',
| 'call_module', 'placeholder', or 'output'. The semantics of these opcodes are
| described in the ``Graph`` docstring.
|
| args (Optional[Tuple[Argument, ...]]): is a tuple of arguments to this node.
|
| kwargs (Optional[Dict[str, Argument]]): the kwargs of this Node
|
| name (Optional[str]): an optional string name for the ``Node``.
| This will influence the name of the value assigned to in the
| Python generated code.
|
| type_expr (Optional[Any]): an optional type annotation representing the
| Python type the output of this node will have.
|
| Returns:
|
| The newly-created and inserted node.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| create_size_node(self, tensor_node: 'Node', dim: 'int') -> 'Node'
| Create an FX node for ``tensor_node.size(dim)``.
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| create_storage_offset_node(self, tensor_node: 'Node') -> 'Node'
| Create an FX node for ``tensor_node.storage_offset()``.
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| create_stride_node(self, tensor_node: 'Node', dim: 'int') -> 'Node'
| Create an FX node for ``tensor_node.stride(dim)``.
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| eliminate_dead_code(self, is_impure_node: 'Callable[[Node], bool] | None' = None) -> 'bool'
| Remove all dead code from the graph, based on each node's number of
| users, and whether the nodes have any side effects. The graph must be
| topologically sorted before calling.
|
| Args:
| is_impure_node (Optional[Callable[[Node], bool]]): A function that returns
| whether a node is impure. If this is None, then the default behavior is to
| use Node.is_impure.
|
| Returns:
| bool: Whether the graph was changed as a result of the pass.
|
| Example:
|
| Before dead code is eliminated, `a` from `a = x + 1` below has no users
| and thus can be eliminated from the graph without having an effect.
|
| .. code-block:: python
|
| def forward(self, x):
| a = x + 1
| return x + self.attr_1
|
| After dead code is eliminated, `a = x + 1` has been removed, and the rest
| of `forward` remains.
|
| .. code-block:: python
|
| def forward(self, x):
| return x + self.attr_1
|
| .. warning::
|
| Dead code elimination has some heuristics to avoid removing
| side-effectful nodes (see Node.is_impure) but in general coverage
| is very bad, so you should assume that this method is not sound
| to call unless you know that your FX graph consists entirely
| of functional operations or you supply your own custom
| function for detecting side-effectful nodes.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| erase_node(self, to_erase: 'Node') -> 'None'
| Erases a ``Node`` from the ``Graph``. Throws an exception if
| there are still users of that node in the ``Graph``.
|
| Args:
|
| to_erase (Node): The ``Node`` to erase from the ``Graph``.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| find_nodes(self, *, op: 'str', target: 'Target | None' = None, sort: 'bool' = True) -> 'list[Any]'
| Allows for fast query of nodes
|
| Args:
|
| op (str): the name of the operation
|
| target (Optional[Target]): the target of the node. For call_function,
| the target is required. For other ops, the target is optional.
|
| sort (bool): whether to return nodes in the order they appear on
| on the graph.
|
| Returns:
|
| Iterable of nodes with the requested op and target.
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| get_attr(self, qualified_name: 'str', type_expr: 'Any | None' = None) -> 'Node'
| Insert a ``get_attr`` node into the Graph. A ``get_attr`` ``Node`` represents the
| fetch of an attribute from the ``Module`` hierarchy.
|
| Args:
|
| qualified_name (str): the fully-qualified name of the attribute to be retrieved.
| For example, if the traced Module has a submodule named ``foo``, which has a
| submodule named ``bar``, which has an attribute named ``baz``, the qualified
| name ``foo.bar.baz`` should be passed as ``qualified_name``.
|
| type_expr (Optional[Any]): an optional type annotation representing the
| Python type the output of this node will have.
|
|
| Returns:
|
| The newly-created and inserted ``get_attr`` node.
|
| .. note::
| The same insertion point and type expression rules apply for this method
| as ``Graph.create_node``.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| graph_copy(self, g: 'Graph', val_map: 'dict[Node, Node]', return_output_node: 'bool' = False) -> 'Argument | None'
| Copy all nodes from a given graph into ``self``.
|
| Args:
|
| g (Graph): The source graph from which to copy Nodes.
|
| val_map (Dict[Node, Node]): a dictionary that will be populated with a mapping
| from nodes in ``g`` to nodes in ``self``. Note that ``val_map`` can be passed
| in with values in it already to override copying of certain values.
|
| Returns:
|
| The value in ``self`` that is now equivalent to the output value in ``g``,
| if ``g`` had an ``output`` node. ``None`` otherwise.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| inserting_after(self, n: 'Node | None' = None) -> '_InsertPoint'
| Set the point at which create_node and companion methods will insert into the graph.
| When used within a 'with' statement, this will temporarily set the insert point and
| then restore it when the with statement exits::
|
| with g.inserting_after(n):
| ... # inserting after node n
| ... # insert point restored to what it was previously
| g.inserting_after(n) # set the insert point permanently
|
| Args:
|
| n (Optional[Node]): The node before which to insert. If None this will insert after
| the beginning of the entire graph.
|
| Returns:
| A resource manager that will restore the insert point on ``__exit__``.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| inserting_before(self, n: 'Node | None' = None) -> '_InsertPoint'
| Set the point at which create_node and companion methods will insert into the graph.
| When used within a 'with' statement, this will temporarily set the insert point and
| then restore it when the with statement exits::
|
| with g.inserting_before(n):
| ... # inserting before node n
| ... # insert point restored to what it was previously
| g.inserting_before(n) # set the insert point permanently
|
| Args:
|
| n (Optional[Node]): The node before which to insert. If None this will insert before
| the beginning of the entire graph.
|
| Returns:
| A resource manager that will restore the insert point on ``__exit__``.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| lint(self) -> 'None'
| Runs various checks on this Graph to make sure it is well-formed. In
| particular:
| - Checks Nodes have correct ownership (owned by this graph)
| - Checks Nodes appear in topological order
| - If this Graph has an owning GraphModule, checks that targets
| exist in that GraphModule
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| materialize_symint(self, value: 'torch.SymInt | int') -> 'Node | int'
| Single-value convenience wrapper around :meth:`materialize_symints`.
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| materialize_symints(self, values: 'Sequence[torch.SymInt | int]') -> 'list[Node | int]'
| Materialize a list of ``SymInt``/``int`` values as FX subgraphs rooted
| at existing nodes in this graph whose meta produces the referenced
| symbols (typically SymInt placeholders or other sym ops).
|
| consider a graph with a tensor placeholder
| ``%x`` of shape ``(s32, s32)`` and we want to record this stride
| as an FX value to pass to a later op, two ways to do it.
|
| * ``g.create_stride_node(%x, 0)`` emits ``%t = aten.sym_stride.int(%x, 0)``.
| The semantics of this op are "ask ``%x`` for its current stride at
| dim 0". If a later pass (e.g. mkldnn channels-last conversion) mutates
| ``%x``'s layout, re-running ``FakeTensorProp`` will overwrite
| ``%t.meta["val"]`` with the NEW stride. This is the right behavior
| when you want a *live* query on the producer.
|
| * ``g.materialize_symints([%x.meta["val"].stride(0)])`` walks the sympy
| expression ``s32`` and emits an FX subgraph that recomputes it from
| the existing producer of ``s32`` (here the placeholder ``%x`` itself
| via ``aten.sym_size.int(%x, 0)``, or a SymInt placeholder if one
| exists). The resulting node's value is "what ``s32`` is at runtime"
| -- which is determined by the input's shape and is INDEPENDENT of any
| layout change to ``%x``. This is the right behavior when you want to
| *freeze* the trace-time stride into the graph.
|
| Note: like other ``Graph`` node-creation APIs (``call_function``,
| ``create_size_node``, etc.), nodes are emitted at the graph's current
| insertion point. The default insertion point (``Graph._root.prepend``)
| appends new nodes to the end of the graph, which on a graph that
| already has an ``output`` node means they land *after* ``return``
| (orphaned). Callers typically scope this in
| ``with graph.inserting_before(graph.output_node()):`` so the new
| nodes land in the body.
|
| Performance: each call performs an O(graph_size) producer-discovery
| scan and builds a per-call ``expr_to_proxy`` hash-cons cache. Prefer
| batching every SymInt you need to lift into a single call (or as few
| calls as possible) over calling it once per value -- this amortises
| the graph scan and lets symints with shared sub-expressions get
| hash-consed into a single subgraph.
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| node_copy(self, node: 'Node', arg_transform: 'Callable[[Node], Argument]' = <function Graph.<lambda> at 0x00000199ECD16DE0>) -> 'Node'
| Copy a node from one graph into another. ``arg_transform`` needs to transform arguments from
| the graph of node to the graph of self. Example::
|
| # Copying all the nodes in `g` into `new_graph`
| g: torch.fx.Graph = ...
| new_graph = torch.fx.graph()
| value_remap = {}
| for node in g.nodes:
| value_remap[node] = new_graph.node_copy(node, lambda n: value_remap[n])
|
| Args:
|
| node (Node): The node to copy into ``self``.
|
| arg_transform (Callable[[Node], Argument]): A function that transforms
| ``Node`` arguments in node's ``args`` and ``kwargs`` into the
| equivalent argument in ``self``. In the simplest case, this should
| retrieve a value out of a table mapping Nodes in the original
| graph to ``self``.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| on_generate_code(self, make_transformer: 'Callable[[TransformCodeFunc | None], TransformCodeFunc]') -> 'contextlib.AbstractContextManager[None]'
| Register a transformer function when python code is generated
|
| Args:
| make_transformer (Callable[[Optional[TransformCodeFunc]], TransformCodeFunc]):
| a function that returns a code transformer to be registered.
| This function is called by `on_generate_code` to obtain the
| code transformer.
|
| This function is also given as its input the currently
| registered code transformer (or None if nothing is registered),
| in case it is not desirable to overwrite it. This is useful to
| chain code transformers together.
|
| Returns:
| a context manager that when used in a `with` statement, to automatically
| restore the previously registered code transformer.
|
| Example:
|
| .. code-block:: python
|
|
| gm: fx.GraphModule = ...
|
|
| # This is a code transformer we want to register. This code
| # transformer prepends a pdb import and trace statement at the very
| # beginning of the generated torch.fx code to allow for manual
| # debugging with the PDB library.
| def insert_pdb(body):
| return ["import pdb; pdb.set_trace()\n", *body]
|
|
| # Registers `insert_pdb`, and overwrites the current registered
| # code transformer (given by `_` to the lambda):
| gm.graph.on_generate_code(lambda _: insert_pdb)
|
| # Or alternatively, registers a code transformer which first
| # runs `body` through existing registered transformer, then
| # through `insert_pdb`:
| gm.graph.on_generate_code(
| lambda current_trans: (
| lambda body: insert_pdb(
| current_trans(body) if current_trans else body
| )
| )
| )
|
| gm.recompile()
| gm(*inputs) # drops into pdb
|
|
| This function can also be used as a context manager, with the benefit to
| automatically restores the previously registered code transformer:
|
| .. code-block:: python
|
| # ... continue from previous example
|
| with gm.graph.on_generate_code(lambda _: insert_pdb):
| # do more stuff with `gm`...
| gm.recompile()
| gm(*inputs) # drops into pdb
|
| # now previous code transformer is restored (but `gm`'s code with pdb
| # remains - that means you can run `gm` with pdb here too, until you
| # run next `recompile()`).
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| output(self, result: 'Argument', type_expr: 'Any | None' = None)
| Insert an ``output`` ``Node`` into the ``Graph``. An ``output`` node represents
| a ``return`` statement in Python code. ``result`` is the value that should
| be returned.
|
| Args:
|
| result (Argument): The value to be returned.
|
| type_expr (Optional[Any]): an optional type annotation representing the
| Python type the output of this node will have.
|
| .. note::
|
| The same insertion point and type expression rules apply for this method
| as ``Graph.create_node``.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| output_node(self) -> 'Node'
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| placeholder(self, name: 'str', type_expr: 'Any | None' = None, default_value: 'Any') -> 'Node'
| Insert a ``placeholder`` node into the Graph. A ``placeholder`` represents
| a function input.
|
| Args:
|
| name (str): A name for the input value. This corresponds to the name
| of the positional argument to the function this ``Graph`` represents.
|
| type_expr (Optional[Any]): an optional type annotation representing the
| Python type the output of this node will have. This is needed in some
| cases for proper code generation (e.g. when the function is used
| subsequently in TorchScript compilation).
|
| default_value (Any): The default value this function argument should take
| on. NOTE: to allow for `None` as a default value, `inspect.Signature.empty`
| should be passed as this argument to specify that the parameter does _not_
| have a default value.
|
| .. note::
| The same insertion point and type expression rules apply for this method
| as ``Graph.create_node``.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| print_tabular(self) -> 'None'
| Prints the intermediate representation of the graph in tabular
| format. Note that this API requires the ``tabulate`` module to be
| installed.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| process_inputs(self, *args: 'Any') -> 'Any'
| Processes args so that they can be passed to the FX graph.
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| process_outputs(self, out: 'Any') -> 'Any'
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| python_code(self, root_module: 'str', *, verbose: 'bool' = False, include_stride: 'bool' = False, include_device: 'bool' = False, colored: 'bool' = False, expanded_def: 'bool' = False, record_func: 'bool' = False, additional_meta: 'list[str] | None' = None) -> 'PythonCode'
| Turn this ``Graph`` into valid Python code.
|
| Args:
|
| root_module (str): The name of the root module on which to look-up
| qualified name targets. This is usually 'self'.
|
| Returns:
|
| A PythonCode object, consisting of two fields:
| src: the Python source code representing the object
| globals: a dictionary of global names in `src` -> the objects that they reference.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| set_codegen(self, codegen: 'CodeGen') -> 'None'
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| nodes
| Get the list of Nodes that constitute this Graph.
|
| Note that this ``Node`` list representation is a doubly-linked list. Mutations
| during iteration (e.g. delete a Node, add a Node) are safe.
|
| Returns:
|
| A doubly-linked list of Nodes. Note that ``reversed`` can be called on
| this list to switch iteration order.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| owning_module
class GraphModule(torch.nn.modules.module.Module)
| GraphModule(*args: 'Any', **kwargs: 'Any') -> 'Self'
|
| GraphModule is an nn.Module generated from an fx.Graph. Graphmodule has a
| ``graph`` attribute, as well as ``code`` and ``forward`` attributes generated
| from that ``graph``.
|
| .. warning::
|
| When ``graph`` is reassigned, ``code`` and ``forward`` will be automatically
| regenerated. However, if you edit the contents of the ``graph`` without reassigning
| the ``graph`` attribute itself, you must call ``recompile()`` to update the generated
| code.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| Method resolution order:
| GraphModule
| torch.nn.modules.module.Module
| builtins.object
|
| Methods defined here:
|
| __copy__(self) -> 'GraphModule'
|
| __deepcopy__(self, memo: 'dict[int, Any]') -> 'GraphModule'
| # because __reduce__ is defined for serialization,
| # we need to define deepcopy otherwise it will call __reduce__
| # and cause symbolic tracing to occur every time we try to copy the object
|
| __init__(self, root: 'torch.nn.Module | dict[str, Any]', graph: 'Graph', class_name: 'str' = 'GraphModule') -> 'None'
| Construct a GraphModule.
|
| Args:
|
| root (Union[torch.nn.Module, Dict[str, Any]):
| ``root`` can either be an nn.Module instance or a Dict mapping strings to any attribute type.
| In the case that ``root`` is a Module, any references to Module-based objects (via qualified
| name) in the Graph's Nodes' ``target`` field will be copied over from the respective place
| within ``root``'s Module hierarchy into the GraphModule's module hierarchy.
| In the case that ``root`` is a dict, the qualified name found in a Node's ``target`` will be
| looked up directly in the dict's keys. The object mapped to by the Dict will be copied
| over into the appropriate place within the GraphModule's module hierarchy.
|
| graph (Graph): ``graph`` contains the nodes this GraphModule should use for code generation
|
| class_name (str): ``name`` denotes the name of this GraphModule for debugging purposes. If it's unset, all
| error messages will report as originating from ``GraphModule``. It may be helpful to set this
| to ``root``'s original name or a name that makes sense within the context of your transform.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| __reduce__(self) -> 'tuple[Any, ...]'
| Serialization of GraphModule. We serialize only the generated code, not
| the underlying ``Graph``. This is because ``Graph`` does not have on-disk
| backward-compatibility guarantees, whereas Python source code does.
| On the deserialization side, we symbolically trace through the generated
| code to regenerate the underlying ``Graph``
|
| __reduce_package__(self, exporter: 'PackageExporter') -> 'tuple[Any, ...]'
|
| __str__(self) -> 'str'
| Return str(self).
|
| add_submodule(self, target: 'str', m: 'torch.nn.Module') -> 'bool'
| Adds the given submodule to ``self``.
|
| This installs empty Modules where none exist yet if they are
| subpaths of ``target``.
|
| Args:
| target: The fully-qualified string name of the new submodule
| (See example in ``nn.Module.get_submodule`` for how to
| specify a fully-qualified string.)
| m: The submodule itself; the actual object we want to
| install in the current Module
|
| Return:
| bool: Whether or not the submodule could be inserted. For
| this method to return True, each object in the chain
| denoted by ``target`` must either a) not exist yet,
| or b) reference an ``nn.Module`` (not a parameter or
| other attribute)
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| delete_all_unused_submodules(self) -> 'None'
| Deletes all unused submodules from ``self``.
|
| A Module is considered "used" if any one of the following is
| true:
| 1. It has children that are used
| 2. Its forward is called directly via a ``call_module`` node
| 3. It has a non-Module attribute that is used from a
| ``get_attr`` node
|
| This method can be called to clean up an ``nn.Module`` without
| manually calling ``delete_submodule`` on each unused submodule.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| delete_submodule(self, target: 'str') -> 'bool'
| Deletes the given submodule from ``self``.
|
| The module will not be deleted if ``target`` is not a valid
| target.
|
| Args:
| target: The fully-qualified string name of the new submodule
| (See example in ``nn.Module.get_submodule`` for how to
| specify a fully-qualified string.)
|
| Returns:
| bool: Whether or not the target string referenced a
| submodule we want to delete. A return value of ``False``
| means that the ``target`` was not a valid reference to
| a submodule.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| print_readable(self, print_output: 'bool' = True, include_stride: 'bool' = False, include_device: 'bool' = False, colored: 'bool' = False, *, fast_sympy_print: 'bool' = False, expanded_def: 'bool' = False, additional_meta: 'list[str] | None' = None) -> 'str'
| Return the Python code generated for current GraphModule and its children GraphModules.
|
| Args:
| additional_meta: Optional list of meta keys to include in the output.
| For each key in the list, if it exists in node.meta, its value
| will be shown in the format "key: value".
| Example: `print_readable(additional_meta=["seq_nr"])`.
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| recompile(self) -> 'PythonCode'
| Recompile this GraphModule from its ``graph`` attribute. This should be
| called after editing the contained ``graph``, otherwise the generated
| code of this ``GraphModule`` will be out of date.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| to_folder(self, folder: 'str | os.PathLike[str]', module_name: 'str' = 'FxModule') -> 'None'
| Dumps out module to ``folder`` with ``module_name`` so that it can be
| imported with ``from <folder> import <module_name>``
|
| Args:
|
| folder (Union[str, os.PathLike]): The folder to write the code out to
|
| module_name (str): Top-level name to use for the ``Module`` while
| writing out the code
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, *args: 'Any', **kwargs: 'Any') -> 'Self'
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| code
| Return the Python code generated from the ``Graph`` underlying this
| ``GraphModule``.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| graph
| Return the ``Graph`` underlying this ``GraphModule``
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __jit_unused_properties__ = ['graph', '_boxed_call']
|
| ----------------------------------------------------------------------
| Methods inherited from torch.nn.modules.module.Module:
|
| __call__ = _wrapped_call_impl(self, *args, **kwargs)
|
| __delattr__(self, name) -> None
| Implement delattr(self, name).
|
| __dir__(self)
| Default dir() implementation.
|
| __getattr__(self, name: str) -> Union[torch.Tensor, ForwardRef('Module')]
| # It is crucial that the return type is not annotated as `Any`, otherwise type checking
| # on `torch.nn.Module` and all its subclasses is largely disabled as a result. See:
| # https://github.com/pytorch/pytorch/pull/115074
|
| __getstate__(self)
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setattr__(self, name: str, value: Union[torch.Tensor, ForwardRef('Module')]) -> None
| Implement setattr(self, name, value).
|
| __setstate__(self, state)
|
| add_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Add a child module to the current module.
|
| The module can be accessed as an attribute using the given name.
|
| Args:
| name (str): name of the child module. The child module can be
| accessed from this module using the given name
| module (Module): child module to be added to the module.
|
| apply(self, fn: collections.abc.Callable[['Module'], None]) -> Self
| Apply ``fn`` recursively to every submodule (as returned by ``.children()``) as well as self.
|
| Typical use includes initializing the parameters of a model
| (see also :ref:`nn-init-doc`).
|
| Args:
| fn (:class:`Module` -> None): function to be applied to each submodule
|
| Returns:
| Module: self
|
| Example::
|
| >>> @torch.no_grad()
| >>> def init_weights(m):
| >>> print(m)
| >>> if type(m) is nn.Linear:
| >>> m.weight.fill_(1.0)
| >>> print(m.weight)
| >>> net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
| >>> net.apply(init_weights)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
|
| bfloat16(self) -> Self
| Casts all floating point parameters and buffers to ``bfloat16`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| buffers(self, recurse: bool = True) -> collections.abc.Iterator[torch.Tensor]
| Return an iterator over module buffers.
|
| Args:
| recurse (bool): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module.
|
| Yields:
| torch.Tensor: module buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for buf in model.buffers():
| >>> print(type(buf), buf.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| children(self) -> collections.abc.Iterator['Module']
| Return an iterator over immediate children modules.
|
| Yields:
| Module: a child module
|
| compile(self, *args, **kwargs) -> None
| Compile this Module's forward using :func:`torch.compile`.
|
| This Module's `__call__` method is compiled and all arguments are passed as-is
| to :func:`torch.compile`.
|
| See :func:`torch.compile` for details on the arguments for this function.
|
| cpu(self) -> Self
| Move all model parameters and buffers to the CPU.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| cuda(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the GPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on GPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| double(self) -> Self
| Casts all floating point parameters and buffers to ``double`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| eval(self) -> Self
| Set the module in evaluation mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e. whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| This is equivalent with :meth:`self.train(False) <torch.nn.Module.train>`.
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.eval()` and several similar mechanisms that may be confused with it.
|
| Returns:
| Module: self
|
| extra_repr(self) -> str
| Return the extra representation of the module.
|
| To print customized extra information, you should re-implement
| this method in your own modules. Both single-line and multi-line
| strings are acceptable.
|
| float(self) -> Self
| Casts all floating point parameters and buffers to ``float`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| forward = _forward_unimplemented(self, *input: Any) -> None from torch.nn.modules.module
| Define the computation performed at every call.
|
| Should be overridden by all subclasses.
|
| .. note::
| Although the recipe for forward pass needs to be defined within
| this function, one should call the :class:`Module` instance afterwards
| instead of this since the former takes care of running the
| registered hooks while the latter silently ignores them.
|
| get_buffer(self, target: str) -> torch.Tensor
| Return the buffer given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the buffer
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.Tensor: The buffer referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not a
| buffer
|
| get_extra_state(self) -> Any
| Return any extra state to include in the module's state_dict.
|
| Implement this and a corresponding :func:`set_extra_state` for your module
| if you need to store extra state. This function is called when building the
| module's `state_dict()`.
|
| Note that extra state should be picklable to ensure working serialization
| of the state_dict. We only provide backwards compatibility guarantees
| for serializing Tensors; other objects may break backwards compatibility if
| their serialized pickled form changes.
|
| Returns:
| object: Any extra state to store in the module's state_dict
|
| get_parameter(self, target: str) -> torch.nn.parameter.Parameter
| Return the parameter given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the Parameter
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Parameter: The Parameter referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not an
| ``nn.Parameter``
|
| get_submodule(self, target: str) -> 'Module'
| Return the submodule given by ``target`` if it exists, otherwise throw an error.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(16, 33, kernel_size=(3, 3), stride=(2, 2))
| )
| (linear): Linear(in_features=100, out_features=200, bias=True)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` which has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To check whether or not we have the ``linear`` submodule, we
| would call ``get_submodule("net_b.linear")``. To check whether
| we have the ``conv`` submodule, we would call
| ``get_submodule("net_b.net_c.conv")``.
|
| The runtime of ``get_submodule`` is bounded by the degree
| of module nesting in ``target``. A query against
| ``named_modules`` achieves the same result, but it is O(N) in
| the number of transitive modules. So, for a simple check to see
| if some submodule exists, ``get_submodule`` should always be
| used.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Module: The submodule referenced by ``target``
|
| Raises:
| AttributeError: If at any point along the path resulting from
| the target string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| half(self) -> Self
| Casts all floating point parameters and buffers to ``half`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| ipu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the IPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on IPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| load_state_dict(self, state_dict: collections.abc.Mapping[str, typing.Any], strict: bool = True, assign: bool = False)
| Copy parameters and buffers from :attr:`state_dict` into this module and its descendants.
|
| If :attr:`strict` is ``True``, then
| the keys of :attr:`state_dict` must exactly match the keys returned
| by this module's :meth:`~torch.nn.Module.state_dict` function.
|
| .. warning::
| If :attr:`assign` is ``True`` the optimizer must be created after
| the call to :attr:`load_state_dict` unless
| :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| Args:
| state_dict (dict): a dict containing parameters and
| persistent buffers.
| strict (bool, optional): whether to strictly enforce that the keys
| in :attr:`state_dict` match the keys returned by this module's
| :meth:`~torch.nn.Module.state_dict` function. Default: ``True``
| assign (bool, optional): When set to ``False``, the properties of the tensors
| in the current module are preserved whereas setting it to ``True`` preserves
| properties of the Tensors in the state dict. The only
| exception is the ``requires_grad`` field of :class:`~torch.nn.Parameter`
| for which the value from the module is preserved. Default: ``False``
|
| Returns:
| ``NamedTuple`` with ``missing_keys`` and ``unexpected_keys`` fields:
| * ``missing_keys`` is a list of str containing any keys that are expected
| by this module but missing from the provided ``state_dict``.
| * ``unexpected_keys`` is a list of str containing the keys that are not
| expected by this module but present in the provided ``state_dict``.
|
| Note:
| If a parameter or buffer is registered as ``None`` and its corresponding key
| exists in :attr:`state_dict`, :meth:`load_state_dict` will raise a
| ``RuntimeError``.
|
| modules(self, remove_duplicate: bool = True) -> collections.abc.Iterator['Module']
| Return an iterator over all modules in the network.
|
| Args:
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not.
|
| Yields:
| Module: a module in the network
|
| Note:
| Duplicate modules are returned only once by default. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.modules()):
| ... print(idx, '->', m)
|
| 0 -> Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
| 1 -> Linear(in_features=2, out_features=2, bias=True)
|
| mtia(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the MTIA.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on MTIA while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| named_buffers(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.Tensor]]
| Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
|
| Args:
| prefix (str): prefix to prepend to all buffer names.
| recurse (bool, optional): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module. Defaults to True.
| remove_duplicate (bool, optional): whether to remove the duplicated buffers in the result. Defaults to True.
|
| Yields:
| (str, torch.Tensor): Tuple containing the name and buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, buf in self.named_buffers():
| >>> if name in ['running_var']:
| >>> print(buf.size())
|
| named_children(self) -> collections.abc.Iterator[tuple[str, 'Module']]
| Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
|
| Yields:
| (str, Module): Tuple containing a name and child module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, module in model.named_children():
| >>> if name in ['conv4', 'conv5']:
| >>> print(module)
|
| named_modules(self, memo: set['Module'] | None = None, prefix: str = '', remove_duplicate: bool = True)
| Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
|
| Args:
| memo: a memo to store the set of modules already added to the result
| prefix: a prefix that will be added to the name of the module
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not
|
| Yields:
| (str, Module): Tuple of name and module
|
| Note:
| Duplicate modules are returned only once. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.named_modules()):
| ... print(idx, '->', m)
|
| 0 -> ('', Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| ))
| 1 -> ('0', Linear(in_features=2, out_features=2, bias=True))
|
| named_parameters(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.nn.parameter.Parameter]]
| Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
|
| Args:
| prefix (str): prefix to prepend to all parameter names.
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
| remove_duplicate (bool, optional): whether to remove the duplicated
| parameters in the result. Defaults to True.
|
| Yields:
| (str, Parameter): Tuple containing the name and parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, param in self.named_parameters():
| >>> if name in ['bias']:
| >>> print(param.size())
|
| parameters(self, recurse: bool = True) -> collections.abc.Iterator[torch.nn.parameter.Parameter]
| Return an iterator over module parameters.
|
| This is typically passed to an optimizer.
|
| Args:
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
|
| Yields:
| Parameter: module parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for param in model.parameters():
| >>> print(type(param), param.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| register_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None]) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| This function is deprecated in favor of :meth:`~torch.nn.Module.register_full_backward_hook` and
| the behavior of this function will change in future versions.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_buffer(self, name: str, tensor: torch.Tensor | None, persistent: bool = True) -> None
| Add a buffer to the module.
|
| This is typically used to register a buffer that should not be
| considered a model parameter. For example, BatchNorm's ``running_mean``
| is not a parameter, but is part of the module's state. Buffers, by
| default, are persistent and will be saved alongside parameters. This
| behavior can be changed by setting :attr:`persistent` to ``False``. The
| only difference between a persistent buffer and a non-persistent buffer
| is that the latter will not be a part of this module's
| :attr:`state_dict`.
|
| Buffers can be accessed as attributes using given names.
|
| Args:
| name (str): name of the buffer. The buffer can be accessed
| from this module using the given name
| tensor (Tensor or None): buffer to be registered. If ``None``, then operations
| that run on buffers, such as :attr:`cuda`, are ignored. If ``None``,
| the buffer is **not** included in the module's :attr:`state_dict`.
| persistent (bool): whether the buffer is part of this module's
| :attr:`state_dict`.
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> self.register_buffer('running_mean', torch.zeros(num_features))
|
| register_forward_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...], typing.Any], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any], typing.Any], typing.Any | None], *, prepend: bool = False, with_kwargs: bool = False, always_call: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward hook on the module.
|
| The hook will be called every time after :func:`forward` has computed an output.
|
| If ``with_kwargs`` is ``False`` or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| output. It can modify the input inplace but it will not have effect on
| forward since this is called after :func:`forward` is called. The hook
| should have the following signature::
|
| hook(module, args, output) -> None or modified output
|
| If ``with_kwargs`` is ``True``, the forward hook will be passed the
| ``kwargs`` given to the forward function and be expected to return the
| output possibly modified. The hook should have the following signature::
|
| hook(module, args, kwargs, output) -> None or modified output
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If ``True``, the provided ``hook`` will be fired
| before all existing ``forward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``forward`` hooks registered with
| :func:`register_module_forward_hook` will fire before all hooks
| registered by this method.
| Default: ``False``
| with_kwargs (bool): If ``True``, the ``hook`` will be passed the
| kwargs given to the forward function.
| Default: ``False``
| always_call (bool): If ``True`` the ``hook`` will be run regardless of
| whether an exception is raised while calling the Module.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_forward_pre_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...]], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[typing.Any, dict[str, typing.Any]] | None], *, prepend: bool = False, with_kwargs: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward pre-hook on the module.
|
| The hook will be called every time before :func:`forward` is invoked.
|
|
| If ``with_kwargs`` is false or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| input. User can either return a tuple or a single modified value in the
| hook. We will wrap the value into a tuple if a single value is returned
| (unless that value is already a tuple). The hook should have the
| following signature::
|
| hook(module, args) -> None or modified input
|
| If ``with_kwargs`` is true, the forward pre-hook will be passed the
| kwargs given to the forward function. And if the hook modifies the
| input, both the args and kwargs should be returned. The hook should have
| the following signature::
|
| hook(module, args, kwargs) -> None or a tuple of modified input and kwargs
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``forward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``forward_pre`` hooks registered with
| :func:`register_module_forward_pre_hook` will fire before all
| hooks registered by this method.
| Default: ``False``
| with_kwargs (bool): If true, the ``hook`` will be passed the kwargs
| given to the forward function.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| The hook will be called every time the gradients with respect to a module are computed, and its firing rules are as follows:
|
| 1. Ordinarily, the hook fires when the gradients are computed with respect to the module inputs.
| 2. If none of the module inputs require gradients, the hook will fire when the gradients are computed
| with respect to module outputs.
| 3. If none of the module outputs require gradients, then the hooks will not fire.
|
| The hook should have the following signature::
|
| hook(module, grad_input, grad_output) -> tuple(Tensor) or None
|
| The :attr:`grad_input` and :attr:`grad_output` are tuples that contain the gradients
| with respect to the inputs and outputs respectively. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the input that will be used in place of :attr:`grad_input` in
| subsequent computations. :attr:`grad_input` will only correspond to the inputs given
| as positional arguments and all kwarg arguments are ignored. Entries
| in :attr:`grad_input` and :attr:`grad_output` will be ``None`` for all non-Tensor
| arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs or outputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``backward`` hooks registered with
| :func:`register_module_full_backward_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_pre_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward pre-hook on the module.
|
| The hook will be called every time the gradients for the module are computed.
| The hook should have the following signature::
|
| hook(module, grad_output) -> tuple[Tensor, ...], Tensor or None
|
| The :attr:`grad_output` is a tuple. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the output that will be used in place of :attr:`grad_output` in
| subsequent computations. Entries in :attr:`grad_output` will be ``None`` for
| all non-Tensor arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``backward_pre`` hooks registered with
| :func:`register_module_full_backward_pre_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_post_hook(self, hook)
| Register a post-hook to be run after module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, incompatible_keys) -> None
|
| The ``module`` argument is the current module that this hook is registered
| on, and the ``incompatible_keys`` argument is a ``NamedTuple`` consisting
| of attributes ``missing_keys`` and ``unexpected_keys``. ``missing_keys``
| is a ``list`` of ``str`` containing the missing keys and
| ``unexpected_keys`` is a ``list`` of ``str`` containing the unexpected keys.
|
| The given incompatible_keys can be modified inplace if needed.
|
| Note that the checks performed when calling :func:`load_state_dict` with
| ``strict=True`` are affected by modifications the hook makes to
| ``missing_keys`` or ``unexpected_keys``, as expected. Additions to either
| set of keys will result in an error being thrown when ``strict=True``, and
| clearing out both missing and unexpected keys will avoid an error.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook)
| Register a pre-hook to be run before module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) -> None # noqa: B950
|
| Arguments:
| hook (Callable): Callable hook that will be invoked before
| loading the state dict.
|
| register_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Alias for :func:`add_module`.
|
| register_parameter(self, name: str, param: torch.nn.parameter.Parameter | None) -> None
| Add a parameter to the module.
|
| The parameter can be accessed as an attribute using given name.
|
| Args:
| name (str): name of the parameter. The parameter can be accessed
| from this module using the given name
| param (Parameter or None): parameter to be added to the module. If
| ``None``, then operations that run on parameters, such as :attr:`cuda`,
| are ignored. If ``None``, the parameter is **not** included in the
| module's :attr:`state_dict`.
|
| register_state_dict_post_hook(self, hook)
| Register a post-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata) -> None
|
| The registered hooks can modify the ``state_dict`` inplace.
|
| register_state_dict_pre_hook(self, hook)
| Register a pre-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, prefix, keep_vars) -> None
|
| The registered hooks can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| requires_grad_(self, requires_grad: bool = True) -> Self
| Change if autograd should record operations on parameters in this module.
|
| This method sets the parameters' :attr:`requires_grad` attributes
| in-place.
|
| This method is helpful for freezing part of the module for finetuning
| or training parts of a model individually (e.g., GAN training).
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.requires_grad_()` and several similar mechanisms that may be confused with it.
|
| Args:
| requires_grad (bool): whether autograd should record operations on
| parameters in this module. Default: ``True``.
|
| Returns:
| Module: self
|
| set_extra_state(self, state: Any) -> None
| Set extra state contained in the loaded `state_dict`.
|
| This function is called from :func:`load_state_dict` to handle any extra state
| found within the `state_dict`. Implement this function and a corresponding
| :func:`get_extra_state` for your module if you need to store extra state within its
| `state_dict`.
|
| Args:
| state (dict): Extra state from the `state_dict`
|
| set_submodule(self, target: str, module: 'Module', strict: bool = False) -> None
| Set the submodule given by ``target`` if it exists, otherwise throw an error.
|
| .. note::
| If ``strict`` is set to ``False`` (default), the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``strict`` is set to ``True``,
| the method will only attempt to replace an existing submodule and throw an error if
| the submodule does not exist.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(3, 3, 3)
| )
| (linear): Linear(3, 3)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To override the ``Conv2d`` with a new submodule ``Linear``, you
| could call ``set_submodule("net_b.net_c.conv", nn.Linear(1, 1))``
| where ``strict`` could be ``True`` or ``False``
|
| To add a new submodule ``Conv2d`` to the existing ``net_b`` module,
| you would call ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1))``.
|
| In the above if you set ``strict=True`` and call
| ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1), strict=True)``, an AttributeError
| will be raised because ``net_b`` does not have a submodule named ``conv``.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
| module: The module to set the submodule to.
| strict: If ``False``, the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``True``,
| the method will only attempt to replace an existing submodule and throw an error
| if the submodule doesn't already exist.
|
| Raises:
| ValueError: If the ``target`` string is empty or if ``module`` is not an instance of ``nn.Module``.
| AttributeError: If at any point along the path resulting from
| the ``target`` string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| share_memory(self) -> Self
| See :meth:`torch.Tensor.share_memory_`.
|
| state_dict(self, *args, destination=None, prefix='', keep_vars=False)
| Return a dictionary containing references to the whole state of the module.
|
| Both parameters and persistent buffers (e.g. running averages) are
| included. Keys are corresponding parameter and buffer names.
| Parameters and buffers set to ``None`` are not included.
|
| .. note::
| The returned object is a shallow copy. It contains references
| to the module's parameters and buffers.
|
| .. warning::
| Currently ``state_dict()`` also accepts positional arguments for
| ``destination``, ``prefix`` and ``keep_vars`` in order. However,
| this is being deprecated and keyword arguments will be enforced in
| future releases.
|
| .. warning::
| Please avoid the use of argument ``destination`` as it is not
| designed for end-users.
|
| Args:
| destination (dict, optional): If provided, the state of module will
| be updated into the dict and the same object is returned.
| Otherwise, an ``OrderedDict`` will be created and returned.
| Default: ``None``.
| prefix (str, optional): a prefix added to parameter and buffer
| names to compose the keys in state_dict. Default: ``''``.
| keep_vars (bool, optional): by default the :class:`~torch.Tensor` s
| returned in the state dict are detached from autograd. If it's
| set to ``True``, detaching will not be performed.
| Default: ``False``.
|
| Returns:
| dict:
| a dictionary containing a whole state of the module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> module.state_dict().keys()
| ['bias', 'weight']
|
| to(self, *args, **kwargs)
| Move and/or cast the parameters and buffers.
|
| This can be called as
|
| .. function:: to(device=None, dtype=None, non_blocking=False)
| :noindex:
|
| .. function:: to(dtype, non_blocking=False)
| :noindex:
|
| .. function:: to(tensor, non_blocking=False)
| :noindex:
|
| .. function:: to(memory_format=torch.channels_last)
| :noindex:
|
| Its signature is similar to :meth:`torch.Tensor.to`, but only accepts
| floating point or complex :attr:`dtype`\ s. In addition, this method will
| only cast the floating point or complex parameters and buffers to :attr:`dtype`
| (if given). The integral parameters and buffers will be moved
| :attr:`device`, if that is given, but with dtypes unchanged. When
| :attr:`non_blocking` is set, it tries to convert/move asynchronously
| with respect to the host if possible, e.g., moving CPU Tensors with
| pinned memory to CUDA devices.
|
| See below for examples.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (:class:`torch.device`): the desired device of the parameters
| and buffers in this module
| dtype (:class:`torch.dtype`): the desired floating point or complex dtype of
| the parameters and buffers in this module
| tensor (torch.Tensor): Tensor whose dtype and device are the desired
| dtype and device for all parameters and buffers in this module
| memory_format (:class:`torch.memory_format`): the desired memory
| format for 4D parameters and buffers in this module (keyword
| only argument)
|
| Returns:
| Module: self
|
| Examples::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> linear = nn.Linear(2, 2)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]])
| >>> linear.to(torch.double)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]], dtype=torch.float64)
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA1)
| >>> gpu1 = torch.device("cuda:1")
| >>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
| >>> cpu = torch.device("cpu")
| >>> linear.to(cpu)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16)
|
| >>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.3741+0.j, 0.2382+0.j],
| [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
| >>> linear(torch.ones(3, 2, dtype=torch.cdouble))
| tensor([[0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
|
| to_empty(self, *, device: str | torch.device | int | None, recurse: bool = True) -> Self
| Move the parameters and buffers to the specified device without copying storage.
|
| Args:
| device (:class:`torch.device`): The desired device of the parameters
| and buffers in this module.
| recurse (bool): Whether parameters and buffers of submodules should
| be recursively moved to the specified device.
|
| Returns:
| Module: self
|
| train(self, mode: bool = True) -> Self
| Set the module in training mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e., whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| Args:
| mode (bool): whether to set training mode (``True``) or evaluation
| mode (``False``). Default: ``True``.
|
| Returns:
| Module: self
|
| type(self, dst_type: torch.dtype | str) -> Self
| Casts all parameters and buffers to :attr:`dst_type`.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| dst_type (type or string): the desired type
|
| Returns:
| Module: self
|
| xpu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the XPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing optimizer if the module will
| live on XPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset gradients of all model parameters.
|
| See similar function under :class:`torch.optim.Optimizer` for more context.
|
| Args:
| set_to_none (bool): instead of setting to zero, set the grads to None.
| See :meth:`torch.optim.Optimizer.zero_grad` for details.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.nn.modules.module.Module:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.nn.modules.module.Module:
|
| T_destination = ~T_destination
|
| call_super_init = False
|
| dump_patches = False
class Interpreter(builtins.object)
| Interpreter(module: torch.nn.modules.module.Module, garbage_collect_values: bool = True, graph: torch.fx.graph.Graph | None = None) -> None
|
| An Interpreter executes an FX graph Node-by-Node. This pattern
| can be useful for many things, including writing code
| transformations as well as analysis passes.
|
| Methods in the Interpreter class can be overridden to customize
| the behavior of execution. The map of overridable methods
| in terms of call hierarchy::
|
| run()
| +-- run_node
| +-- placeholder()
| +-- get_attr()
| +-- call_function()
| +-- call_method()
| +-- call_module()
| +-- output()
|
| Example:
|
| Suppose we want to swap all instances of ``torch.neg`` with
| ``torch.sigmoid`` and vice versa (including their ``Tensor``
| method equivalents). We could subclass Interpreter like so::
|
| class NegSigmSwapInterpreter(Interpreter):
| def call_function(
| self, target: Target, args: Tuple, kwargs: Dict
| ) -> Any:
| if target is torch.sigmoid:
| return torch.neg(*args, **kwargs)
| return super().call_function(target, args, kwargs)
|
| def call_method(self, target: Target, args: Tuple, kwargs: Dict) -> Any:
| if target == "neg":
| call_self, *args_tail = args
| return call_self.sigmoid(*args_tail, **kwargs)
| return super().call_method(target, args, kwargs)
|
|
| def fn(x):
| return torch.sigmoid(x).neg()
|
|
| gm = torch.fx.symbolic_trace(fn)
| input = torch.randn(3, 4)
| result = NegSigmSwapInterpreter(gm).run(input)
| torch.testing.assert_close(result, torch.neg(input).sigmoid())
|
| Args:
| module (torch.nn.Module): The module to be executed
| garbage_collect_values (bool): Whether to delete values after their last
| use within the Module's execution. This ensures optimal memory usage during
| execution. This can be disabled to, for example, examine all of the intermediate
| values in the execution by looking at the ``Interpreter.env`` attribute.
| graph (Optional[Graph]): If passed, the interpreter will execute this
| graph instead of `module.graph`, using the provided `module`
| argument to satisfy any requests for state.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| Methods defined here:
|
| __init__(self, module: torch.nn.modules.module.Module, garbage_collect_values: bool = True, graph: torch.fx.graph.Graph | None = None) -> None
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| boxed_run(self, args_list: list[typing.Any]) -> Any
| Run `module` via interpretation and return the result. This uses the "boxed"
| calling convention, where you pass a list of arguments, which will be cleared
| by the interpreter. This ensures that input tensors are promptly deallocated.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| call_function(self, target: 'Target', args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Any]) -> Any
| Execute a ``call_function`` node and return the result.
|
| Args:
| target (Target): The call target for this node. See
| `Node <https://pytorch.org/docs/main/fx.html#torch.fx.Node>`__ for
| details on semantics
| args (Tuple): Tuple of positional args for this invocation
| kwargs (Dict): Dict of keyword arguments for this invocation
|
| Return
| Any: The value returned by the function invocation
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| call_method(self, target: 'Target', args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Any]) -> Any
| Execute a ``call_method`` node and return the result.
|
| Args:
| target (Target): The call target for this node. See
| `Node <https://pytorch.org/docs/main/fx.html#torch.fx.Node>`__ for
| details on semantics
| args (Tuple): Tuple of positional args for this invocation
| kwargs (Dict): Dict of keyword arguments for this invocation
|
| Return
| Any: The value returned by the method invocation
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| call_module(self, target: 'Target', args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Any]) -> Any
| Execute a ``call_module`` node and return the result.
|
| Args:
| target (Target): The call target for this node. See
| `Node <https://pytorch.org/docs/main/fx.html#torch.fx.Node>`__ for
| details on semantics
| args (Tuple): Tuple of positional args for this invocation
| kwargs (Dict): Dict of keyword arguments for this invocation
|
| Return
| Any: The value returned by the module invocation
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| fetch_args_kwargs_from_env(self, n: torch.fx.node.Node) -> tuple[tuple[typing.Any, ...], dict[str, typing.Any]]
| Fetch the concrete values of ``args`` and ``kwargs`` of node ``n``
| from the current execution environment.
|
| Args:
| n (Node): The node for which ``args`` and ``kwargs`` should be fetched.
|
| Return:
| Tuple[Tuple, Dict]: ``args`` and ``kwargs`` with concrete values for ``n``.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| fetch_attr(self, target: str) -> Any
| Fetch an attribute from the ``Module`` hierarchy of ``self.module``.
|
| Args:
| target (str): The fully-qualified name of the attribute to fetch
|
| Return:
| Any: The value of the attribute.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| get_attr(self, target: 'Target', args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Any]) -> Any
| Execute a ``get_attr`` node. Will retrieve an attribute
| value from the ``Module`` hierarchy of ``self.module``.
|
| Args:
| target (Target): The call target for this node. See
| `Node <https://pytorch.org/docs/main/fx.html#torch.fx.Node>`__ for
| details on semantics
| args (Tuple): Tuple of positional args for this invocation
| kwargs (Dict): Dict of keyword arguments for this invocation
|
| Return:
| Any: The value of the attribute that was retrieved
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| map_nodes_to_values(self, args: Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], n: torch.fx.node.Node) -> Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType]
| Recursively descend through ``args`` and look up the concrete value
| for each ``Node`` in the current execution environment.
|
| Args:
| args (Argument): Data structure within which to look up concrete values
|
| n (Node): Node to which ``args`` belongs. This is only used for error reporting.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| output(self, target: 'Target', args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Any]) -> Any
| Execute an ``output`` node. This really just retrieves
| the value referenced by the ``output`` node and returns it.
|
| Args:
| target (Target): The call target for this node. See
| `Node <https://pytorch.org/docs/main/fx.html#torch.fx.Node>`__ for
| details on semantics
| args (Tuple): Tuple of positional args for this invocation
| kwargs (Dict): Dict of keyword arguments for this invocation
|
| Return:
| Any: The return value referenced by the output node
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| placeholder(self, target: 'Target', args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Any]) -> Any
| Execute a ``placeholder`` node. Note that this is stateful:
| ``Interpreter`` maintains an internal iterator over
| arguments passed to ``run`` and this method returns
| next() on that iterator.
|
| Args:
| target (Target): The call target for this node. See
| `Node <https://pytorch.org/docs/main/fx.html#torch.fx.Node>`__ for
| details on semantics
| args (Tuple): Tuple of positional args for this invocation
| kwargs (Dict): Dict of keyword arguments for this invocation
|
| Returns:
| Any: The argument value that was retrieved.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| run(self, *args: Any, initial_env: dict[torch.fx.node.Node, typing.Any] | None = None, enable_io_processing: bool = True) -> Any
| Run `module` via interpretation and return the result.
|
| Args:
| *args: The arguments to the Module to run, in positional order
| initial_env (Optional[Dict[Node, Any]]): An optional starting environment for execution.
| This is a dict mapping `Node` to any value. This can be used, for example, to
| pre-populate results for certain `Nodes` so as to do only partial evaluation within
| the interpreter.
| enable_io_processing (bool): If true, we process the inputs and outputs with graph's process_inputs and
| process_outputs function first before using them.
|
| Returns:
| Any: The value returned from executing the Module
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| run_node(self, n: torch.fx.node.Node) -> Any
| Run a specific node ``n`` and return the result.
| Calls into placeholder, get_attr, call_function,
| call_method, call_module, or output depending
| on ``node.op``
|
| Args:
| n (Node): The Node to execute
|
| Returns:
| Any: The result of executing ``n``
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Node(torch._C._NodeBase)
| Node(graph: 'Graph', name: str, op: str, target: 'Target', args: tuple['Argument', ...], kwargs: dict[str, 'Argument'], return_type: typing.Any | None = None) -> None
|
| ``Node`` is the data structure that represents individual operations within
| a ``Graph``. For the most part, Nodes represent callsites to various entities,
| such as operators, methods, and Modules (some exceptions include nodes that
| specify function inputs and outputs). Each ``Node`` has a function specified
| by its ``op`` property. The ``Node`` semantics for each value of ``op`` are as follows:
|
| - ``placeholder`` represents a function input. The ``name`` attribute specifies the name this value will take on.
| ``target`` is similarly the name of the argument. ``args`` holds either: 1) nothing, or 2) a single argument
| denoting the default parameter of the function input. ``kwargs`` is don't-care. Placeholders correspond to
| the function parameters (e.g. ``x``) in the graph printout.
| - ``get_attr`` retrieves a parameter from the module hierarchy. ``name`` is similarly the name the result of the
| fetch is assigned to. ``target`` is the fully-qualified name of the parameter's position in the module hierarchy.
| ``args`` and ``kwargs`` are don't-care
| - ``call_function`` applies a free function to some values. ``name`` is similarly the name of the value to assign
| to. ``target`` is the function to be applied. ``args`` and ``kwargs`` represent the arguments to the function,
| following the Python calling convention
| - ``call_module`` applies a module in the module hierarchy's ``forward()`` method to given arguments. ``name`` is
| as previous. ``target`` is the fully-qualified name of the module in the module hierarchy to call.
| ``args`` and ``kwargs`` represent the arguments to invoke the module on, *excluding the self argument*.
| - ``call_method`` calls a method on a value. ``name`` is as similar. ``target`` is the string name of the method
| to apply to the ``self`` argument. ``args`` and ``kwargs`` represent the arguments to invoke the module on,
| *including the self argument*
| - ``output`` contains the output of the traced function in its ``args[0]`` attribute. This corresponds to the "return" statement
| in the Graph printout.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| Method resolution order:
| Node
| torch._C._NodeBase
| builtins.object
|
| Methods defined here:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __init__(self, graph: 'Graph', name: str, op: str, target: 'Target', args: tuple['Argument', ...], kwargs: dict[str, 'Argument'], return_type: typing.Any | None = None) -> None
| Instantiate an instance of ``Node``. Note: most often, you want to use the
| Graph APIs, i.e. ``Graph.call_module``, ``Graph.call_method``, etc. rather
| than instantiating a ``Node`` directly.
|
| Args:
| graph (Graph): The ``Graph`` to which this ``Node`` should belong.
|
| name (str): The name to which the output of this ``Node`` should be assigned
|
| op (str): The opcode for this ``Node``. Can be one of 'placeholder',
| 'call_method', 'call_module', 'call_function', 'get_attr',
| 'output'
|
| target ('Target'): The target this op should call. See the broader
| ``Node`` docstring for more details.
|
| args (Tuple['Argument']): The args to be passed to ``target``
|
| kwargs (Dict[str, 'Argument']): The kwargs to be passed to ``target``
|
| return_type (Optional[Any]): The python type expression representing the
| type of the output of this node. This field can be used for
| annotation of values in the generated code or for other types
| of analyses.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setattr__(self, name: str, value: Any) -> None
| Implement setattr(self, name, value).
|
| __setstate__(self, state: dict[str, typing.Any]) -> None
|
| append(self, x: 'Node') -> None
| Insert ``x`` after this node in the list of nodes in the graph.
| Equivalent to ``self.next.prepend(x)``
|
| Args:
| x (Node): The node to put after this node. Must be a member of the same graph.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| format_node(self, placeholder_names: list[str] | None = None, maybe_return_typename: list[str] | None = None, *, include_tensor_metadata: bool = False) -> str | None
| Return a descriptive string representation of ``self``.
|
| This method can be used with no arguments as a debugging
| utility.
|
| This function is also used internally in the ``__str__`` method
| of ``Graph``. Together, the strings in ``placeholder_names``
| and ``maybe_return_typename`` make up the signature of the
| autogenerated ``forward`` function in this Graph's surrounding
| GraphModule. ``placeholder_names`` and ``maybe_return_typename``
| should not be used otherwise.
|
| Args:
| placeholder_names: A list that will store formatted strings
| representing the placeholders in the generated
| ``forward`` function. Internal use only.
| maybe_return_typename: A single-element list that will store
| a formatted string representing the output of the
| generated ``forward`` function. Internal use only.
| include_tensor_metadata: Whether to include tensor metadata
|
| Returns:
| str: If 1) we're using ``format_node`` as an internal helper
| in the ``__str__`` method of ``Graph``, and 2) ``self``
| is a placeholder Node, return ``None``. Otherwise,
| return a descriptive string representation of the
| current Node.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| insert_arg(self, idx: int, arg: Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType]) -> None
| Insert a positional argument to the argument list with given index.
|
| Args:
|
| idx (int): The index of the element in ``self.args`` to be inserted before.
| arg (Argument): The new argument value to insert into ``args``
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| is_impure(self, impure_random: bool = True) -> bool
| Returns whether this op is impure, i.e. if its op is a placeholder or
| output, or if a call_function or call_module which is impure.
|
| Args:
| impure_random (bool): Whether to treat rand op as impure.
|
| Returns:
|
| bool: If the op is impure or not.
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| normalized_arguments(self, root: torch.nn.modules.module.Module, arg_types: tuple[typing.Any] | None = None, kwarg_types: dict[str, typing.Any] | None = None, normalize_to_only_use_kwargs: bool = False) -> torch.fx.operator_schemas.ArgsKwargsPair | None
| Returns normalized arguments to Python targets. This means that
| `args/kwargs` will be matched up to the module/functional's
| signature and return exclusively kwargs in positional order
| if `normalize_to_only_use_kwargs` is true.
| Also populates default values. Does not support positional-only
| parameters or varargs parameters.
|
| Supports module calls.
|
| May require `arg_types` and `kwarg_types` in order to disambiguate overloads.
|
| Args:
| root (torch.nn.Module): Module upon which to resolve module targets.
| arg_types (Optional[Tuple[Any]]): Tuple of arg types for the args
| kwarg_types (Optional[Dict[str, Any]]): Dict of arg types for the kwargs
| normalize_to_only_use_kwargs (bool): Whether to normalize to only use kwargs.
|
| Returns:
|
| Returns NamedTuple ArgsKwargsPair, or `None` if not successful.
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| prepend(self, x: 'Node') -> None
| Insert x before this node in the list of nodes in the graph. Example::
|
| Before: p -> self
| bx -> x -> ax
| After: p -> x -> self
| bx -> ax
|
| Args:
| x (Node): The node to put before this node. Must be a member of the same graph.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| replace_all_uses_with(self, replace_with: 'Node', delete_user_cb: collections.abc.Callable[['Node'], bool] | None = None, *, propagate_meta: bool = False) -> list['Node']
| Replace all uses of ``self`` in the Graph with the Node ``replace_with``.
|
| Args:
|
| replace_with (Node): The node to replace all uses of ``self`` with.
| delete_user_cb (Callable): Callback that is called to determine
| whether a given user of the self node should be removed.
| propagate_meta (bool): Whether or not to copy all properties
| on the .meta field of the original node onto the replacement node.
| For safety, this is only valid to do if the replacement node
| doesn't already have an existing .meta field.
|
| Returns:
|
| The list of Nodes on which this change was made.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| replace_input_with(self, old_input: 'Node', new_input: 'Node') -> None
| Loop through input nodes of ``self``, and replace all instances of
| ``old_input`` with ``new_input``.
|
| Args:
|
| old_input (Node): The old input node to be replaced.
| new_input (Node): The new input node to replace ``old_input``.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| update_arg(self, idx: int, arg: Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType]) -> None
| Update an existing positional argument to contain the new value
| ``arg``. After calling, ``self.args[idx] == arg``.
|
| Args:
|
| idx (int): The index into ``self.args`` of the element to update
| arg (Argument): The new argument value to write into ``args``
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| update_kwarg(self, key: str, arg: Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType]) -> None
| Update an existing keyword argument to contain the new value
| ``arg``. After calling, ``self.kwargs[key] == arg``.
|
| Args:
|
| key (str): The key in ``self.kwargs`` of the element to update
| arg (Argument): The new argument value to write into ``kwargs``
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| all_input_nodes
| Return all Nodes that are inputs to this Node. This is equivalent to
| iterating over ``args`` and ``kwargs`` and only collecting the values that
| are Nodes.
|
| Returns:
|
| List of ``Nodes`` that appear in the ``args`` and ``kwargs`` of this
| ``Node``, in that order.
|
| next
| Returns the next ``Node`` in the linked list of Nodes.
|
| Returns:
|
| The next ``Node`` in the linked list of Nodes.
|
| prev
| Returns the previous ``Node`` in the linked list of Nodes.
|
| Returns:
|
| The previous ``Node`` in the linked list of Nodes.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| args
| The tuple of arguments to this ``Node``. The interpretation of arguments
| depends on the node's opcode. See the :class:`Node` docstring for more
| information.
|
| Assignment to this property is allowed. All accounting of uses and users
| is updated automatically on assignment.
|
| kwargs
| The dict of keyword arguments to this ``Node``. The interpretation of arguments
| depends on the node's opcode. See the :class:`Node` docstring for more
| information.
|
| Assignment to this property is allowed. All accounting of uses and users
| is updated automatically on assignment.
|
| stack_trace
| Return the Python stack trace that was recorded during tracing, if any.
| When traced with fx.Tracer, this property is usually populated by
| `Tracer.create_proxy`. To record stack traces during tracing for debug purposes,
| set `record_stack_traces = True` on the `Tracer` instance.
| When traced with dynamo, this property will be populated by default by
| `OutputGraph.create_proxy`.
|
| stack_trace would have the innermost frame at the end of the string.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'_args': tuple['Argument', ...], '_input_nodes': di...
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C._NodeBase:
|
| __ge__(...)
| Return True if self.sort_key >= other.sort_key
|
| __gt__(...)
| Return True if self.sort_key > other.sort_key
|
| __le__(...)
| Return True if self.sort_key <= other.sort_key
|
| __lt__(...)
| Return True if self.sort_key < other.sort_key
|
| ----------------------------------------------------------------------
| Static methods inherited from torch._C._NodeBase:
|
| __new__(*args, **kwargs) class method of torch._C._NodeBase
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C._NodeBase:
|
| graph
|
| meta
|
| name
|
| op
|
| target
|
| type
|
| users
class Proxy(builtins.object)
| Proxy(node: torch.fx.node.Node, tracer: 'TracerBase | None' = None) -> None
|
| ``Proxy`` objects are ``Node`` wrappers that flow through the
| program during symbolic tracing and record all the operations
| (``torch`` function calls, method calls, operators) that they touch
| into the growing FX Graph.
|
| If you're doing graph transforms, you can wrap your own ``Proxy``
| method around a raw ``Node`` so that you can use the overloaded
| operators to add additional things to a ``Graph``.
|
| ``Proxy`` objects cannot be iterated. In other words, the symbolic
| tracer will throw an error if a ``Proxy`` is used in a loop or as
| an ``*args``/``**kwargs`` function argument.
|
| There are two main ways around this:
| 1. Factor out the untraceable logic into a top-level function and
| use ``fx.wrap`` on it.
| 2. If the control flow is static (i.e. the loop trip count is
| based on some hyperparameter), the code can be kept in its original
| position and refactored into something like::
|
| for i in range(self.some_hyperparameter):
| indexed_item = proxied_value[i]
|
| For a more detailed description into the Proxy internals, check out
| the "Proxy" section in `torch/fx/README.md`
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| Methods defined here:
|
| __abs__(self) -> 'Proxy'
|
| __add__ = add(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __and__ = and_(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __bool__(self) -> bool
|
| __call__(self, *args: Any, **kwargs: Any) -> 'Proxy'
| Call self as a function.
|
| __deepcopy__(self, memo: dict[int, typing.Any]) -> 'Proxy'
|
| __div__ = div(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __eq__ = eq(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __floordiv__ = floordiv(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __ge__ = ge(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __getattr__(self, k: str) -> 'Attribute'
|
| __getitem__ = getitem(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __gt__ = gt(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __init__(self, node: torch.fx.node.Node, tracer: 'TracerBase | None' = None) -> None
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| __invert__ = invert(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __iter__(self) -> collections.abc.Iterator['Proxy']
|
| __le__ = le(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __len__(self) -> int
|
| __lshift__ = lshift(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __lt__ = lt(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __matmul__ = matmul(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __mod__ = mod(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __mul__ = mul(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __ne__ = ne(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __neg__ = neg(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __or__ = or_(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __pos__ = pos(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __pow__ = pow(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __radd__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __rand__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __rdiv__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __repr__(self) -> str
| Return repr(self).
|
| __rfloordiv__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __rgetitem__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __rlshift__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __rmatmul__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __rmod__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __rmul__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __ror__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __rpow__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __rrshift__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __rshift__ = rshift(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __rsub__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __rtruediv__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __rxor__(self: 'Proxy', rhs: Any) -> 'Proxy' from torch.fx.proxy
|
| __setstate__(self, d: dict[str, typing.Any]) -> None
|
| __sub__ = sub(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __truediv__ = truediv(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| __xor__ = xor(*args: Any, **kwargs: Any) -> 'Proxy' from torch.fx.proxy._scope.<locals>
|
| keys(self) -> 'Proxy'
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(orig_method: collections.abc.Callable[..., typing.Any], types: tuple[type, ...], args: tuple[typing.Any, ...] | None = None, kwargs: dict[str, typing.Any] | None = None) -> 'Proxy'
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Tracer(torch.fx.proxy.TracerBase)
| Tracer(autowrap_modules: tuple[module] = (<module 'math' (built-in)>,), autowrap_functions: tuple[collections.abc.Callable[..., typing.Any], ...] = (), param_shapes_constant: bool = False) -> None
|
| Tracer(autowrap_modules=(math,), autowrap_functions=())
|
| ``Tracer`` is the class that implements the symbolic tracing functionality
| of ``torch.fx.symbolic_trace``. A call to ``symbolic_trace(m)`` is equivalent
| to ``Tracer().trace(m)``.
|
| Tracer can be subclassed to override various behaviors of the tracing
| process. The different behaviors that can be overridden are described
| in the docstrings of the methods on this class.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| Method resolution order:
| Tracer
| torch.fx.proxy.TracerBase
| builtins.object
|
| Methods defined here:
|
| __deepcopy__(self, memo: dict[int, typing.Any]) -> 'Tracer'
|
| __init__(self, autowrap_modules: tuple[module] = (<module 'math' (built-in)>,), autowrap_functions: tuple[collections.abc.Callable[..., typing.Any], ...] = (), param_shapes_constant: bool = False) -> None
| Construct a Tracer object.
|
| Args:
|
| autowrap_modules (Tuple[ModuleType]): defaults to `(math, )`,
| Python modules whose functions should be wrapped automatically
| without needing to use fx.wrap(). Backward-compatibility for
| this parameter is guaranteed.
|
| autowrap_functions (Tuple[Callable, ...]): defaults to `()`,
| Python functions that should be wrapped automatically without
| needing to use fx.wrap(). Backward compatibility for this
| parameter is guaranteed.
|
| param_shapes_constant (bool): When this flag is set, calls to shape,
| size and a few other shape like attributes of a module's parameter
| will be evaluated directly, rather than returning a new Proxy value
| for an attribute access. Backward compatibility for this parameter
| is guaranteed.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| call_module(self, m: torch.nn.modules.module.Module, forward: collections.abc.Callable[..., typing.Any], args: tuple[typing.Any, ...], kwargs: dict[str, typing.Any]) -> Any
| Method that specifies the behavior of this ``Tracer`` when it encounters
| a call to an ``nn.Module`` instance.
|
| By default, the behavior is to check if the called module is a leaf module
| via ``is_leaf_module``. If it is, emit a ``call_module`` node referring to
| ``m`` in the ``Graph``. Otherwise, call the ``Module`` normally, tracing through
| the operations in its ``forward`` function.
|
| This method can be overridden to--for example--create nested traced
| GraphModules, or any other behavior you would want while tracing across
| ``Module`` boundaries.
|
| Args:
|
| m (Module): The module for which a call is being emitted
| forward (Callable): The forward() method of the ``Module`` to be invoked
| args (Tuple): args of the module callsite
| kwargs (Dict): kwargs of the module callsite
|
| Return:
|
| The return value from the Module call. In the case that a ``call_module``
| node was emitted, this is a ``Proxy`` value. Otherwise, it is whatever
| value was returned from the ``Module`` invocation.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| create_arg(self, a: Any) -> 'Argument'
| A method to specify the behavior of tracing when preparing values to
| be used as arguments to nodes in the ``Graph``.
|
| By default, the behavior includes:
|
| #. Iterate through collection types (e.g. tuple, list, dict) and recursively
| call ``create_args`` on the elements.
| #. Given a Proxy object, return a reference to the underlying IR ``Node``
| #. Given a non-Proxy Tensor object, emit IR for various cases:
|
| * For a Parameter, emit a ``get_attr`` node referring to that Parameter
| * For a non-Parameter Tensor, store the Tensor away in a special
| attribute referring to that attribute.
|
| This method can be overridden to support more types.
|
| Args:
|
| a (Any): The value to be emitted as an ``Argument`` in the ``Graph``.
|
|
| Returns:
|
| The value ``a`` converted into the appropriate ``Argument``
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| create_args_for_root(self, root_fn: collections.abc.Callable[..., typing.Any], is_module: bool, concrete_args: dict[str, typing.Any] | tuple[typing.Any, ...] | None = None) -> tuple[typing.Any, list[typing.Any]]
| Create ``placeholder`` nodes corresponding to the signature of the ``root``
| Module. This method introspects root's signature and emits those
| nodes accordingly, also supporting ``*args`` and ``**kwargs``.
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| get_fresh_qualname(self, prefix: str) -> str
| Gets a fresh name for a prefix and returns it. This function ensures
| that it will not clash with an existing attribute on the graph.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| getattr(self, attr: str, attr_val: Any, parameter_proxy_cache: dict[str, torch.fx.proxy.Proxy]) -> Any
| Method that specifies the behavior of this ``Tracer`` when we call getattr
| on a call to an ``nn.Module`` instance.
|
| By default, the behavior is to return a proxy value for the attribute. It
| also stores the proxy value in the ``parameter_proxy_cache``, so that future
| calls will reuse the proxy rather than creating a new one.
|
| This method can be overridden to --for example-- not return proxies when
| querying parameters.
|
| Args:
|
| attr (str): The name of the attribute being queried
| attr_val (Any): The value of the attribute
| parameter_proxy_cache (Dict[str, Any]): A cache of attr names to proxies
|
| Return:
|
| The return value from the getattr call.
|
|
| .. warning::
| This API is experimental and is *NOT* backward-compatible.
|
| is_leaf_module(self, m: torch.nn.modules.module.Module, module_qualified_name: str) -> bool
| A method to specify whether a given ``nn.Module`` is a "leaf" module.
|
| Leaf modules are the atomic units that appear in
| the IR, referenced by ``call_module`` calls. By default,
| Modules in the PyTorch standard library namespace (torch.nn)
| are leaf modules. All other modules are traced through and
| their constituent ops are recorded, unless specified otherwise
| via this parameter.
|
| Args:
|
| m (Module): The module being queried about
| module_qualified_name (str): The path to root of this module. For example,
| if you have a module hierarchy where submodule ``foo`` contains
| submodule ``bar``, which contains submodule ``baz``, that module will
| appear with the qualified name ``foo.bar.baz`` here.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| path_of_module(self, mod: torch.nn.modules.module.Module) -> str
| Helper method to find the qualified name of ``mod`` in the Module hierarchy
| of ``root``. For example, if ``root`` has a submodule named ``foo``, which has
| a submodule named ``bar``, passing ``bar`` into this function will return
| the string "foo.bar".
|
| Args:
|
| mod (str): The ``Module`` to retrieve the qualified name for.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| trace(self, root: torch.nn.modules.module.Module | collections.abc.Callable[..., typing.Any], concrete_args: dict[str, typing.Any] | None = None) -> torch.fx.graph.Graph
| Trace ``root`` and return the corresponding FX ``Graph`` representation. ``root``
| can either be an ``nn.Module`` instance or a Python callable.
|
| Note that after this call, ``self.root`` may be different from the ``root`` passed
| in here. For example, when a free function is passed to ``trace()``, we will
| create an ``nn.Module`` instance to use as the root and add embedded constants
| to.
|
|
| Args:
|
| root (Union[Module, Callable]): Either a ``Module`` or a function to be
| traced through. Backwards-compatibility for this parameter is
| guaranteed.
| concrete_args (Optional[Dict[str, any]]): Concrete arguments that should
| not be treated as Proxies. This parameter is experimental and
| its backwards-compatibility is *NOT* guaranteed.
|
| Returns:
|
| A ``Graph`` representing the semantics of the passed-in ``root``.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'_qualname_counter': dict[str, int]}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.fx.proxy.TracerBase:
|
| create_node(self, kind: str, target: collections.abc.Callable[..., typing.Any] | str, args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType]], name: str | None = None, type_expr: typing.Any | None = None) -> torch.fx.node.Node
| Inserts a graph node given target, args, kwargs, and name.
|
| This method can be overridden to do extra checking, validation, or
| modification of values used in node creation. For example, one might
| want to disallow in-place operations from being recorded.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| create_proxy(self, kind: str, target: collections.abc.Callable[..., typing.Any] | str, args: tuple[typing.Any, ...], kwargs: dict[str, typing.Any], name: str | None = None, type_expr: typing.Any | None = None, proxy_factory_fn: collections.abc.Callable[[torch.fx.node.Node], 'Proxy'] | None = None) -> 'Proxy'
| Create a Node from the given arguments, then return the Node
| wrapped in a Proxy object.
|
| If kind = 'placeholder', then we're creating a Node that
| represents the parameter of a function. If we need to encode
| a default parameter, we use the ``args`` tuple. ``args`` is
| otherwise empty for ``placeholder`` Nodes.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| iter(self, obj: 'Proxy') -> collections.abc.Iterator
| Called when a proxy object is being iterated over, such as
| when used in control flow. Normally we don't know what to do because
| we don't know the value of the proxy, but a custom tracer can attach more
| information to the graph node using create_node and can choose to return an iterator.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| keys(self, obj: 'Proxy') -> 'Proxy'
| Called when a proxy object is has the keys() method called.
| This is what happens when ** is called on a proxy. This should return an
| iterator it ** is suppose to work in your custom tracer.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| proxy(self, node: torch.fx.node.Node) -> 'Proxy'
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| to_bool(self, obj: 'Proxy') -> bool
| Called when a proxy object is being converted to a boolean, such as
| when used in control flow. Normally we don't know what to do because
| we don't know the value of the proxy, but a custom tracer can attach more
| information to the graph node using create_node and can choose to return a value.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.fx.proxy.TracerBase:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.fx.proxy.TracerBase:
|
| check_mutable_operations = False
|
| proxy_buffer_attributes = False
|
| record_stack_traces = False
|
| trace_asserts = False
|
| traced_func_name = 'forward'
class Transformer(Interpreter)
| Transformer(module: torch.fx.graph_module.GraphModule) -> None
|
| ``Transformer`` is a special type of interpreter that produces a
| new ``Module``. It exposes a ``transform()`` method that returns
| the transformed ``Module``. ``Transformer`` does not require
| arguments to run, as ``Interpreter`` does. ``Transformer`` works
| entirely symbolically.
|
| Example:
|
| Suppose we want to swap all instances of ``torch.neg`` with
| ``torch.sigmoid`` and vice versa (including their ``Tensor``
| method equivalents). We could subclass ``Transformer`` like so::
|
| class NegSigmSwapXformer(Transformer):
| def call_function(
| self,
| target: "Target",
| args: Tuple[Argument, ...],
| kwargs: Dict[str, Any],
| ) -> Any:
| if target is torch.sigmoid:
| return torch.neg(*args, **kwargs)
| return super().call_function(target, args, kwargs)
|
| def call_method(
| self,
| target: "Target",
| args: Tuple[Argument, ...],
| kwargs: Dict[str, Any],
| ) -> Any:
| if target == "neg":
| call_self, *args_tail = args
| return call_self.sigmoid(*args_tail, **kwargs)
| return super().call_method(target, args, kwargs)
|
|
| def fn(x):
| return torch.sigmoid(x).neg()
|
|
| gm = torch.fx.symbolic_trace(fn)
|
| transformed: torch.nn.Module = NegSigmSwapXformer(gm).transform()
| input = torch.randn(3, 4)
| torch.testing.assert_close(transformed(input), torch.neg(input).sigmoid())
|
| Args:
| module (GraphModule): The ``Module`` to be transformed.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| Method resolution order:
| Transformer
| Interpreter
| builtins.object
|
| Methods defined here:
|
| __init__(self, module: torch.fx.graph_module.GraphModule) -> None
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| call_function(self, target: 'Target', args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Any]) -> Any
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| call_module(self, target: 'Target', args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Any]) -> Any
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| get_attr(self, target: 'Target', args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Any]) -> torch.fx.proxy.Proxy
| Execute a ``get_attr`` node. In ``Transformer``, this is
| overridden to insert a new ``get_attr`` node into the output
| graph.
|
| Args:
| target (Target): The call target for this node. See
| `Node <https://pytorch.org/docs/main/fx.html#torch.fx.Node>`__ for
| details on semantics
| args (Tuple): Tuple of positional args for this invocation
| kwargs (Dict): Dict of keyword arguments for this invocation
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| placeholder(self, target: 'Target', args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Any]) -> torch.fx.proxy.Proxy
| Execute a ``placeholder`` node. In ``Transformer``, this is
| overridden to insert a new ``placeholder`` into the output
| graph.
|
| Args:
| target (Target): The call target for this node. See
| `Node <https://pytorch.org/docs/main/fx.html#torch.fx.Node>`__ for
| details on semantics
| args (Tuple): Tuple of positional args for this invocation
| kwargs (Dict): Dict of keyword arguments for this invocation
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| transform(self) -> torch.fx.graph_module.GraphModule
| Transform ``self.module`` and return the transformed
| ``GraphModule``.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| ----------------------------------------------------------------------
| Methods inherited from Interpreter:
|
| boxed_run(self, args_list: list[typing.Any]) -> Any
| Run `module` via interpretation and return the result. This uses the "boxed"
| calling convention, where you pass a list of arguments, which will be cleared
| by the interpreter. This ensures that input tensors are promptly deallocated.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| call_method(self, target: 'Target', args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Any]) -> Any
| Execute a ``call_method`` node and return the result.
|
| Args:
| target (Target): The call target for this node. See
| `Node <https://pytorch.org/docs/main/fx.html#torch.fx.Node>`__ for
| details on semantics
| args (Tuple): Tuple of positional args for this invocation
| kwargs (Dict): Dict of keyword arguments for this invocation
|
| Return
| Any: The value returned by the method invocation
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| fetch_args_kwargs_from_env(self, n: torch.fx.node.Node) -> tuple[tuple[typing.Any, ...], dict[str, typing.Any]]
| Fetch the concrete values of ``args`` and ``kwargs`` of node ``n``
| from the current execution environment.
|
| Args:
| n (Node): The node for which ``args`` and ``kwargs`` should be fetched.
|
| Return:
| Tuple[Tuple, Dict]: ``args`` and ``kwargs`` with concrete values for ``n``.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| fetch_attr(self, target: str) -> Any
| Fetch an attribute from the ``Module`` hierarchy of ``self.module``.
|
| Args:
| target (str): The fully-qualified name of the attribute to fetch
|
| Return:
| Any: The value of the attribute.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| map_nodes_to_values(self, args: Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], n: torch.fx.node.Node) -> Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType]
| Recursively descend through ``args`` and look up the concrete value
| for each ``Node`` in the current execution environment.
|
| Args:
| args (Argument): Data structure within which to look up concrete values
|
| n (Node): Node to which ``args`` belongs. This is only used for error reporting.
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| output(self, target: 'Target', args: tuple[typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType], ...], kwargs: dict[str, typing.Any]) -> Any
| Execute an ``output`` node. This really just retrieves
| the value referenced by the ``output`` node and returns it.
|
| Args:
| target (Target): The call target for this node. See
| `Node <https://pytorch.org/docs/main/fx.html#torch.fx.Node>`__ for
| details on semantics
| args (Tuple): Tuple of positional args for this invocation
| kwargs (Dict): Dict of keyword arguments for this invocation
|
| Return:
| Any: The return value referenced by the output node
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| run(self, *args: Any, initial_env: dict[torch.fx.node.Node, typing.Any] | None = None, enable_io_processing: bool = True) -> Any
| Run `module` via interpretation and return the result.
|
| Args:
| *args: The arguments to the Module to run, in positional order
| initial_env (Optional[Dict[Node, Any]]): An optional starting environment for execution.
| This is a dict mapping `Node` to any value. This can be used, for example, to
| pre-populate results for certain `Nodes` so as to do only partial evaluation within
| the interpreter.
| enable_io_processing (bool): If true, we process the inputs and outputs with graph's process_inputs and
| process_outputs function first before using them.
|
| Returns:
| Any: The value returned from executing the Module
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| run_node(self, n: torch.fx.node.Node) -> Any
| Run a specific node ``n`` and return the result.
| Calls into placeholder, get_attr, call_function,
| call_method, call_module, or output depending
| on ``node.op``
|
| Args:
| n (Node): The Node to execute
|
| Returns:
| Any: The result of executing ``n``
|
|
| .. note::
| Backwards-compatibility for this API is guaranteed.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Interpreter:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
has_side_effect(fn: collections.abc.Callable[~_P, ~_R]) -> collections.abc.Callable[~_P, ~_R]
Registers a function to not be dead code eliminated by
fx.graph.eliminate_dead_code
NOTE: For new operators, please do not add to this set!
Instead, consider using the effects system via
torch.library._register_effectful_op() for operators.
This _side_effectful_functions set is only for:
- Legacy functions that aren't operators (e.g., profiler ops, asserts)
- Things that cannot be marked via the normal effects system
.. warning::
This API is experimental and is *NOT* backward-compatible.
map_arg(a: ~ArgumentT, fn: collections.abc.Callable[[torch.fx.node.Node], typing.Union[tuple['Argument', ...], collections.abc.Sequence['Argument'], collections.abc.Mapping[str, 'Argument'], slice, range, ForwardRef('Node'), str, int, float, bool, complex, torch.dtype, torch.Tensor, torch.device, torch.memory_format, torch.layout, torch._ops.OpOverload, torch.SymInt, torch.SymBool, torch.SymFloat, NoneType]]) -> ~ArgumentT
Apply fn recursively to each Node appearing in arg.
arg may be a list, tuple, slice, or dict with string keys: the return value will
have the same type and structure.
.. note::
Backwards-compatibility for this API is guaranteed.
replace_pattern(gm: torch.fx.graph_module.GraphModule, pattern: collections.abc.Callable[..., typing.Any] | torch.fx.graph_module.GraphModule, replacement: collections.abc.Callable[..., typing.Any] | torch.fx.graph_module.GraphModule) -> list[torch.fx.subgraph_rewriter.Match]
Matches all possible non-overlapping sets of operators and their
data dependencies (``pattern``) in the Graph of a GraphModule
(``gm``), then replaces each of these matched subgraphs with another
subgraph (``replacement``).
Args:
``gm``: The GraphModule that wraps the Graph to operate on
``pattern``: The subgraph to match in ``gm`` for replacement
``replacement``: The subgraph to replace ``pattern`` with
Returns:
List[Match]: A list of ``Match`` objects representing the places
in the original graph that ``pattern`` was matched to. The list
is empty if there are no matches. ``Match`` is defined as:
.. code-block:: python
class Match(NamedTuple):
# Node from which the match was found
anchor: Node
# Maps nodes in the pattern subgraph to nodes in the larger graph
nodes_map: Dict[Node, Node]
Examples:
.. code-block:: python
import torch
from torch.fx import symbolic_trace, subgraph_rewriter
class M(torch.nn.Module):
def __init__(self) -> None:
super().__init__()
def forward(self, x, w1, w2):
m1 = torch.cat([w1, w2]).sum()
m2 = torch.cat([w1, w2]).sum()
return x + torch.max(m1) + torch.max(m2)
def pattern(w1, w2):
return torch.cat([w1, w2])
def replacement(w1, w2):
return torch.stack([w1, w2])
traced_module = symbolic_trace(M())
subgraph_rewriter.replace_pattern(traced_module, pattern, replacement)
The above code will first match ``pattern`` in the ``forward``
method of ``traced_module``. Pattern-matching is done based on
use-def relationships, not node names. For example, if you had
``p = torch.cat([a, b])`` in ``pattern``, you could match
``m = torch.cat([a, b])`` in the original ``forward`` function,
despite the variable names being different (``p`` vs ``m``).
The ``return`` statement in ``pattern`` is matched based on its
value only; it may or may not match to the ``return`` statement in
the larger graph. In other words, the pattern doesn't have to extend
to the end of the larger graph.
When the pattern is matched, it will be removed from the larger
function and replaced by ``replacement``. If there are multiple
matches for ``pattern`` in the larger function, each non-overlapping
match will be replaced. In the case of a match overlap, the first
found match in the set of overlapping matches will be replaced.
("First" here being defined as the first in a topological ordering
of the Nodes' use-def relationships. In most cases, the first Node
is the parameter that appears directly after ``self``, while the
last Node is whatever the function returns.)
One important thing to note is that the parameters of the
``pattern`` Callable must be used in the Callable itself,
and the parameters of the ``replacement`` Callable must match
the pattern. The first rule is why, in the above code block, the
``forward`` function has parameters ``x, w1, w2``, but the
``pattern`` function only has parameters ``w1, w2``. ``pattern``
doesn't use ``x``, so it shouldn't specify ``x`` as a parameter.
As an example of the second rule, consider replacing
.. code-block:: python
def pattern(x, y):
return torch.neg(x) + torch.relu(y)
with
.. code-block:: python
def replacement(x, y):
return torch.relu(x)
In this case, ``replacement`` needs the same number of parameters
as ``pattern`` (both ``x`` and ``y``), even though the parameter
``y`` isn't used in ``replacement``.
After calling ``subgraph_rewriter.replace_pattern``, the generated
Python code looks like this:
.. code-block:: python
def forward(self, x, w1, w2):
stack_1 = torch.stack([w1, w2])
sum_1 = stack_1.sum()
stack_2 = torch.stack([w1, w2])
sum_2 = stack_2.sum()
max_1 = torch.max(sum_1)
add_1 = x + max_1
max_2 = torch.max(sum_2)
add_2 = add_1 + max_2
return add_2
.. note::
Backwards-compatibility for this API is guaranteed.
symbolic_trace(root: torch.nn.modules.module.Module | collections.abc.Callable[..., typing.Any], concrete_args: dict[str, typing.Any] | None = None) -> torch.fx.graph_module.GraphModule
Symbolic tracing API
Given an ``nn.Module`` or function instance ``root``, this function will return a ``GraphModule``
constructed by recording operations seen while tracing through ``root``.
``concrete_args`` allows you to partially specialize your function, whether it's to remove control flow or data structures.
For example::
def f(a, b):
if b == True:
return a
else:
return a * 2
FX can typically not trace through this due to the presence of control
flow. However, we can use `concrete_args` to specialize on the value of
`b` to trace through this::
f = fx.symbolic_trace(f, concrete_args={"b": False})
assert f(3, False) == 6
Note that although you can still pass in different values of `b`, they will be ignored.
We can also use `concrete_args` to eliminate data-structure handling from
our function. This will use pytrees to flatten your input. To avoid
overspecializing, pass in `fx.PH` for values that shouldn't be
specialized. For example::
def f(x):
out = 0
for v in x.values():
out += v
return out
f = fx.symbolic_trace(
f, concrete_args={"x": {"a": fx.PH, "b": fx.PH, "c": fx.PH}}
)
assert f({"a": 1, "b": 2, "c": 4}) == 7
Args:
root (Union[torch.nn.Module, Callable]): Module or function to be traced and converted
into a Graph representation.
concrete_args (Optional[Dict[str, any]]): Inputs to be partially specialized
Returns:
GraphModule: a Module created from the recorded operations from ``root``.
.. note::
Backwards-compatibility for this API is guaranteed.
wrap(fn_or_name: str | collections.abc.Callable[..., typing.Any]) -> str | collections.abc.Callable[..., typing.Any]
This function can be called at module-level scope to register fn_or_name as a "leaf function".
A "leaf function" will be preserved as a CallFunction node in the FX trace instead of being
traced through::
# foo/bar/baz.py
def my_custom_function(x, y):
return x * x + y * y
torch.fx.wrap("my_custom_function")
def fn_to_be_traced(x, y):
# When symbolic tracing, the below call to my_custom_function will be inserted into
# the graph rather than tracing it.
return my_custom_function(x, y)
This function can also equivalently be used as a decorator::
# foo/bar/baz.py
@torch.fx.wrap
def my_custom_function(x, y):
return x * x + y * y
A wrapped function can be thought of a "leaf function", analogous to the concept of
"leaf modules", that is, they are functions that are left as calls in the FX trace
rather than traced through.
Args:
fn_or_name (Union[str, Callable]): The function or name of the global function to insert into the
graph when it's called
.. note::
Backwards-compatibility for this API is guaranteed.
DATA
__all__ = ['symbolic_trace', 'Tracer', 'wrap', 'Graph', 'GraphModule',...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\fx\__init__.py
torch.gather
Python Library Documentation: built-in function gather in module torch
gather(...)
gather(input, dim, index, *, sparse_grad=False, out=None) -> Tensor
Gathers values along an axis specified by `dim`.
For a 3-D tensor the output is specified by::
out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0
out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1
out[i][j][k] = input[i][j][index[i][j][k]] # if dim == 2
:attr:`input` and :attr:`index` must have the same number of dimensions.
It is also required that ``index.size(d) <= input.size(d)`` for all
dimensions ``d != dim``. :attr:`out` will have the same shape as :attr:`index`.
Note that ``input`` and ``index`` do not broadcast against each other.
When :attr:`index` is empty, we always return an empty output with the same shape
without further error checking.
Args:
input (Tensor): the source tensor
dim (int): the axis along which to index
index (LongTensor): the indices of elements to gather
Keyword arguments:
sparse_grad (bool, optional): If ``True``, gradient w.r.t. :attr:`input` will be a sparse tensor.
out (Tensor, optional): the destination tensor
Example::
>>> t = torch.tensor([[1, 2], [3, 4]])
>>> torch.gather(t, 1, torch.tensor([[0, 0], [1, 0]]))
tensor([[ 1, 1],
[ 4, 3]])
torch.gcd
Python Library Documentation: built-in function gcd in module torch
gcd(...)
gcd(input, other, *, out=None) -> Tensor
Computes the element-wise greatest common divisor (GCD) of :attr:`input` and :attr:`other`.
Both :attr:`input` and :attr:`other` must have integer types.
.. note::
This defines :math:`gcd(0, 0) = 0`.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([5, 10, 15])
>>> b = torch.tensor([3, 4, 5])
>>> torch.gcd(a, b)
tensor([1, 2, 5])
>>> c = torch.tensor([3])
>>> torch.gcd(a, c)
tensor([1, 1, 3])
torch.gcd_
Python Library Documentation: built-in function gcd_ in module torch gcd_(...)
torch.ge
Python Library Documentation: built-in function ge in module torch
ge(...)
ge(input, other, *, out=None) -> Tensor
Computes :math:`\text{input} \geq \text{other}` element-wise.
The second argument can be a number or a tensor whose shape is
:ref:`broadcastable <broadcasting-semantics>` with the first argument.
Args:
input (Tensor): the tensor to compare
other (Tensor or float): the tensor or value to compare
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
A boolean tensor that is True where :attr:`input` is greater than or equal to :attr:`other` and False elsewhere
Example::
>>> torch.ge(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[True, True], [False, True]])
torch.geqrf
Python Library Documentation: built-in function geqrf in module torch
geqrf(...)
geqrf(input, *, out=None) -> (Tensor, Tensor)
This is a low-level function for calling LAPACK's geqrf directly. This function
returns a namedtuple (a, tau) as defined in `LAPACK documentation for geqrf`_ .
Computes a QR decomposition of :attr:`input`.
Both `Q` and `R` matrices are stored in the same output tensor `a`.
The elements of `R` are stored on and above the diagonal.
Elementary reflectors (or Householder vectors) implicitly defining matrix `Q`
are stored below the diagonal.
The results of this function can be used together with :func:`torch.linalg.householder_product`
to obtain the `Q` matrix or
with :func:`torch.ormqr`, which uses an implicit representation of the `Q` matrix,
for an efficient matrix-matrix multiplication.
See `LAPACK documentation for geqrf`_ for further details.
.. note::
See also :func:`torch.linalg.qr`, which computes Q and R matrices, and :func:`torch.linalg.lstsq`
with the ``driver="gels"`` option for a function that can solve matrix equations using a QR decomposition.
Args:
input (Tensor): the input matrix
Keyword args:
out (tuple, optional): the output tuple of (Tensor, Tensor). Ignored if `None`. Default: `None`.
.. _LAPACK documentation for geqrf:
http://www.netlib.org/lapack/explore-html/df/dc5/group__variants_g_ecomputational_ga3766ea903391b5cf9008132f7440ec7b.html
torch.ger
Python Library Documentation: built-in function ger in module torch
ger(...)
ger(input, vec2, *, out=None) -> Tensor
Alias of :func:`torch.outer`.
.. warning::
This function is deprecated and will be removed in a future PyTorch release.
Use :func:`torch.outer` instead.
torch.get_autocast_cpu_dtype
Python Library Documentation: built-in function get_autocast_cpu_dtype in module torch get_autocast_cpu_dtype(...)
torch.get_autocast_dtype
Python Library Documentation: built-in function get_autocast_dtype in module torch get_autocast_dtype(...)
torch.get_autocast_gpu_dtype
Python Library Documentation: built-in function get_autocast_gpu_dtype in module torch get_autocast_gpu_dtype(...)
torch.get_autocast_ipu_dtype
Python Library Documentation: built-in function get_autocast_ipu_dtype in module torch get_autocast_ipu_dtype(...)
torch.get_autocast_xla_dtype
Python Library Documentation: built-in function get_autocast_xla_dtype in module torch get_autocast_xla_dtype(...)
torch.get_default_device
Python Library Documentation: function get_default_device in module torch
get_default_device() -> 'torch.device'
Gets the default ``torch.Tensor`` to be allocated on ``device``
torch.get_default_dtype
Python Library Documentation: built-in function get_default_dtype in module torch
get_default_dtype(...)
get_default_dtype() -> torch.dtype
Get the current default floating point :class:`torch.dtype`.
Example::
>>> torch.get_default_dtype() # initial default for floating point is torch.float32
torch.float32
>>> torch.set_default_dtype(torch.float64)
>>> torch.get_default_dtype() # default is now changed to torch.float64
torch.float64
torch.get_deterministic_debug_mode
Python Library Documentation: function get_deterministic_debug_mode in module torch
get_deterministic_debug_mode() -> int
Returns the current value of the debug mode for deterministic
operations. Refer to :func:`torch.set_deterministic_debug_mode`
documentation for more details.
torch.get_device
Python Library Documentation: built-in function get_device in module torch get_device(...)
torch.get_device_module
Python Library Documentation: _lru_cache_wrapper in module torch
get_device_module(device: torch.device | str | None = None)
Returns the module associated with a given device(e.g., torch.device('cuda'), "mtia:0", "xpu", ...).
If no device is given, return the module for the current accelerator or CPU if none is present.
torch.get_file_path
Python Library Documentation: function get_file_path in module torch._utils_internal get_file_path(*path_components: str) -> str
torch.get_float32_matmul_precision
Python Library Documentation: function get_float32_matmul_precision in module torch
get_float32_matmul_precision() -> str
Returns the current value of float32 matrix multiplication precision. Refer to
:func:`torch.set_float32_matmul_precision` documentation for more details.
torch.get_num_interop_threads
Python Library Documentation: built-in function get_num_interop_threads in module torch
get_num_interop_threads(...)
get_num_interop_threads() -> int
Returns the number of threads used for inter-op parallelism on CPU
(e.g. in JIT interpreter)
torch.get_num_threads
Python Library Documentation: built-in function get_num_threads in module torch
get_num_threads(...)
get_num_threads() -> int
Returns the number of threads used for parallelizing CPU operations
torch.get_rng_state
Python Library Documentation: function get_rng_state in module torch.random
get_rng_state() -> torch.Tensor
Returns the random number generator state as a `torch.ByteTensor`.
.. note:: The returned state is for the default generator on CPU only.
See also: :func:`torch.random.fork_rng`.
torch.glob
Python Library Documentation: module glob
NAME
glob - Filename globbing utility.
MODULE REFERENCE
https://docs.python.org/3.12/library/glob.html
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
FUNCTIONS
escape(pathname)
Escape all special characters.
glob(pathname, *, root_dir=None, dir_fd=None, recursive=False, include_hidden=False)
Return a list of paths matching a pathname pattern.
The pattern may contain simple shell-style wildcards a la
fnmatch. Unlike fnmatch, filenames starting with a
dot are special cases that are not matched by '*' and '?'
patterns by default.
If `include_hidden` is true, the patterns '*', '?', '**' will match hidden
directories.
If `recursive` is true, the pattern '**' will match any files and
zero or more directories and subdirectories.
iglob(pathname, *, root_dir=None, dir_fd=None, recursive=False, include_hidden=False)
Return an iterator which yields the paths matching a pathname pattern.
The pattern may contain simple shell-style wildcards a la
fnmatch. However, unlike fnmatch, filenames starting with a
dot are special cases that are not matched by '*' and '?'
patterns.
If recursive is true, the pattern '**' will match any files and
zero or more directories and subdirectories.
DATA
__all__ = ['glob', 'iglob', 'escape']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\glob.py
torch.gradient
Python Library Documentation: built-in function gradient in module torch
gradient(...)
gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
one or more dimensions using the `second-order accurate central differences method
<https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
either first or second order estimates at the boundaries.
The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
:attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
:math:`g(1, 2, 3)\ == input[1, 2, 3]`.
When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
This is detailed in the "Keyword Arguments" section below.
The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
.. math::
\begin{aligned}
f(x+h_r) = f(x) + h_r f'(x) + {h_r}^2 \frac{f''(x)}{2} + {h_r}^3 \frac{f'''(\xi_1)}{6}, \xi_1 \in (x, x+h_r) \\
f(x-h_l) = f(x) - h_l f'(x) + {h_l}^2 \frac{f''(x)}{2} - {h_l}^3 \frac{f'''(\xi_2)}{6}, \xi_2 \in (x, x-h_l) \\
\end{aligned}
Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
.. math::
f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
+ ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
.. note::
We estimate the gradient of functions in complex domain
:math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
The value of each partial derivative at the boundary points is computed differently. See edge_order below.
Args:
input (``Tensor``): the tensor that represents the values of the function
Keyword args:
spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
the coordinates are (t0[1], t1[2], t2[3])
dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
the :attr:`spacing` argument must correspond with the specified dims."
edge_order (``int``, optional): 1 or 2, for `first-order
<https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
`second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
dimension size of :attr:`input` should be at least edge_order+1
Examples::
>>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
>>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
>>> values = torch.tensor([4., 1., 1., 16.], )
>>> torch.gradient(values, spacing = coordinates)
(tensor([-3., -2., 2., 5.]),)
>>> # Estimates the gradient of the R^2 -> R function whose samples are
>>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
>>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
>>> # partial derivative for both dimensions.
>>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
>>> torch.gradient(t)
(tensor([[ 9., 18., 36., 72.],
[ 9., 18., 36., 72.]]),
tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
[10.0000, 15.0000, 30.0000, 40.0000]]))
>>> # A scalar value for spacing modifies the relationship between tensor indices
>>> # and input coordinates by multiplying the indices to find the
>>> # coordinates. For example, below the indices of the innermost
>>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
>>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
>>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
(tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
[ 4.5000, 9.0000, 18.0000, 36.0000]]),
tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
[ 5.0000, 7.5000, 15.0000, 20.0000]]))
>>> # doubling the spacing between samples halves the estimated partial gradients.
>>>
>>> # Estimates only the partial derivative for dimension 1
>>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
(tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
[10.0000, 15.0000, 30.0000, 40.0000]]),)
>>> # When spacing is a list of scalars, the relationship between the tensor
>>> # indices and input coordinates changes based on dimension.
>>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
>>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
>>> # 0, 1 translate to coordinates of [0, 2].
>>> torch.gradient(t, spacing = [3., 2.])
(tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
[ 4.5000, 9.0000, 18.0000, 36.0000]]),
tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
[ 3.3333, 5.0000, 10.0000, 13.3333]]))
>>> # The following example is a replication of the previous one with explicit
>>> # coordinates.
>>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
>>> torch.gradient(t, spacing = coords)
(tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
[ 4.5000, 9.0000, 18.0000, 36.0000]]),
tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
[ 3.3333, 5.0000, 10.0000, 13.3333]]))
torch.greater
Python Library Documentation: built-in function greater in module torch
greater(...)
greater(input, other, *, out=None) -> Tensor
Alias for :func:`torch.gt`.
torch.greater_equal
Python Library Documentation: built-in function greater_equal in module torch
greater_equal(...)
greater_equal(input, other, *, out=None) -> Tensor
Alias for :func:`torch.ge`.
torch.grid_sampler
Python Library Documentation: built-in function grid_sampler in module torch grid_sampler(...)
torch.grid_sampler_2d
Python Library Documentation: built-in function grid_sampler_2d in module torch grid_sampler_2d(...)
torch.grid_sampler_3d
Python Library Documentation: built-in function grid_sampler_3d in module torch grid_sampler_3d(...)
torch.group_norm
Python Library Documentation: built-in function group_norm in module torch group_norm(...)
torch.gru
Python Library Documentation: built-in function gru in module torch gru(...)
torch.gru_cell
Python Library Documentation: built-in function gru_cell in module torch gru_cell(...)
torch.gt
Python Library Documentation: built-in function gt in module torch
gt(...)
gt(input, other, *, out=None) -> Tensor
Computes :math:`\text{input} > \text{other}` element-wise.
The second argument can be a number or a tensor whose shape is
:ref:`broadcastable <broadcasting-semantics>` with the first argument.
Args:
input (Tensor): the tensor to compare
other (Tensor or float): the tensor or value to compare
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
A boolean tensor that is True where :attr:`input` is greater than :attr:`other` and False elsewhere
Example::
>>> torch.gt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[False, True], [False, False]])
torch.half
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.hamming_window
Python Library Documentation: built-in function hamming_window in module torch
hamming_window(...)
hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
Hamming window function.
.. math::
w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
where :math:`N` is the full window size.
The input :attr:`window_length` is a positive integer controlling the
returned window size. :attr:`periodic` flag determines whether the returned
window trims off the last duplicate value from the symmetric window and is
ready to be used as a periodic window with functions like
:meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
``torch.hamming_window(L, periodic=True)`` equal to
``torch.hamming_window(L + 1, periodic=False)[:-1])``.
.. note::
If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
.. note::
This is a generalized version of :meth:`torch.hann_window`.
Arguments:
window_length (int): the size of returned window
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
.. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
pin_memory=False, requires_grad=False) -> Tensor
:noindex:
Hamming window function with periodic specified.
Arguments:
window_length (int): the size of returned window
periodic (bool): If True, returns a window to be used as periodic
function. If False, return a symmetric window.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
.. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
pin_memory=False, requires_grad=False) -> Tensor
:noindex:
Hamming window function with periodic and alpha specified.
Arguments:
window_length (int): the size of returned window
periodic (bool): If True, returns a window to be used as periodic
function. If False, return a symmetric window.
alpha (float): The coefficient :math:`\alpha` in the equation above
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
.. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
device=None, pin_memory=False, requires_grad=False) -> Tensor
:noindex:
Hamming window function with periodic, alpha and beta specified.
Arguments:
window_length (int): the size of returned window
periodic (bool): If True, returns a window to be used as periodic
function. If False, return a symmetric window.
alpha (float): The coefficient :math:`\alpha` in the equation above
beta (float): The coefficient :math:`\beta` in the equation above
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
torch.hann_window
Python Library Documentation: built-in function hann_window in module torch
hann_window(...)
hann_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Hann window function.
.. math::
w[n] = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{N - 1} \right)\right] =
\sin^2 \left( \frac{\pi n}{N - 1} \right),
where :math:`N` is the full window size.
The input :attr:`window_length` is a positive integer controlling the
returned window size. :attr:`periodic` flag determines whether the returned
window trims off the last duplicate value from the symmetric window and is
ready to be used as a periodic window with functions like
:meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
``torch.hann_window(L, periodic=True)`` equal to
``torch.hann_window(L + 1, periodic=False)[:-1])``.
.. note::
If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
Arguments:
window_length (int): the size of returned window
periodic (bool, optional): If True, returns a window to be used as periodic
function. If False, return a symmetric window.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
torch.hardshrink
Python Library Documentation: built-in function hardshrink in module torch
hardshrink(...)
hardshrink(input, lambd=0.5) -> Tensor
Applies the hard shrinkage function element-wise
See :class:`~torch.nn.Hardshrink` for more details.
torch.has_lapack
Python Library Documentation: bool object class bool(int) | bool(x) -> bool | | Returns True when the argument x is true, False otherwise. | The builtins True and False are the only two instances of the class bool. | The class bool is a subclass of the class int, and cannot be subclassed. | | Method resolution order: | bool | int | object | | Methods defined here: | | __and__(self, value, /) | Return self&value. | | __invert__(self, /) | ~self | | __or__(self, value, /) | Return self|value. | | __rand__(self, value, /) | Return value&self. | | __repr__(self, /) | Return repr(self). | | __ror__(self, value, /) | Return value|self. | | __rxor__(self, value, /) | Return value^self. | | __xor__(self, value, /) | Return self^value. | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __format__(self, format_spec, /) | Convert to a string according to format_spec. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number
torch.has_mkl
Python Library Documentation: bool object class bool(int) | bool(x) -> bool | | Returns True when the argument x is true, False otherwise. | The builtins True and False are the only two instances of the class bool. | The class bool is a subclass of the class int, and cannot be subclassed. | | Method resolution order: | bool | int | object | | Methods defined here: | | __and__(self, value, /) | Return self&value. | | __invert__(self, /) | ~self | | __or__(self, value, /) | Return self|value. | | __rand__(self, value, /) | Return value&self. | | __repr__(self, /) | Return repr(self). | | __ror__(self, value, /) | Return value|self. | | __rxor__(self, value, /) | Return value^self. | | __xor__(self, value, /) | Return self^value. | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __format__(self, format_spec, /) | Convert to a string according to format_spec. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number
torch.has_openmp
Python Library Documentation: bool object class bool(int) | bool(x) -> bool | | Returns True when the argument x is true, False otherwise. | The builtins True and False are the only two instances of the class bool. | The class bool is a subclass of the class int, and cannot be subclassed. | | Method resolution order: | bool | int | object | | Methods defined here: | | __and__(self, value, /) | Return self&value. | | __invert__(self, /) | ~self | | __or__(self, value, /) | Return self|value. | | __rand__(self, value, /) | Return value&self. | | __repr__(self, /) | Return repr(self). | | __ror__(self, value, /) | Return value|self. | | __rxor__(self, value, /) | Return value^self. | | __xor__(self, value, /) | Return self^value. | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __format__(self, format_spec, /) | Convert to a string according to format_spec. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number
torch.has_spectral
Python Library Documentation: bool object class bool(int) | bool(x) -> bool | | Returns True when the argument x is true, False otherwise. | The builtins True and False are the only two instances of the class bool. | The class bool is a subclass of the class int, and cannot be subclassed. | | Method resolution order: | bool | int | object | | Methods defined here: | | __and__(self, value, /) | Return self&value. | | __invert__(self, /) | ~self | | __or__(self, value, /) | Return self|value. | | __rand__(self, value, /) | Return value&self. | | __repr__(self, /) | Return repr(self). | | __ror__(self, value, /) | Return value|self. | | __rxor__(self, value, /) | Return value^self. | | __xor__(self, value, /) | Return self^value. | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __format__(self, format_spec, /) | Convert to a string according to format_spec. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number
torch.hash_tensor
Python Library Documentation: built-in function hash_tensor in module torch
hash_tensor(...)
hash_tensor(input, *, mode=0) -> Tensor
Returns a hash of all elements in the :attr:`input` tensor.
Currently only mode=0 (reduction via xor) is supported. The output will always
be of type ``torch.uint64``. The elements of ``input`` are upcasted to their
64 bit float / integer equivalent and bitcasted to ``torch.uint64`` before
reduction via xor.
Args:
input (Tensor): the input tensor.
Keyword Args:
mode (int) : The hash to use. Default: 0 (xor_reduction)
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 1.1918, -1.1813, 0.3373]])
>>> torch.hash_tensor(a)
tensor(13822780554648485888, dtype=torch.uint64)
.. function:: hash_tensor(input, dim, *, keepdim=False, mode=0) -> Tensor
:noindex:
Returns the hash of each row of the :attr:`input` tensor in the given
dimension :attr:`dim` given by mode. If :attr:`dim` is a list of dimensions,
reduce over all of them.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword Args:
mode (int) : The hash to use. Default: 0 (xor_reduction)
Example::
>>> a = torch.randn(2, 4)
>>> a
tensor([[ 0.1317, -0.5554, -1.4724, -1.1391],
[ 0.0778, -0.6070, 0.6375, 0.1798]])
>>> torch.hash_tensor(a, 1)
tensor([9233691267014066176, 9255993250844508160], dtype=torch.uint64)
torch.heaviside
Python Library Documentation: built-in function heaviside in module torch
heaviside(...)
heaviside(input, values, *, out=None) -> Tensor
Computes the Heaviside step function for each element in :attr:`input`.
The Heaviside step function is defined as:
.. math::
\text{{heaviside}}(input, values) = \begin{cases}
0, & \text{if input < 0}\\
values, & \text{if input == 0}\\
1, & \text{if input > 0}
\end{cases}
Args:
input (Tensor): the input tensor.
values (Tensor): The values to use where :attr:`input` is zero.
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> input = torch.tensor([-1.5, 0, 2.0])
>>> values = torch.tensor([0.5])
>>> torch.heaviside(input, values)
tensor([0.0000, 0.5000, 1.0000])
>>> values = torch.tensor([1.2, -2.0, 3.5])
>>> torch.heaviside(input, values)
tensor([0., -2., 1.])
torch.hinge_embedding_loss
Python Library Documentation: built-in function hinge_embedding_loss in module torch hinge_embedding_loss(...)
torch.histc
Python Library Documentation: built-in function histc in module torch
histc(...)
histc(input, bins=100, min=0, max=0, *, out=None) -> Tensor
Computes the histogram of a tensor.
The elements are sorted into equal width bins between :attr:`min` and
:attr:`max`. If :attr:`min` and :attr:`max` are both zero, the minimum and
maximum values of the data are used.
Elements lower than min and higher than max and ``NaN`` elements are ignored.
Args:
input (Tensor): the input tensor.
bins (int): number of histogram bins
min (Scalar): lower end of the range (inclusive)
max (Scalar): upper end of the range (inclusive)
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
Tensor: Histogram represented as a tensor
Example::
>>> torch.histc(torch.tensor([1., 2, 1]), bins=4, min=0, max=3)
tensor([ 0., 2., 1., 0.])
torch.histogram
Python Library Documentation: built-in function histogram in module torch
histogram(...)
histogram(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor)
Computes a histogram of the values in a tensor.
:attr:`bins` can be an integer or a 1D tensor.
If :attr:`bins` is an int, it specifies the number of equal-width bins.
By default, the lower and upper range of the bins is determined by the
minimum and maximum elements of the input tensor. The :attr:`range`
argument can be provided to specify a range for the bins.
If :attr:`bins` is a 1D tensor, it specifies the sequence of bin edges
including the rightmost edge. It should contain at least 2 elements
and its elements should be increasing.
Args:
input (Tensor): the input tensor.
bins: int or 1D Tensor. If int, defines the number of equal-width bins. If tensor,
defines the sequence of bin edges including the rightmost edge.
Keyword args:
range (tuple of float): Defines the range of the bins.
weight (Tensor): If provided, weight should have the same shape as input. Each value in
input contributes its associated weight towards its bin's result.
density (bool): If False, the result will contain the count (or total weight) in each bin.
If True, the result is the value of the probability density function over the bins,
normalized such that the integral over the range of the bins is 1.
out (Tensor, optional): the output tensor. (tuple, optional): The result tuple of two output tensors (hist, bin_edges).
Returns:
hist (Tensor): 1D Tensor containing the values of the histogram.
bin_edges(Tensor): 1D Tensor containing the edges of the histogram bins.
Example::
>>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]))
(tensor([ 0., 5., 2., 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
>>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]), density=True)
(tensor([ 0., 0.9524, 0.3810, 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
torch.histogramdd
Python Library Documentation: built-in function histogramdd in module torch
histogramdd(...)
histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])
Computes a multi-dimensional histogram of the values in a tensor.
Interprets the elements of an input tensor whose innermost dimension has size N
as a collection of N-dimensional points. Maps each of the points into a set of
N-dimensional bins and returns the number of points (or total weight) in each bin.
:attr:`input` must be a tensor with at least 2 dimensions.
If input has shape (M, N), each of its M rows defines a point in N-dimensional space.
If input has three or more dimensions, all but the last dimension are flattened.
Each dimension is independently associated with its own strictly increasing sequence
of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D
tensors. Alternatively, bin edges may be constructed automatically by passing a
sequence of integers specifying the number of equal-width bins in each dimension.
For each N-dimensional point in input:
- Each of its coordinates is binned independently among the bin edges
corresponding to its dimension
- Binning results are combined to identify the N-dimensional bin (if any)
into which the point falls
- If the point falls into a bin, the bin's count (or total weight) is incremented
- Points which do not fall into any bin do not contribute to the output
:attr:`bins` can be a sequence of N 1D tensors, a sequence of N ints, or a single int.
If :attr:`bins` is a sequence of N 1D tensors, it explicitly specifies the N sequences
of bin edges. Each 1D tensor should contain a strictly increasing sequence with at
least one element. A sequence of K bin edges defines K-1 bins, explicitly specifying
the left and right edges of all bins. Every bin is inclusive of its left edge. Only
the rightmost bin is inclusive of its right edge.
If :attr:`bins` is a sequence of N ints, it specifies the number of equal-width bins
in each dimension. By default, the leftmost and rightmost bin edges in each dimension
are determined by the minimum and maximum elements of the input tensor in the
corresponding dimension. The :attr:`range` argument can be provided to manually
specify the leftmost and rightmost bin edges in each dimension.
If :attr:`bins` is an int, it specifies the number of equal-width bins for all dimensions.
.. note::
See also :func:`torch.histogram`, which specifically computes 1D histograms.
While :func:`torch.histogramdd` infers the dimensionality of its bins and
binned values from the shape of :attr:`input`, :func:`torch.histogram`
accepts and flattens :attr:`input` of any shape.
Args:
input (Tensor): the input tensor.
bins: Tensor[], int[], or int.
If Tensor[], defines the sequences of bin edges.
If int[], defines the number of equal-width bins in each dimension.
If int, defines the number of equal-width bins for all dimensions.
Keyword args:
range (sequence of float): Defines the leftmost and rightmost bin edges
in each dimension.
weight (Tensor): By default, each value in the input has weight 1. If a weight
tensor is passed, each N-dimensional coordinate in input
contributes its associated weight towards its bin's result.
The weight tensor should have the same shape as the :attr:`input`
tensor excluding its innermost dimension N.
density (bool): If False (default), the result will contain the count (or total weight)
in each bin. If True, each count (weight) is divided by the total count
(total weight), then divided by the volume of its associated bin.
Returns:
hist (Tensor): N-dimensional Tensor containing the values of the histogram.
bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
Example::
>>> torch.histogramdd(torch.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3],
... weight=torch.tensor([1., 2., 4., 8.]))
torch.return_types.histogramdd(
hist=tensor([[0., 1., 0.],
[2., 0., 0.],
[4., 0., 8.]]),
bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]),
tensor([0.0000, 0.6667, 1.3333, 2.0000])))
>>> torch.histogramdd(torch.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2],
... range=[0., 1., 0., 1.], density=True)
torch.return_types.histogramdd(
hist=tensor([[2., 0.],
[0., 2.]]),
bin_edges=(tensor([0.0000, 0.5000, 1.0000]),
tensor([0.0000, 0.5000, 1.0000])))
torch.hsmm
Python Library Documentation: built-in function hsmm in module torch hsmm(...)
torch.hsplit
Python Library Documentation: built-in function hsplit in module torch
hsplit(...)
hsplit(input, indices_or_sections) -> List of Tensors
Splits :attr:`input`, a tensor with one or more dimensions, into multiple tensors
horizontally according to :attr:`indices_or_sections`. Each split is a view of
:attr:`input`.
If :attr:`input` is one dimensional this is equivalent to calling
torch.tensor_split(input, indices_or_sections, dim=0) (the split dimension is
zero), and if :attr:`input` has two or more dimensions it's equivalent to calling
torch.tensor_split(input, indices_or_sections, dim=1) (the split dimension is 1),
except that if :attr:`indices_or_sections` is an integer it must evenly divide
the split dimension or a runtime error will be thrown.
This function is based on NumPy's :func:`numpy.hsplit`.
Args:
input (Tensor): tensor to split.
indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
Example::
>>> t = torch.arange(16.0).reshape(4,4)
>>> t
tensor([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.],
[12., 13., 14., 15.]])
>>> torch.hsplit(t, 2)
(tensor([[ 0., 1.],
[ 4., 5.],
[ 8., 9.],
[12., 13.]]),
tensor([[ 2., 3.],
[ 6., 7.],
[10., 11.],
[14., 15.]]))
>>> torch.hsplit(t, [3, 6])
(tensor([[ 0., 1., 2.],
[ 4., 5., 6.],
[ 8., 9., 10.],
[12., 13., 14.]]),
tensor([[ 3.],
[ 7.],
[11.],
[15.]]),
tensor([], size=(4, 0)))
torch.hspmm
Python Library Documentation: built-in function hspmm in module torch
hspmm(...)
hspmm(mat1, mat2, *, out=None) -> Tensor
Performs a matrix multiplication of a :ref:`sparse COO matrix
<sparse-coo-docs>` :attr:`mat1` and a strided matrix :attr:`mat2`. The
result is a (1 + 1)-dimensional :ref:`hybrid COO matrix
<sparse-hybrid-coo-docs>`.
Args:
mat1 (Tensor): the first sparse matrix to be matrix multiplied
mat2 (Tensor): the second strided matrix to be matrix multiplied
Keyword args:
out (Tensor, optional): the output tensor.
torch.hstack
Python Library Documentation: built-in function hstack in module torch
hstack(...)
hstack(tensors, *, out=None) -> Tensor
Stack tensors in sequence horizontally (column wise).
This is equivalent to concatenation along the first axis for 1-D tensors, and along the second axis for all other tensors.
Args:
tensors (sequence of Tensors): sequence of tensors to concatenate
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([1, 2, 3])
>>> b = torch.tensor([4, 5, 6])
>>> torch.hstack((a,b))
tensor([1, 2, 3, 4, 5, 6])
>>> a = torch.tensor([[1],[2],[3]])
>>> b = torch.tensor([[4],[5],[6]])
>>> torch.hstack((a,b))
tensor([[1, 4],
[2, 5],
[3, 6]])
torch.hub
Python Library Documentation: module torch.hub in torch
NAME
torch.hub - # mypy: allow-untyped-defs
FUNCTIONS
download_url_to_file(url: str, dst: str, hash_prefix: str | None = None, progress: bool = True) -> None
Download object at the given URL to a local path.
Args:
url (str): URL of the object to download
dst (str): Full path where object will be saved, e.g. ``/tmp/temporary_file``
hash_prefix (str, optional): If not None, the SHA256 downloaded file should start with ``hash_prefix``.
Default: None
progress (bool, optional): whether or not to display a progress bar to stderr
Default: True
Example:
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB)
>>> # xdoctest: +REQUIRES(POSIX)
>>> torch.hub.download_url_to_file(
... "https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth",
... "/tmp/temporary_file",
... )
get_dir() -> str
Get the Torch Hub cache directory used for storing downloaded models & weights.
If :func:`~torch.hub.set_dir` is not called, default path is ``$TORCH_HOME/hub`` where
environment variable ``$TORCH_HOME`` defaults to ``$XDG_CACHE_HOME/torch``.
``$XDG_CACHE_HOME`` follows the X Design Group specification of the Linux
filesystem layout, with a default value ``~/.cache`` if the environment
variable is not set.
help(github, model, force_reload=False, skip_validation=False, trust_repo='check')
Show the docstring of entrypoint ``model``.
Args:
github (str): a string with format <repo_owner/repo_name[:ref]> with an optional
ref (a tag or a branch). If ``ref`` is not specified, the default branch is assumed
to be ``main`` if it exists, and otherwise ``master``.
Example: 'pytorch/vision:0.10'
model (str): a string of entrypoint name defined in repo's ``hubconf.py``
force_reload (bool, optional): whether to discard the existing cache and force a fresh download.
Default is ``False``.
skip_validation (bool, optional): if ``False``, torchhub will check that the ref
specified by the ``github`` argument properly belongs to the repo owner. This will make
requests to the GitHub API; you can specify a non-default GitHub token by setting the
``GITHUB_TOKEN`` environment variable. Default is ``False``.
trust_repo (bool or str): ``"check"``, ``True`` or ``False``.
This parameter was introduced in v1.12 and helps ensuring that users
only run code from repos that they trust.
- If ``False``, a prompt will ask the user whether the repo should
be trusted.
- If ``True``, the repo will be added to the trusted list and loaded
without requiring explicit confirmation.
- If ``"check"``, the repo will be checked against the list of
trusted repos in the cache. If it is not present in that list, the
behaviour will fall back onto the ``trust_repo=False`` option.
Default is ``"check"``.
Example:
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB)
>>> print(torch.hub.help("pytorch/vision", "resnet18", force_reload=True))
list(github, force_reload=False, skip_validation=False, trust_repo='check', verbose=True)
List all callable entrypoints available in the repo specified by ``github``.
Args:
github (str): a string with format "repo_owner/repo_name[:ref]" with an optional
ref (tag or branch). If ``ref`` is not specified, the default branch is assumed to be ``main`` if
it exists, and otherwise ``master``.
Example: 'pytorch/vision:0.10'
force_reload (bool, optional): whether to discard the existing cache and force a fresh download.
Default is ``False``.
skip_validation (bool, optional): if ``False``, torchhub will check that the branch or commit
specified by the ``github`` argument properly belongs to the repo owner. This will make
requests to the GitHub API; you can specify a non-default GitHub token by setting the
``GITHUB_TOKEN`` environment variable. Default is ``False``.
trust_repo (bool or str): ``"check"``, ``True`` or ``False``.
This parameter was introduced in v1.12 and helps ensuring that users
only run code from repos that they trust.
- If ``False``, a prompt will ask the user whether the repo should
be trusted.
- If ``True``, the repo will be added to the trusted list and loaded
without requiring explicit confirmation.
- If ``"check"``, the repo will be checked against the list of
trusted repos in the cache. If it is not present in that list, the
behaviour will fall back onto the ``trust_repo=False`` option.
Default is ``"check"``.
verbose (bool, optional): If ``False``, mute messages about hitting
local caches. Note that the message about first download cannot be
muted. Default is ``True``.
Returns:
list: The available callables entrypoint
Example:
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB)
>>> entrypoints = torch.hub.list("pytorch/vision", force_reload=True)
load(repo_or_dir, model, *args, source='github', trust_repo='check', force_reload=False, verbose=True, skip_validation=False, **kwargs)
Load a model from a github repo or a local directory.
Note: Loading a model is the typical use case, but this can also be used to
for loading other objects such as tokenizers, loss functions, etc.
If ``source`` is 'github', ``repo_or_dir`` is expected to be
of the form ``repo_owner/repo_name[:ref]`` with an optional
ref (a tag or a branch).
If ``source`` is 'local', ``repo_or_dir`` is expected to be a
path to a local directory.
Args:
repo_or_dir (str): If ``source`` is 'github',
this should correspond to a github repo with format ``repo_owner/repo_name[:ref]`` with
an optional ref (tag or branch), for example 'pytorch/vision:0.10'. If ``ref`` is not specified,
the default branch is assumed to be ``main`` if it exists, and otherwise ``master``.
If ``source`` is 'local' then it should be a path to a local directory.
model (str): the name of a callable (entrypoint) defined in the
repo/dir's ``hubconf.py``.
*args (optional): the corresponding args for callable ``model``.
source (str, optional): 'github' or 'local'. Specifies how
``repo_or_dir`` is to be interpreted. Default is 'github'.
trust_repo (bool or str): ``"check"``, ``True`` or ``False``.
This parameter was introduced in v1.12 and helps ensuring that users
only run code from repos that they trust.
- If ``False``, a prompt will ask the user whether the repo should
be trusted.
- If ``True``, the repo will be added to the trusted list and loaded
without requiring explicit confirmation.
- If ``"check"``, the repo will be checked against the list of
trusted repos in the cache. If it is not present in that list, the
behaviour will fall back onto the ``trust_repo=False`` option.
Default is ``"check"``.
force_reload (bool, optional): whether to force a fresh download of
the github repo unconditionally. Does not have any effect if
``source = 'local'``. Default is ``False``.
verbose (bool, optional): If ``False``, mute messages about hitting
local caches. Note that the message about first download cannot be
muted. Does not have any effect if ``source = 'local'``.
Default is ``True``.
skip_validation (bool, optional): if ``False``, torchhub will check that the branch or commit
specified by the ``github`` argument properly belongs to the repo owner. This will make
requests to the GitHub API; you can specify a non-default GitHub token by setting the
``GITHUB_TOKEN`` environment variable. Default is ``False``.
**kwargs (optional): the corresponding kwargs for callable ``model``.
Returns:
The output of the ``model`` callable when called with the given
``*args`` and ``**kwargs``.
Example:
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB)
>>> # from a github repo
>>> repo = "pytorch/vision"
>>> model = torch.hub.load(
... repo, "resnet50", weights="ResNet50_Weights.IMAGENET1K_V1"
... )
>>> # from a local directory
>>> path = "/some/local/path/pytorch/vision"
>>> # xdoctest: +SKIP
>>> model = torch.hub.load(path, "resnet50", weights="ResNet50_Weights.DEFAULT")
load_state_dict_from_url(url: str, model_dir: str | None = None, map_location: collections.abc.Callable[[torch.types.Storage, str], torch.types.Storage] | torch.device | str | dict[str, str] | None = None, progress: bool = True, check_hash: bool = False, file_name: str | None = None, weights_only: bool = False) -> dict[str, typing.Any]
Loads the Torch serialized object at the given URL.
If downloaded file is a zip file, it will be automatically
decompressed.
If the object is already present in `model_dir`, it's deserialized and
returned.
The default value of ``model_dir`` is ``<hub_dir>/checkpoints`` where
``hub_dir`` is the directory returned by :func:`~torch.hub.get_dir`.
Args:
url (str): URL of the object to download
model_dir (str, optional): directory in which to save the object
map_location (optional): a function or a dict specifying how to remap storage locations (see torch.load)
progress (bool, optional): whether or not to display a progress bar to stderr.
Default: True
check_hash(bool, optional): If True, the filename part of the URL should follow the naming convention
``filename-<sha256>.ext`` where ``<sha256>`` is the first eight or more
digits of the SHA256 hash of the contents of the file. The hash is used to
ensure unique names and to verify the contents of the file.
Default: False
file_name (str, optional): name for the downloaded file. Filename from ``url`` will be used if not set.
weights_only(bool, optional): If True, only weights will be loaded and no complex pickled objects.
Recommended for untrusted sources. See :func:`~torch.load` for more details.
Example:
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_HUB)
>>> state_dict = torch.hub.load_state_dict_from_url(
... "https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth"
... )
set_dir(d: str | os.PathLike) -> None
Optionally set the Torch Hub directory used to save downloaded models & weights.
Args:
d (str): path to a local folder to save downloaded models & weights.
DATA
__all__ = ['download_url_to_file', 'get_dir', 'help', 'list', 'load', ...
__annotations__ = {'_hub_dir': str | None}
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\hub.py
torch.hypot
Python Library Documentation: built-in function hypot in module torch
hypot(...)
hypot(input, other, *, out=None) -> Tensor
Given the legs of a right triangle, return its hypotenuse.
.. math::
\text{out}_{i} = \sqrt{\text{input}_{i}^{2} + \text{other}_{i}^{2}}
The shapes of ``input`` and ``other`` must be
:ref:`broadcastable <broadcasting-semantics>`.
Args:
input (Tensor): the first input tensor
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.hypot(torch.tensor([4.0]), torch.tensor([3.0, 4.0, 5.0]))
tensor([5.0000, 5.6569, 6.4031])
torch.i0
Python Library Documentation: built-in function i0 in module torch
i0(...)
i0(input, *, out=None) -> Tensor
Alias for :func:`torch.special.i0`.
torch.i0_
Python Library Documentation: built-in function i0_ in module torch i0_(...)
torch.igamma
Python Library Documentation: built-in function igamma in module torch
igamma(...)
igamma(input, other, *, out=None) -> Tensor
Alias for :func:`torch.special.gammainc`.
torch.igammac
Python Library Documentation: built-in function igammac in module torch
igammac(...)
igammac(input, other, *, out=None) -> Tensor
Alias for :func:`torch.special.gammaincc`.
torch.iinfo
Python Library Documentation: class iinfo in module torch class iinfo(builtins.object) | Methods defined here: | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __repr__(self, /) | Return repr(self). | | __str__(self, /) | Return str(self). | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | bits | | dtype | | max | | min | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __hash__ = None
torch.imag
Python Library Documentation: built-in function imag in module torch
imag(...)
imag(input) -> Tensor
Returns a new tensor containing imaginary values of the :attr:`self` tensor.
The returned tensor and :attr:`self` share the same underlying storage.
.. warning::
:func:`imag` is only supported for tensors with complex dtypes.
Args:
input (Tensor): the input tensor.
Example::
>>> x=torch.randn(4, dtype=torch.cfloat)
>>> x
tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
>>> x.imag
tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
torch.import_ir_module
Python Library Documentation: built-in function import_ir_module in module torch
import_ir_module(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
import_ir_module(arg0: torch._C.CompilationUnit, arg1: str, arg2: object, arg3: dict, arg4: bool) -> torch._C.ScriptModule
torch.import_ir_module_from_buffer
Python Library Documentation: built-in function import_ir_module_from_buffer in module torch
import_ir_module_from_buffer(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
import_ir_module_from_buffer(arg0: torch._C.CompilationUnit, arg1: str, arg2: object, arg3: dict, arg4: bool) -> torch._C.ScriptModule
torch.importlib
Python Library Documentation: package importlib
NAME
importlib - A pure Python implementation of import.
MODULE REFERENCE
https://docs.python.org/3.12/library/importlib.html
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
PACKAGE CONTENTS
_abc
_bootstrap
_bootstrap_external
abc
machinery
metadata (package)
readers
resources (package)
simple
util
FUNCTIONS
__import__(name, globals=None, locals=None, fromlist=(), level=0)
Import a module.
The 'globals' argument is used to infer where the import is occurring from
to handle relative imports. The 'locals' argument is ignored. The
'fromlist' argument specifies what should exist as attributes on the module
being imported (e.g. ``from module import <fromlist>``). The 'level'
argument represents the package location to import from in a relative
import (e.g. ``from ..pkg import mod`` would have a 'level' of 2).
import_module(name, package=None)
Import a module.
The 'package' argument is required when performing a relative import. It
specifies the package to use as the anchor point from which to resolve the
relative import to an absolute import.
invalidate_caches()
Call the invalidate_caches() method on all meta path finders stored in
sys.meta_path (where implemented).
reload(module)
Reload the module and return it.
The module must have been successfully imported before.
DATA
__all__ = ['__import__', 'import_module', 'invalidate_caches', 'reload...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\importlib\__init__.py
torch.index_add
Python Library Documentation: built-in function index_add in module torch
index_add(...)
index_add(input: Tensor, dim: int, index: Tensor, source: Tensor, *, alpha: Union[Number, _complex] = 1, out: Optional[Tensor]) -> Tensor # noqa: B950
See :meth:`~Tensor.index_add_` for function description.
torch.index_copy
Python Library Documentation: built-in function index_copy in module torch
index_copy(...)
index_copy(input: Tensor, dim: int, index: Tensor, source: Tensor, *, out: Optional[Tensor]) -> Tensor
See :meth:`~Tensor.index_copy_` for function description.
torch.index_fill
Python Library Documentation: built-in function index_fill in module torch index_fill(...)
torch.index_put
Python Library Documentation: built-in function index_put in module torch index_put(...)
torch.index_put_
Python Library Documentation: built-in function index_put_ in module torch index_put_(...)
torch.index_reduce
Python Library Documentation: built-in function index_reduce in module torch
index_reduce(...)
index_reduce(input: Tensor, dim: int, index: Tensor, source: Tensor, reduce: str, *, include_self: bool = True, out: Optional[Tensor]) -> Tensor # noqa: B950
See :meth:`~Tensor.index_reduce_` for function description.
torch.index_select
Python Library Documentation: built-in function index_select in module torch
index_select(...)
index_select(input, dim, index, *, out=None) -> Tensor
Returns a new tensor which indexes the :attr:`input` tensor along dimension
:attr:`dim` using the entries in :attr:`index`.
The returned tensor has the same number of dimensions as the original tensor
(:attr:`input`). The :attr:`dim`\ th dimension has the same size as the length
of :attr:`index`; other dimensions have the same size as in the original tensor.
.. note:: The returned tensor does **not** use the same storage as the original
tensor. If :attr:`out` has a different shape than expected, we
silently change it to the correct shape, reallocating the underlying
storage if necessary.
Args:
input (Tensor): the input tensor.
dim (int): the dimension in which we index
index (IntTensor or LongTensor): the 1-D tensor containing the indices to index
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.randn(3, 4)
>>> x
tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
[-0.4664, 0.2647, -0.1228, -1.1068],
[-1.1734, -0.6571, 0.7230, -0.6004]])
>>> indices = torch.tensor([0, 2])
>>> torch.index_select(x, 0, indices)
tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
[-1.1734, -0.6571, 0.7230, -0.6004]])
>>> torch.index_select(x, 1, indices)
tensor([[ 0.1427, -0.5414],
[-0.4664, -0.1228],
[-1.1734, 0.7230]])
torch.indices_copy
Python Library Documentation: built-in function indices_copy in module torch
indices_copy(...)
Performs the same operation as :func:`torch.indices`, but all output tensors
are freshly created instead of aliasing the input.
torch.inf
Python Library Documentation: float object
class float(object)
| float(x=0, /)
|
| Convert a string or number to a floating-point number, if possible.
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(self, /)
| Return the ceiling as an Integral.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(self, /)
| Return the floor as an Integral.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Formats the float according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __int__(self, /)
| int(self)
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __round__(self, ndigits=None, /)
| Return the Integral closest to x, rounding half toward even.
|
| When an argument is passed, work like built-in round(x, ndigits).
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(self, /)
| Return the Integral closest to x between 0 and x.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is exactly equal to the original float.
|
| The ratio is in lowest terms and has a positive denominator. Raise
| OverflowError on infinities and a ValueError on NaNs.
|
| >>> (10.0).as_integer_ratio()
| (10, 1)
| >>> (0.0).as_integer_ratio()
| (0, 1)
| >>> (-.25).as_integer_ratio()
| (-1, 4)
|
| conjugate(self, /)
| Return self, the complex conjugate of any float.
|
| hex(self, /)
| Return a hexadecimal representation of a floating-point number.
|
| >>> (-0.1).hex()
| '-0x1.999999999999ap-4'
| >>> 3.14159.hex()
| '0x1.921f9f01b866ep+1'
|
| is_integer(self, /)
| Return True if the float is an integer.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __getformat__(typestr, /)
| You probably don't want to use this function.
|
| typestr
| Must be 'double' or 'float'.
|
| It exists mainly to be used in Python's test suite.
|
| This function returns whichever of 'unknown', 'IEEE, big-endian' or 'IEEE,
| little-endian' best describes the format of floating-point numbers used by the
| C type named by typestr.
|
| fromhex(string, /)
| Create a floating-point number from a hexadecimal string.
|
| >>> float.fromhex('0x1.ffffp10')
| 2047.984375
| >>> float.fromhex('-0x1p-1074')
| -5e-324
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| imag
| the imaginary part of a complex number
|
| real
| the real part of a complex number
torch.inference_mode
Python Library Documentation: class inference_mode in module torch.autograd.grad_mode
class inference_mode(torch.utils._contextlib._DecoratorContextManager)
| inference_mode(mode=True)
|
| Context manager that enables or disables inference mode.
|
| InferenceMode is analogous to :class:`~no_grad` and should be used
| when you are certain your operations will not interact with autograd
| (e.g., during data loading or model evaluation). Compared to
| :class:`~no_grad`, it removes additional overhead by disabling view
| tracking and version counter bumps. It is also more restrictive, in
| that tensors created in this mode cannot be used in computations
| recorded by autograd.
|
| This context manager is thread-local; it does not affect computation
| in other threads.
|
| Also functions as a decorator.
|
| .. note::
| Inference mode is one of several mechanisms that can locally enable
| or disable gradients. See :ref:`locally-disable-grad-doc` for a
| comparison. If avoiding the use of tensors created in inference mode
| in autograd-tracked regions is difficult, consider benchmarking your
| code with and without inference mode to weigh the performance benefits
| against the trade-offs. You can always use :class:`~no_grad` instead.
|
| .. note::
| Unlike some other mechanisms that locally enable or disable grad,
| entering inference_mode also disables :ref:`forward-mode AD <forward-mode-ad>`.
|
| .. warning::
| `inference_mode` does NOT automatically set the model to evaluation mode.
| For proper inference behavior (e.g., disabling dropout, using running statistics
| in batch normalization), you must explicitly set your model to evaluation mode using
| `model.eval()` in addition to using this context manager.
|
| Args:
| mode (bool or function): Either a boolean flag to enable or disable
| inference mode, or a Python function to decorate with inference
| mode enabled.
|
| Example::
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_AUTOGRAD)
| >>> import torch
| >>> x = torch.ones(1, 2, 3, requires_grad=True)
| >>> with torch.inference_mode():
| ... y = x * x
| >>> y.requires_grad
| False
| >>> # xdoctest: +SKIP("want string isn't quite right")
| >>> y._version
| Traceback (most recent call last):
| File "<stdin>", line 1, in <module>
| RuntimeError: Inference tensors do not track version counter.
| >>> @torch.inference_mode()
| ... def func(x):
| ... return x * x
| >>> out = func(x)
| >>> out.requires_grad
| False
| >>> @torch.inference_mode()
| ... def doubler(x):
| ... return x * 2
| >>> out = doubler(x)
| >>> out.requires_grad
| False
|
| Method resolution order:
| inference_mode
| torch.utils._contextlib._DecoratorContextManager
| builtins.object
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None
|
| __init__(self, mode: bool = True) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| clone(self) -> 'inference_mode'
| Create a copy of this class
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, mode=True)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __call__(self, orig_func: ~F) -> ~F
| Call self as a function.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
torch.init_num_threads
Python Library Documentation: built-in function init_num_threads in module torch
init_num_threads(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
init_num_threads() -> None
init_num_threads()
Initializes the number of parallel threads used on the current thread.
Call this whenever a new thread is created in order to propagate values from
:func:`torch.set_num_threads` onto the new thread.
torch.initial_seed
Python Library Documentation: function initial_seed in module torch.random
initial_seed() -> int
Returns the initial seed for generating random numbers as a
Python `long`.
.. note:: The returned seed is for the default generator on CPU only.
torch.inner
Python Library Documentation: built-in function inner in module torch
inner(...)
inner(input, other, *, out=None) -> Tensor
Computes the dot product for 1D tensors. For higher dimensions, sums the product
of elements from :attr:`input` and :attr:`other` along their last dimension.
.. note::
If either :attr:`input` or :attr:`other` is a scalar, the result is equivalent
to `torch.mul(input, other)`.
If both :attr:`input` and :attr:`other` are non-scalars, the size of their last
dimension must match and the result is equivalent to `torch.tensordot(input,
other, dims=([-1], [-1]))`
Args:
input (Tensor): First input tensor
other (Tensor): Second input tensor
Keyword args:
out (Tensor, optional): Optional output tensor to write result into. The output
shape is `input.shape[:-1] + other.shape[:-1]`.
Example::
# Dot product
>>> torch.inner(torch.tensor([1, 2, 3]), torch.tensor([0, 2, 1]))
tensor(7)
# Multidimensional input tensors
>>> a = torch.randn(2, 3)
>>> a
tensor([[0.8173, 1.0874, 1.1784],
[0.3279, 0.1234, 2.7894]])
>>> b = torch.randn(2, 4, 3)
>>> b
tensor([[[-0.4682, -0.7159, 0.1506],
[ 0.4034, -0.3657, 1.0387],
[ 0.9892, -0.6684, 0.1774],
[ 0.9482, 1.3261, 0.3917]],
[[ 0.4537, 0.7493, 1.1724],
[ 0.2291, 0.5749, -0.2267],
[-0.7920, 0.3607, -0.3701],
[ 1.3666, -0.5850, -1.7242]]])
>>> torch.inner(a, b)
tensor([[[-0.9837, 1.1560, 0.2907, 2.6785],
[ 2.5671, 0.5452, -0.6912, -1.5509]],
[[ 0.1782, 2.9843, 0.7366, 1.5672],
[ 3.5115, -0.4864, -1.2476, -4.4337]]])
# Scalar input
>>> torch.inner(a, torch.tensor(2))
tensor([[1.6347, 2.1748, 2.3567],
[0.6558, 0.2469, 5.5787]])
torch.inspect
Python Library Documentation: module inspect
NAME
inspect - Get useful information from live Python objects.
MODULE REFERENCE
https://docs.python.org/3.12/library/inspect.html
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
DESCRIPTION
This module encapsulates the interface provided by the internal special
attributes (co_*, im_*, tb_*, etc.) in a friendlier fashion.
It also provides some help for examining source code and class layout.
Here are some of the useful functions provided by this module:
ismodule(), isclass(), ismethod(), isfunction(), isgeneratorfunction(),
isgenerator(), istraceback(), isframe(), iscode(), isbuiltin(),
isroutine() - check object types
getmembers() - get members of an object that satisfy a given condition
getfile(), getsourcefile(), getsource() - find an object's source code
getdoc(), getcomments() - get documentation on an object
getmodule() - determine the module that an object came from
getclasstree() - arrange classes so as to represent their hierarchy
getargvalues(), getcallargs() - get info about function arguments
getfullargspec() - same, with support for Python 3 features
formatargvalues() - format an argument spec
getouterframes(), getinnerframes() - get info about frames
currentframe() - get the current stack frame
stack(), trace() - get info about frames on the stack or in a traceback
signature() - get a Signature object for the callable
get_annotations() - safely compute an object's annotations
CLASSES
builtins.Exception(builtins.BaseException)
ClassFoundException
EndOfBlock
builtins.object
BlockFinder
BoundArguments
Parameter
Signature
builtins.tuple(builtins.object)
ArgInfo
Arguments
Attribute
ClosureVars
FullArgSpec
enum.IntFlag(builtins.int, enum.ReprEnum, enum.Flag)
BufferFlags
_FrameInfo(builtins.tuple)
FrameInfo
_Traceback(builtins.tuple)
Traceback
class ArgInfo(builtins.tuple)
| ArgInfo(args, varargs, keywords, locals)
|
| ArgInfo(args, varargs, keywords, locals)
|
| Method resolution order:
| ArgInfo
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __getnewargs__(self) from collections.ArgInfo
| Return self as a plain tuple. Used by copy and pickle.
|
| __repr__(self) from collections.ArgInfo
| Return a nicely formatted representation string
|
| _asdict(self) from collections.ArgInfo
| Return a new dict which maps field names to their values.
|
| _replace(self, /, **kwds) from collections.ArgInfo
| Return a new ArgInfo object replacing specified fields with new values
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| _make(iterable) from collections.ArgInfo
| Make a new ArgInfo object from a sequence or iterable
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(_cls, args, varargs, keywords, locals) from namedtuple_ArgInfo.ArgInfo
| Create new instance of ArgInfo(args, varargs, keywords, locals)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| args
| Alias for field number 0
|
| varargs
| Alias for field number 1
|
| keywords
| Alias for field number 2
|
| locals
| Alias for field number 3
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('args', 'varargs', 'keywords', 'locals')
|
| _field_defaults = {}
|
| _fields = ('args', 'varargs', 'keywords', 'locals')
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class Arguments(builtins.tuple)
| Arguments(args, varargs, varkw)
|
| Arguments(args, varargs, varkw)
|
| Method resolution order:
| Arguments
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __getnewargs__(self) from collections.Arguments
| Return self as a plain tuple. Used by copy and pickle.
|
| __repr__(self) from collections.Arguments
| Return a nicely formatted representation string
|
| _asdict(self) from collections.Arguments
| Return a new dict which maps field names to their values.
|
| _replace(self, /, **kwds) from collections.Arguments
| Return a new Arguments object replacing specified fields with new values
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| _make(iterable) from collections.Arguments
| Make a new Arguments object from a sequence or iterable
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(_cls, args, varargs, varkw) from namedtuple_Arguments.Arguments
| Create new instance of Arguments(args, varargs, varkw)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| args
| Alias for field number 0
|
| varargs
| Alias for field number 1
|
| varkw
| Alias for field number 2
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('args', 'varargs', 'varkw')
|
| _field_defaults = {}
|
| _fields = ('args', 'varargs', 'varkw')
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class Attribute(builtins.tuple)
| Attribute(name, kind, defining_class, object)
|
| Attribute(name, kind, defining_class, object)
|
| Method resolution order:
| Attribute
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __getnewargs__(self) from collections.Attribute
| Return self as a plain tuple. Used by copy and pickle.
|
| __repr__(self) from collections.Attribute
| Return a nicely formatted representation string
|
| _asdict(self) from collections.Attribute
| Return a new dict which maps field names to their values.
|
| _replace(self, /, **kwds) from collections.Attribute
| Return a new Attribute object replacing specified fields with new values
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| _make(iterable) from collections.Attribute
| Make a new Attribute object from a sequence or iterable
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(_cls, name, kind, defining_class, object) from namedtuple_Attribute.Attribute
| Create new instance of Attribute(name, kind, defining_class, object)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| name
| Alias for field number 0
|
| kind
| Alias for field number 1
|
| defining_class
| Alias for field number 2
|
| object
| Alias for field number 3
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('name', 'kind', 'defining_class', 'object')
|
| _field_defaults = {}
|
| _fields = ('name', 'kind', 'defining_class', 'object')
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class BlockFinder(builtins.object)
| Provide a tokeneater() method to detect the end of a code block.
|
| Methods defined here:
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| tokeneater(self, type, token, srowcol, erowcol, line)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class BoundArguments(builtins.object)
| BoundArguments(signature, arguments)
|
| Result of `Signature.bind` call. Holds the mapping of arguments
| to the function's parameters.
|
| Has the following public attributes:
|
| * arguments : dict
| An ordered mutable mapping of parameters' names to arguments' values.
| Does not contain arguments' default values.
| * signature : Signature
| The Signature object that created this instance.
| * args : tuple
| Tuple of positional arguments values.
| * kwargs : dict
| Dict of keyword arguments values.
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __getstate__(self)
| Helper for pickle.
|
| __init__(self, signature, arguments)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| __setstate__(self, state)
|
| apply_defaults(self)
| Set default values for missing arguments.
|
| For variable-positional arguments (*args) the default is an
| empty tuple.
|
| For variable-keyword arguments (**kwargs) the default is an
| empty dict.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| args
|
| kwargs
|
| signature
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| arguments
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class BufferFlags(enum.IntFlag)
| BufferFlags(*values)
|
| Method resolution order:
| BufferFlags
| enum.IntFlag
| builtins.int
| enum.ReprEnum
| enum.Flag
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __and__(self, other) from enum.Flag
|
| __format__(self, format_spec, /) from builtins.int
| Convert to a string according to format_spec.
|
| __invert__(self) from enum.Flag
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| __or__(self, other) from enum.Flag
| Return self|value.
|
| __rand__ = __and__(self, other)
|
| __ror__ = __or__(self, other)
|
| __rxor__ = __xor__(self, other)
|
| __xor__(self, other) from enum.Flag
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| FORMAT = <BufferFlags.FORMAT: 4>
|
| ND = <BufferFlags.ND: 8>
|
| READ = <BufferFlags.READ: 256>
|
| WRITABLE = <BufferFlags.WRITABLE: 1>
|
| WRITE = <BufferFlags.WRITE: 512>
|
| ----------------------------------------------------------------------
| Methods inherited from enum.IntFlag:
|
| __repr__(self) from enum.Flag
| Return repr(self).
|
| __str__ = __repr__(self, /) from builtins.int
| Return repr(self).
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.int:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.int:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.int:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Flag:
|
| __contains__(self, other)
| Returns True if self has at least the same flags set as other.
|
| __iter__(self)
| Returns flags in definition order.
|
| __len__(self)
| Return the number of members (no aliases)
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Static methods inherited from enum.EnumType:
|
| __getitem__(name)
| Return the member matching `name`.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class ClassFoundException(builtins.Exception)
| Method resolution order:
| ClassFoundException
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ClosureVars(builtins.tuple)
| ClosureVars(nonlocals, globals, builtins, unbound)
|
| ClosureVars(nonlocals, globals, builtins, unbound)
|
| Method resolution order:
| ClosureVars
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __getnewargs__(self) from collections.ClosureVars
| Return self as a plain tuple. Used by copy and pickle.
|
| __repr__(self) from collections.ClosureVars
| Return a nicely formatted representation string
|
| _asdict(self) from collections.ClosureVars
| Return a new dict which maps field names to their values.
|
| _replace(self, /, **kwds) from collections.ClosureVars
| Return a new ClosureVars object replacing specified fields with new values
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| _make(iterable) from collections.ClosureVars
| Make a new ClosureVars object from a sequence or iterable
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(_cls, nonlocals, globals, builtins, unbound) from namedtuple_ClosureVars.ClosureVars
| Create new instance of ClosureVars(nonlocals, globals, builtins, unbound)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| nonlocals
| Alias for field number 0
|
| globals
| Alias for field number 1
|
| builtins
| Alias for field number 2
|
| unbound
| Alias for field number 3
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('nonlocals', 'globals', 'builtins', 'unbound')
|
| _field_defaults = {}
|
| _fields = ('nonlocals', 'globals', 'builtins', 'unbound')
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class EndOfBlock(builtins.Exception)
| Method resolution order:
| EndOfBlock
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class FrameInfo(_FrameInfo)
| FrameInfo(frame, filename, lineno, function, code_context, index, *, positions=None)
|
| Method resolution order:
| FrameInfo
| _FrameInfo
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __repr__(self)
| Return a nicely formatted representation string
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, frame, filename, lineno, function, code_context, index, *, positions=None)
| Create new instance of _FrameInfo(frame, filename, lineno, function, code_context, index)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| ----------------------------------------------------------------------
| Methods inherited from _FrameInfo:
|
| __getnewargs__(self) from collections._FrameInfo
| Return self as a plain tuple. Used by copy and pickle.
|
| _asdict(self) from collections._FrameInfo
| Return a new dict which maps field names to their values.
|
| _replace(self, /, **kwds) from collections._FrameInfo
| Return a new _FrameInfo object replacing specified fields with new values
|
| ----------------------------------------------------------------------
| Class methods inherited from _FrameInfo:
|
| _make(iterable) from collections._FrameInfo
| Make a new _FrameInfo object from a sequence or iterable
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _FrameInfo:
|
| frame
| Alias for field number 0
|
| filename
| Alias for field number 1
|
| lineno
| Alias for field number 2
|
| function
| Alias for field number 3
|
| code_context
| Alias for field number 4
|
| index
| Alias for field number 5
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from _FrameInfo:
|
| __match_args__ = ('frame', 'filename', 'lineno', 'function', 'code_con...
|
| _field_defaults = {}
|
| _fields = ('frame', 'filename', 'lineno', 'function', 'code_context', ...
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class FullArgSpec(builtins.tuple)
| FullArgSpec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations)
|
| FullArgSpec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations)
|
| Method resolution order:
| FullArgSpec
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __getnewargs__(self) from collections.FullArgSpec
| Return self as a plain tuple. Used by copy and pickle.
|
| __repr__(self) from collections.FullArgSpec
| Return a nicely formatted representation string
|
| _asdict(self) from collections.FullArgSpec
| Return a new dict which maps field names to their values.
|
| _replace(self, /, **kwds) from collections.FullArgSpec
| Return a new FullArgSpec object replacing specified fields with new values
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| _make(iterable) from collections.FullArgSpec
| Make a new FullArgSpec object from a sequence or iterable
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(_cls, args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations) from namedtuple_FullArgSpec.FullArgSpec
| Create new instance of FullArgSpec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| args
| Alias for field number 0
|
| varargs
| Alias for field number 1
|
| varkw
| Alias for field number 2
|
| defaults
| Alias for field number 3
|
| kwonlyargs
| Alias for field number 4
|
| kwonlydefaults
| Alias for field number 5
|
| annotations
| Alias for field number 6
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('args', 'varargs', 'varkw', 'defaults', 'kwonlyargs'...
|
| _field_defaults = {}
|
| _fields = ('args', 'varargs', 'varkw', 'defaults', 'kwonlyargs', 'kwon...
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class Parameter(builtins.object)
| Parameter(name, kind, *, default, annotation)
|
| Represents a parameter in a function signature.
|
| Has the following public attributes:
|
| * name : str
| The name of the parameter as a string.
| * default : object
| The default value for the parameter if specified. If the
| parameter has no default value, this attribute is set to
| `Parameter.empty`.
| * annotation
| The annotation for the parameter if specified. If the
| parameter has no annotation, this attribute is set to
| `Parameter.empty`.
| * kind : str
| Describes how argument values are bound to the parameter.
| Possible values: `Parameter.POSITIONAL_ONLY`,
| `Parameter.POSITIONAL_OR_KEYWORD`, `Parameter.VAR_POSITIONAL`,
| `Parameter.KEYWORD_ONLY`, `Parameter.VAR_KEYWORD`.
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, name, kind, *, default, annotation)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setstate__(self, state)
|
| __str__(self)
| Return str(self).
|
| replace(self, *, name=<class 'inspect._void'>, kind=<class 'inspect._void'>, annotation=<class 'inspect._void'>, default=<class 'inspect._void'>)
| Creates a customized copy of the Parameter.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| annotation
|
| default
|
| kind
|
| name
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| KEYWORD_ONLY = <_ParameterKind.KEYWORD_ONLY: 3>
|
| POSITIONAL_ONLY = <_ParameterKind.POSITIONAL_ONLY: 0>
|
| POSITIONAL_OR_KEYWORD = <_ParameterKind.POSITIONAL_OR_KEYWORD: 1>
|
| VAR_KEYWORD = <_ParameterKind.VAR_KEYWORD: 4>
|
| VAR_POSITIONAL = <_ParameterKind.VAR_POSITIONAL: 2>
|
| empty = <class 'inspect._empty'>
| Marker object for Signature.empty and Parameter.empty.
class Signature(builtins.object)
| Signature(parameters=None, *, return_annotation, __validate_parameters__=True)
|
| A Signature object represents the overall signature of a function.
| It stores a Parameter object for each parameter accepted by the
| function, as well as information specific to the function itself.
|
| A Signature object has the following public attributes and methods:
|
| * parameters : OrderedDict
| An ordered mapping of parameters' names to the corresponding
| Parameter objects (keyword-only arguments are in the same order
| as listed in `code.co_varnames`).
| * return_annotation : object
| The annotation for the return type of the function if specified.
| If the function has no annotation for its return type, this
| attribute is set to `Signature.empty`.
| * bind(*args, **kwargs) -> BoundArguments
| Creates a mapping from positional and keyword arguments to
| parameters.
| * bind_partial(*args, **kwargs) -> BoundArguments
| Creates a partial mapping from positional and keyword arguments
| to parameters (simulating 'functools.partial' behavior.)
|
| Methods defined here:
|
| __eq__(self, other)
| Return self==value.
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, parameters=None, *, return_annotation, __validate_parameters__=True)
| Constructs Signature from the given list of Parameter
| objects and 'return_annotation'. All arguments are optional.
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setstate__(self, state)
|
| __str__(self)
| Return str(self).
|
| bind(self, /, *args, **kwargs)
| Get a BoundArguments object, that maps the passed `args`
| and `kwargs` to the function's signature. Raises `TypeError`
| if the passed arguments can not be bound.
|
| bind_partial(self, /, *args, **kwargs)
| Get a BoundArguments object, that partially maps the
| passed `args` and `kwargs` to the function's signature.
| Raises `TypeError` if the passed arguments can not be bound.
|
| replace(self, *, parameters=<class 'inspect._void'>, return_annotation=<class 'inspect._void'>)
| Creates a customized copy of the Signature.
| Pass 'parameters' and/or 'return_annotation' arguments
| to override them in the new copy.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_callable(obj, *, follow_wrapped=True, globals=None, locals=None, eval_str=False)
| Constructs Signature for the given callable object.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| parameters
|
| return_annotation
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| empty = <class 'inspect._empty'>
| Marker object for Signature.empty and Parameter.empty.
class Traceback(_Traceback)
| Traceback(filename, lineno, function, code_context, index, *, positions=None)
|
| Method resolution order:
| Traceback
| _Traceback
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __repr__(self)
| Return a nicely formatted representation string
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, filename, lineno, function, code_context, index, *, positions=None)
| Create new instance of _Traceback(filename, lineno, function, code_context, index)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| ----------------------------------------------------------------------
| Methods inherited from _Traceback:
|
| __getnewargs__(self) from collections._Traceback
| Return self as a plain tuple. Used by copy and pickle.
|
| _asdict(self) from collections._Traceback
| Return a new dict which maps field names to their values.
|
| _replace(self, /, **kwds) from collections._Traceback
| Return a new _Traceback object replacing specified fields with new values
|
| ----------------------------------------------------------------------
| Class methods inherited from _Traceback:
|
| _make(iterable) from collections._Traceback
| Make a new _Traceback object from a sequence or iterable
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _Traceback:
|
| filename
| Alias for field number 0
|
| lineno
| Alias for field number 1
|
| function
| Alias for field number 2
|
| code_context
| Alias for field number 3
|
| index
| Alias for field number 4
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from _Traceback:
|
| __match_args__ = ('filename', 'lineno', 'function', 'code_context', 'i...
|
| _field_defaults = {}
|
| _fields = ('filename', 'lineno', 'function', 'code_context', 'index')
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
FUNCTIONS
classify_class_attrs(cls)
Return list of attribute-descriptor tuples.
For each name in dir(cls), the return list contains a 4-tuple
with these elements:
0. The name (a string).
1. The kind of attribute this is, one of these strings:
'class method' created via classmethod()
'static method' created via staticmethod()
'property' created via property()
'method' any other flavor of method or descriptor
'data' not a method
2. The class which defined this attribute (a class).
3. The object as obtained by calling getattr; if this fails, or if the
resulting object does not live anywhere in the class' mro (including
metaclasses) then the object is looked up in the defining class's
dict (found by walking the mro).
If one of the items in dir(cls) is stored in the metaclass it will now
be discovered and not have None be listed as the class in which it was
defined. Any items whose home class cannot be discovered are skipped.
cleandoc(doc)
Clean up indentation from docstrings.
Any whitespace that can be uniformly removed from the second line
onwards is removed.
currentframe()
Return the frame of the caller or None if this is not possible.
findsource(object)
Return the entire source file and starting line number for an object.
The argument may be a module, class, method, function, traceback, frame,
or code object. The source code is returned as a list of all the lines
in the file and the line number indexes a line in that list. An OSError
is raised if the source code cannot be retrieved.
formatannotation(annotation, base_module=None)
formatannotationrelativeto(object)
formatargvalues(args, varargs, varkw, locals, formatarg=<class 'str'>, formatvarargs=<function <lambda> at 0x00000199DD86C9A0>, formatvarkw=<function <lambda> at 0x00000199DD86CA40>, formatvalue=<function <lambda> at 0x00000199DD86CAE0>)
Format an argument spec from the 4 values returned by getargvalues.
The first four arguments are (args, varargs, varkw, locals). The
next four arguments are the corresponding optional formatting functions
that are called to turn names and values into strings. The ninth
argument is an optional function to format the sequence of arguments.
get_annotations(obj, *, globals=None, locals=None, eval_str=False)
Compute the annotations dict for an object.
obj may be a callable, class, or module.
Passing in an object of any other type raises TypeError.
Returns a dict. get_annotations() returns a new dict every time
it's called; calling it twice on the same object will return two
different but equivalent dicts.
This function handles several details for you:
* If eval_str is true, values of type str will
be un-stringized using eval(). This is intended
for use with stringized annotations
("from __future__ import annotations").
* If obj doesn't have an annotations dict, returns an
empty dict. (Functions and methods always have an
annotations dict; classes, modules, and other types of
callables may not.)
* Ignores inherited annotations on classes. If a class
doesn't have its own annotations dict, returns an empty dict.
* All accesses to object members and dict values are done
using getattr() and dict.get() for safety.
* Always, always, always returns a freshly-created dict.
eval_str controls whether or not values of type str are replaced
with the result of calling eval() on those values:
* If eval_str is true, eval() is called on values of type str.
* If eval_str is false (the default), values of type str are unchanged.
globals and locals are passed in to eval(); see the documentation
for eval() for more information. If either globals or locals is
None, this function may replace that value with a context-specific
default, contingent on type(obj):
* If obj is a module, globals defaults to obj.__dict__.
* If obj is a class, globals defaults to
sys.modules[obj.__module__].__dict__ and locals
defaults to the obj class namespace.
* If obj is a callable, globals defaults to obj.__globals__,
although if obj is a wrapped function (using
functools.update_wrapper()) it is first unwrapped.
getabsfile(object, _filename=None)
Return an absolute path to the source or compiled file for an object.
The idea is for each object to have a unique origin, so this routine
normalizes the result as much as possible.
getargs(co)
Get information about the arguments accepted by a code object.
Three things are returned: (args, varargs, varkw), where
'args' is the list of argument names. Keyword-only arguments are
appended. 'varargs' and 'varkw' are the names of the * and **
arguments or None.
getargvalues(frame)
Get information about arguments passed into a particular frame.
A tuple of four things is returned: (args, varargs, varkw, locals).
'args' is a list of the argument names.
'varargs' and 'varkw' are the names of the * and ** arguments or None.
'locals' is the locals dictionary of the given frame.
getasyncgenlocals(agen)
Get the mapping of asynchronous generator local variables to their current
values.
A dict is returned, with the keys the local variable names and values the
bound values.
getasyncgenstate(agen)
Get current state of an asynchronous generator object.
Possible states are:
AGEN_CREATED: Waiting to start execution.
AGEN_RUNNING: Currently being executed by the interpreter.
AGEN_SUSPENDED: Currently suspended at a yield expression.
AGEN_CLOSED: Execution has completed.
getattr_static(obj, attr, default=<object object at 0x00000199DD0A87B0>)
Retrieve attributes without triggering dynamic lookup via the
descriptor protocol, __getattr__ or __getattribute__.
Note: this function may not be able to retrieve all attributes
that getattr can fetch (like dynamically created attributes)
and may find attributes that getattr can't (like descriptors
that raise AttributeError). It can also return descriptor objects
instead of instance members in some cases. See the
documentation for details.
getblock(lines)
Extract the block of code at the top of the given list of lines.
getcallargs(func, /, *positional, **named)
Get the mapping of arguments to values.
A dict is returned, with keys the function argument names (including the
names of the * and ** arguments, if any), and values the respective bound
values from 'positional' and 'named'.
getclasstree(classes, unique=False)
Arrange the given list of classes into a hierarchy of nested lists.
Where a nested list appears, it contains classes derived from the class
whose entry immediately precedes the list. Each entry is a 2-tuple
containing a class and a tuple of its base classes. If the 'unique'
argument is true, exactly one entry appears in the returned structure
for each class in the given list. Otherwise, classes using multiple
inheritance and their descendants will appear multiple times.
getclosurevars(func)
Get the mapping of free variables to their current values.
Returns a named tuple of dicts mapping the current nonlocal, global
and builtin references as seen by the body of the function. A final
set of unbound names that could not be resolved is also provided.
getcomments(object)
Get lines of comments immediately preceding an object's source code.
Returns None when source can't be found.
getcoroutinelocals(coroutine)
Get the mapping of coroutine local variables to their current values.
A dict is returned, with the keys the local variable names and values the
bound values.
getcoroutinestate(coroutine)
Get current state of a coroutine object.
Possible states are:
CORO_CREATED: Waiting to start execution.
CORO_RUNNING: Currently being executed by the interpreter.
CORO_SUSPENDED: Currently suspended at an await expression.
CORO_CLOSED: Execution has completed.
getdoc(object)
Get the documentation string for an object.
All tabs are expanded to spaces. To clean up docstrings that are
indented to line up with blocks of code, any whitespace than can be
uniformly removed from the second line onwards is removed.
getfile = _patched_getfile(object)
getframeinfo(frame, context=1)
Get information about a frame or traceback object.
A tuple of five things is returned: the filename, the line number of
the current line, the function name, a list of lines of context from
the source code, and the index of the current line within that list.
The optional second argument specifies the number of lines of context
to return, which are centered around the current line.
getfullargspec(func)
Get the names and default values of a callable object's parameters.
A tuple of seven things is returned:
(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations).
'args' is a list of the parameter names.
'varargs' and 'varkw' are the names of the * and ** parameters or None.
'defaults' is an n-tuple of the default values of the last n parameters.
'kwonlyargs' is a list of keyword-only parameter names.
'kwonlydefaults' is a dictionary mapping names from kwonlyargs to defaults.
'annotations' is a dictionary mapping parameter names to annotations.
Notable differences from inspect.signature():
- the "self" parameter is always reported, even for bound methods
- wrapper chains defined by __wrapped__ *not* unwrapped automatically
getgeneratorlocals(generator)
Get the mapping of generator local variables to their current values.
A dict is returned, with the keys the local variable names and values the
bound values.
getgeneratorstate(generator)
Get current state of a generator-iterator.
Possible states are:
GEN_CREATED: Waiting to start execution.
GEN_RUNNING: Currently being executed by the interpreter.
GEN_SUSPENDED: Currently suspended at a yield expression.
GEN_CLOSED: Execution has completed.
getinnerframes(tb, context=1)
Get a list of records for a traceback's frame and all lower frames.
Each record contains a frame object, filename, line number, function
name, a list of lines of context, and index within the context.
getlineno(frame)
Get the line number from a frame object, allowing for optimization.
getmembers(object, predicate=None)
Return all members of an object as (name, value) pairs sorted by name.
Optionally, only return members that satisfy a given predicate.
getmembers_static(object, predicate=None)
Return all members of an object as (name, value) pairs sorted by name
without triggering dynamic lookup via the descriptor protocol,
__getattr__ or __getattribute__. Optionally, only return members that
satisfy a given predicate.
Note: this function may not be able to retrieve all members
that getmembers can fetch (like dynamically created attributes)
and may find members that getmembers can't (like descriptors
that raise AttributeError). It can also return descriptor objects
instead of instance members in some cases.
getmodule(object, _filename=None)
Return the module an object was defined in, or None if not found.
getmodulename(path)
Return the module name for a given file, or None.
getmro(cls)
Return tuple of base classes (including cls) in method resolution order.
getouterframes(frame, context=1)
Get a list of records for a frame and all higher (calling) frames.
Each record contains a frame object, filename, line number, function
name, a list of lines of context, and index within the context.
getsource(object)
Return the text of the source code for an object.
The argument may be a module, class, method, function, traceback, frame,
or code object. The source code is returned as a single string. An
OSError is raised if the source code cannot be retrieved.
getsourcefile(object)
Return the filename that can be used to locate an object's source.
Return None if no way can be identified to get the source.
getsourcelines(object)
Return a list of source lines and starting line number for an object.
The argument may be a module, class, method, function, traceback, frame,
or code object. The source code is returned as a list of the lines
corresponding to the object and the line number indicates where in the
original source file the first line of code was found. An OSError is
raised if the source code cannot be retrieved.
indentsize(line)
Return the indent size, in spaces, at the start of a line of text.
isabstract(object)
Return true if the object is an abstract base class (ABC).
isasyncgen(object)
Return true if the object is an asynchronous generator.
isasyncgenfunction(obj)
Return true if the object is an asynchronous generator function.
Asynchronous generator functions are defined with "async def"
syntax and have "yield" expressions in their body.
isawaitable(object)
Return true if object can be passed to an ``await`` expression.
isbuiltin(object)
Return true if the object is a built-in function or method.
Built-in functions and methods provide these attributes:
__doc__ documentation string
__name__ original name of this function or method
__self__ instance to which a method is bound, or None
isclass(object)
Return true if the object is a class.
iscode(object)
Return true if the object is a code object.
Code objects provide these attributes:
co_argcount number of arguments (not including *, ** args
or keyword only arguments)
co_code string of raw compiled bytecode
co_cellvars tuple of names of cell variables
co_consts tuple of constants used in the bytecode
co_filename name of file in which this code object was created
co_firstlineno number of first line in Python source code
co_flags bitmap: 1=optimized | 2=newlocals | 4=*arg | 8=**arg
| 16=nested | 32=generator | 64=nofree | 128=coroutine
| 256=iterable_coroutine | 512=async_generator
co_freevars tuple of names of free variables
co_posonlyargcount number of positional only arguments
co_kwonlyargcount number of keyword only arguments (not including ** arg)
co_lnotab encoded mapping of line numbers to bytecode indices
co_name name with which this code object was defined
co_names tuple of names other than arguments and function locals
co_nlocals number of local variables
co_stacksize virtual machine stack space required
co_varnames tuple of names of arguments and local variables
iscoroutine(object)
Return true if the object is a coroutine.
iscoroutinefunction(obj)
Return true if the object is a coroutine function.
Coroutine functions are normally defined with "async def" syntax, but may
be marked via markcoroutinefunction.
isdatadescriptor(object)
Return true if the object is a data descriptor.
Data descriptors have a __set__ or a __delete__ attribute. Examples are
properties (defined in Python) and getsets and members (defined in C).
Typically, data descriptors will also have __name__ and __doc__ attributes
(properties, getsets, and members have both of these attributes), but this
is not guaranteed.
isframe(object)
Return true if the object is a frame object.
Frame objects provide these attributes:
f_back next outer frame object (this frame's caller)
f_builtins built-in namespace seen by this frame
f_code code object being executed in this frame
f_globals global namespace seen by this frame
f_lasti index of last attempted instruction in bytecode
f_lineno current line number in Python source code
f_locals local namespace seen by this frame
f_trace tracing function for this frame, or None
isfunction(object)
Return true if the object is a user-defined function.
Function objects provide these attributes:
__doc__ documentation string
__name__ name with which this function was defined
__code__ code object containing compiled function bytecode
__defaults__ tuple of any default values for arguments
__globals__ global namespace in which this function was defined
__annotations__ dict of parameter annotations
__kwdefaults__ dict of keyword only parameters with defaults
isgenerator(object)
Return true if the object is a generator.
Generator objects provide these attributes:
__iter__ defined to support iteration over container
close raises a new GeneratorExit exception inside the
generator to terminate the iteration
gi_code code object
gi_frame frame object or possibly None once the generator has
been exhausted
gi_running set to 1 when generator is executing, 0 otherwise
next return the next item from the container
send resumes the generator and "sends" a value that becomes
the result of the current yield-expression
throw used to raise an exception inside the generator
isgeneratorfunction(obj)
Return true if the object is a user-defined generator function.
Generator function objects provide the same attributes as functions.
See help(isfunction) for a list of attributes.
isgetsetdescriptor(object)
Return true if the object is a getset descriptor.
getset descriptors are specialized descriptors defined in extension
modules.
ismemberdescriptor(object)
Return true if the object is a member descriptor.
Member descriptors are specialized descriptors defined in extension
modules.
ismethod(object)
Return true if the object is an instance method.
ismethoddescriptor(object)
Return true if the object is a method descriptor.
But not if ismethod() or isclass() or isfunction() are true.
This is new in Python 2.2, and, for example, is true of int.__add__.
An object passing this test has a __get__ attribute but not a __set__
attribute, but beyond that the set of attributes varies. __name__ is
usually sensible, and __doc__ often is.
Methods implemented via descriptors that also pass one of the other
tests return false from the ismethoddescriptor() test, simply because
the other tests promise more -- you can, e.g., count on having the
__func__ attribute (etc) when an object passes ismethod().
ismethodwrapper(object)
Return true if the object is a method wrapper.
ismodule(object)
Return true if the object is a module.
isroutine(object)
Return true if the object is any kind of function or method.
istraceback(object)
Return true if the object is a traceback.
Traceback objects provide these attributes:
tb_frame frame object at this level
tb_lasti index of last attempted instruction in bytecode
tb_lineno current line number in Python source code
tb_next next inner traceback object (called by this level)
markcoroutinefunction(func)
Decorator to ensure callable is recognised as a coroutine function.
signature(obj, *, follow_wrapped=True, globals=None, locals=None, eval_str=False)
Get a signature object for the passed callable.
stack(context=1)
Return a list of records for the stack above the caller's frame.
trace(context=1)
Return a list of records for the stack below the current exception.
unwrap(func, *, stop=None)
Get the object wrapped by *func*.
Follows the chain of :attr:`__wrapped__` attributes returning the last
object in the chain.
*stop* is an optional callback accepting an object in the wrapper chain
as its sole argument that allows the unwrapping to be terminated early if
the callback returns a true value. If the callback never returns a true
value, the last object in the chain is returned as usual. For example,
:func:`signature` uses this to stop unwrapping if any object in the
chain has a ``__signature__`` attribute defined.
:exc:`ValueError` is raised if a cycle is encountered.
walktree(classes, children, parent)
Recursive helper function for getclasstree().
DATA
AGEN_CLOSED = 'AGEN_CLOSED'
AGEN_CREATED = 'AGEN_CREATED'
AGEN_RUNNING = 'AGEN_RUNNING'
AGEN_SUSPENDED = 'AGEN_SUSPENDED'
CORO_CLOSED = 'CORO_CLOSED'
CORO_CREATED = 'CORO_CREATED'
CORO_RUNNING = 'CORO_RUNNING'
CORO_SUSPENDED = 'CORO_SUSPENDED'
CO_ASYNC_GENERATOR = 512
CO_COROUTINE = 128
CO_GENERATOR = 32
CO_ITERABLE_COROUTINE = 256
CO_NESTED = 16
CO_NEWLOCALS = 2
CO_NOFREE = 64
CO_OPTIMIZED = 1
CO_VARARGS = 4
CO_VARKEYWORDS = 8
GEN_CLOSED = 'GEN_CLOSED'
GEN_CREATED = 'GEN_CREATED'
GEN_RUNNING = 'GEN_RUNNING'
GEN_SUSPENDED = 'GEN_SUSPENDED'
TPFLAGS_IS_ABSTRACT = 1048576
__all__ = ['AGEN_CLOSED', 'AGEN_CREATED', 'AGEN_RUNNING', 'AGEN_SUSPEN...
__warningregistry__ = {'version': 13}
AUTHOR
('Ka-Ping Yee <ping@lfw.org>', 'Yury Selivanov <yselivanov@sprymix.com>')
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\inspect.py
torch.instance_norm
Python Library Documentation: built-in function instance_norm in module torch instance_norm(...)
torch.int
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.int1
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.int16
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.int2
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.int3
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.int32
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.int4
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.int5
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.int6
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.int64
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.int7
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.int8
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.int_repr
Python Library Documentation: built-in function int_repr in module torch int_repr(...)
torch.inverse
Python Library Documentation: built-in function inverse in module torch
inverse(...)
inverse(input, *, out=None) -> Tensor
Alias for :func:`torch.linalg.inv`
torch.is_anomaly_check_nan_enabled
Python Library Documentation: built-in function is_anomaly_check_nan_enabled in module torch is_anomaly_check_nan_enabled(...)
torch.is_anomaly_enabled
Python Library Documentation: built-in function is_anomaly_enabled in module torch is_anomaly_enabled(...)
torch.is_autocast_cache_enabled
Python Library Documentation: built-in function is_autocast_cache_enabled in module torch is_autocast_cache_enabled(...)
torch.is_autocast_cpu_enabled
Python Library Documentation: built-in function is_autocast_cpu_enabled in module torch is_autocast_cpu_enabled(...)
torch.is_autocast_enabled
Python Library Documentation: built-in function is_autocast_enabled in module torch is_autocast_enabled(...)
torch.is_autocast_ipu_enabled
Python Library Documentation: built-in function is_autocast_ipu_enabled in module torch is_autocast_ipu_enabled(...)
torch.is_autocast_xla_enabled
Python Library Documentation: built-in function is_autocast_xla_enabled in module torch is_autocast_xla_enabled(...)
torch.is_complex
Python Library Documentation: built-in function is_complex in module torch
is_complex(...)
is_complex(input: Tensor) -> bool
Returns True if the data type of :attr:`input` is a complex data type i.e.,
one of ``torch.complex64``, and ``torch.complex128``.
Args:
input (Tensor): the input tensor.
Example::
>>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.complex64))
True
>>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.complex128))
True
>>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.int32))
False
>>> torch.is_complex(torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16))
False
torch.is_conj
Python Library Documentation: built-in function is_conj in module torch
is_conj(...)
is_conj(input) -> (bool)
Returns True if the :attr:`input` is a conjugated tensor, i.e. its conjugate bit is set to `True`.
Args:
input (Tensor): the input tensor.
torch.is_deterministic_algorithms_warn_only_enabled
Python Library Documentation: function is_deterministic_algorithms_warn_only_enabled in module torch
is_deterministic_algorithms_warn_only_enabled() -> bool
Returns True if the global deterministic flag is set to warn only.
Refer to :func:`torch.use_deterministic_algorithms` documentation for more
details.
torch.is_distributed
Python Library Documentation: built-in function is_distributed in module torch is_distributed(...)
torch.is_floating_point
Python Library Documentation: built-in function is_floating_point in module torch
is_floating_point(...)
is_floating_point(input: Tensor) -> bool
Returns True if the data type of :attr:`input` is a floating point data type i.e.,
one of ``torch.float64``, ``torch.float32``, ``torch.float16``, and ``torch.bfloat16``.
Args:
input (Tensor): the input tensor.
Example::
>>> torch.is_floating_point(torch.tensor([1.0, 2.0, 3.0]))
True
>>> torch.is_floating_point(torch.tensor([1, 2, 3], dtype=torch.int32))
False
>>> torch.is_floating_point(torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16))
True
>>> torch.is_floating_point(torch.tensor([1, 2, 3], dtype=torch.complex64))
False
torch.is_grad_enabled
Python Library Documentation: built-in function is_grad_enabled in module torch
is_grad_enabled(...)
is_grad_enabled() -> (bool)
Returns True if grad mode is currently enabled.
torch.is_inference
Python Library Documentation: built-in function is_inference in module torch
is_inference(...)
is_inference(input) -> (bool)
Returns True if :attr:`input` is an inference tensor.
A non-view tensor is an inference tensor if and only if it was
allocated during inference mode. A view tensor is an inference
tensor if and only if the tensor it is a view of is an inference tensor.
For details on inference mode please see
`Inference Mode <https://pytorch.org/cppdocs/notes/inference_mode.html>`_.
Args:
input (Tensor): the input tensor.
torch.is_inference_mode_enabled
Python Library Documentation: built-in function is_inference_mode_enabled in module torch
is_inference_mode_enabled(...)
is_inference_mode_enabled() -> (bool)
Returns True if inference mode is currently enabled.
torch.is_neg
Python Library Documentation: built-in function is_neg in module torch is_neg(...)
torch.is_nonzero
Python Library Documentation: built-in function is_nonzero in module torch
is_nonzero(...)
is_nonzero(input) -> (bool)
Returns True if the :attr:`input` is a single element tensor which is not equal to zero
after type conversions.
i.e. not equal to ``torch.tensor([0.])`` or ``torch.tensor([0])`` or
``torch.tensor([False])``.
Throws a ``RuntimeError`` if ``torch.numel() != 1`` (even in case
of sparse tensors).
Args:
input (Tensor): the input tensor.
Examples::
>>> torch.is_nonzero(torch.tensor([0.]))
False
>>> torch.is_nonzero(torch.tensor([1.5]))
True
>>> torch.is_nonzero(torch.tensor([False]))
False
>>> torch.is_nonzero(torch.tensor([3]))
True
>>> torch.is_nonzero(torch.tensor([1, 3, 5]))
Traceback (most recent call last):
...
RuntimeError: Boolean value of Tensor with more than one value is ambiguous
>>> torch.is_nonzero(torch.tensor([]))
Traceback (most recent call last):
...
RuntimeError: Boolean value of Tensor with no values is ambiguous
torch.is_same_size
Python Library Documentation: built-in function is_same_size in module torch is_same_size(...)
torch.is_signed
Python Library Documentation: built-in function is_signed in module torch is_signed(...)
torch.is_storage
Python Library Documentation: function is_storage in module torch
is_storage(obj: Any, /) -> TypeGuard[ForwardRef('TypedStorage | UntypedStorage')]
Returns True if `obj` is a PyTorch storage object.
Args:
obj (Object): Object to test
Example::
>>> import torch
>>> # UntypedStorage (recommended)
>>> tensor = torch.tensor([1, 2, 3])
>>> storage = tensor.untyped_storage()
>>> torch.is_storage(storage)
True
>>>
>>> # TypedStorage (legacy)
>>> typed_storage = torch.TypedStorage(5, dtype=torch.float32)
>>> torch.is_storage(typed_storage)
True
>>>
>>> # regular tensor (should return False)
>>> torch.is_storage(tensor)
False
>>>
>>> # non-storage object
>>> torch.is_storage([1, 2, 3])
False
torch.is_tensor
Python Library Documentation: function is_tensor in module torch
is_tensor(obj: Any, /) -> typing_extensions.TypeIs[ForwardRef('torch.Tensor')]
Returns True if `obj` is a PyTorch tensor.
Args:
obj (object): Object to test
Example::
>>> x = torch.tensor([1, 2, 3])
>>> torch.is_tensor(x)
True
torch.is_vulkan_available
Python Library Documentation: built-in function is_vulkan_available in module torch is_vulkan_available(...)
torch.is_warn_always_enabled
Python Library Documentation: function is_warn_always_enabled in module torch
is_warn_always_enabled() -> bool
Returns True if the global warn_always flag is turned on. Refer to
:func:`torch.set_warn_always` documentation for more details.
torch.isclose
Python Library Documentation: built-in function isclose in module torch
isclose(...)
isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
Returns a new tensor with boolean elements representing if each element of
:attr:`input` is "close" to the corresponding element of :attr:`other`.
Closeness is defined as:
.. math::
\lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{rtol} \times \lvert \text{other}_i \rvert + \texttt{atol}
where :attr:`input` and :attr:`other` are finite. Where :attr:`input`
and/or :attr:`other` are nonfinite they are close if and only if
they are equal, with NaNs being considered equal to each other when
:attr:`equal_nan` is True.
Args:
input (Tensor): first tensor to compare
other (Tensor): second tensor to compare
rtol (float, optional): relative tolerance. Default: 1e-05
atol (float, optional): absolute tolerance. Default: 1e-08
equal_nan (bool, optional): if ``True``, then two ``NaN`` s will be considered equal. Default: ``False``
Examples::
>>> torch.isclose(torch.tensor((1., 2, 3)), torch.tensor((1 + 1e-10, 3, 4)))
tensor([ True, False, False])
>>> torch.isclose(torch.tensor((float('inf'), 4)), torch.tensor((float('inf'), 6)), rtol=.5)
tensor([True, True])
torch.isfinite
Python Library Documentation: built-in function isfinite in module torch
isfinite(...)
isfinite(input) -> Tensor
Returns a new tensor with boolean elements representing if each element is `finite` or not.
Real values are finite when they are not NaN, negative infinity, or infinity.
Complex values are finite when both their real and imaginary parts are finite.
Args:
input (Tensor): the input tensor.
Returns:
A boolean tensor that is True where :attr:`input` is finite and False elsewhere
Example::
>>> torch.isfinite(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
tensor([True, False, True, False, False])
torch.isin
Python Library Documentation: built-in function isin in module torch
isin(...)
isin(elements, test_elements, *, assume_unique=False, invert=False) -> Tensor
Tests if each element of :attr:`elements` is in :attr:`test_elements`. Returns
a boolean tensor of the same shape as :attr:`elements` that is True for elements
in :attr:`test_elements` and False otherwise.
.. note::
One of :attr:`elements` or :attr:`test_elements` can be a scalar, but not both.
Args:
elements (Tensor or Scalar): Input elements
test_elements (Tensor or Scalar): Values against which to test for each input element
assume_unique (bool, optional): If True, assumes both :attr:`elements` and
:attr:`test_elements` contain unique elements, which can speed up the
calculation. Default: False
invert (bool, optional): If True, inverts the boolean return tensor, resulting in True
values for elements *not* in :attr:`test_elements`. Default: False
Returns:
A boolean tensor of the same shape as :attr:`elements` that is True for elements in
:attr:`test_elements` and False otherwise
Example:
>>> torch.isin(torch.tensor([[1, 2], [3, 4]]), torch.tensor([2, 3]))
tensor([[False, True],
[ True, False]])
torch.isinf
Python Library Documentation: built-in function isinf in module torch
isinf(...)
isinf(input) -> Tensor
Tests if each element of :attr:`input` is infinite
(positive or negative infinity) or not.
.. note::
Complex values are infinite when their real or imaginary part is
infinite.
Args:
input (Tensor): the input tensor.
Returns:
A boolean tensor that is True where :attr:`input` is infinite and False elsewhere
Example::
>>> torch.isinf(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
tensor([False, True, False, True, False])
torch.isnan
Python Library Documentation: built-in function isnan in module torch
isnan(...)
isnan(input) -> Tensor
Returns a new tensor with boolean elements representing if each element of :attr:`input`
is NaN or not. Complex values are considered NaN when either their real
and/or imaginary part is NaN.
Arguments:
input (Tensor): the input tensor.
Returns:
A boolean tensor that is True where :attr:`input` is NaN and False elsewhere
Example::
>>> torch.isnan(torch.tensor([1, float('nan'), 2]))
tensor([False, True, False])
torch.isneginf
Python Library Documentation: built-in function isneginf in module torch
isneginf(...)
isneginf(input, *, out=None) -> Tensor
Tests if each element of :attr:`input` is negative infinity or not.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([-float('inf'), float('inf'), 1.2])
>>> torch.isneginf(a)
tensor([ True, False, False])
torch.isposinf
Python Library Documentation: built-in function isposinf in module torch
isposinf(...)
isposinf(input, *, out=None) -> Tensor
Tests if each element of :attr:`input` is positive infinity or not.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([-float('inf'), float('inf'), 1.2])
>>> torch.isposinf(a)
tensor([False, True, False])
torch.isreal
Python Library Documentation: built-in function isreal in module torch
isreal(...)
isreal(input) -> Tensor
Returns a new tensor with boolean elements representing if each element of :attr:`input` is real-valued or not.
All real-valued types are considered real. Complex values are considered real when their imaginary part is 0.
Arguments:
input (Tensor): the input tensor.
Returns:
A boolean tensor that is True where :attr:`input` is real and False elsewhere
Example::
>>> torch.isreal(torch.tensor([1, 1+1j, 2+0j]))
tensor([True, False, True])
torch.istft
Python Library Documentation: built-in function istft in module torch
istft(...)
istft(input, n_fft, hop_length=None, win_length=None, window=None, center=True, normalized=False, onesided=None, length=None, return_complex=False) -> Tensor:
Inverse short time Fourier Transform. This is expected to be the inverse of :func:`~torch.stft`.
.. warning::
From version 2.1, a warning will be provided if a :attr:`window` is
not specified. In a future release, this attribute will be required.
Please provide the same window used in the stft call.
It has the same parameters (+ additional optional parameter of :attr:`length`) and it should return the
least squares estimation of the original signal. The algorithm will check using the NOLA condition (
nonzero overlap).
Important consideration in the parameters :attr:`window` and :attr:`center` so that the envelope
created by the summation of all the windows is never zero at certain point in time. Specifically,
:math:`\sum_{t=-\infty}^{\infty} |w|^2[n-t\times hop\_length] \cancel{=} 0`.
Since :func:`~torch.stft` discards elements at the end of the signal if they do not fit in a frame,
``istft`` may return a shorter signal than the original signal (can occur if :attr:`center` is False
since the signal isn't padded). If `length` is given in the arguments and is longer than expected,
``istft`` will pad zeros to the end of the returned signal.
If :attr:`center` is ``True``, then there will be padding e.g. ``'constant'``, ``'reflect'``, etc.
Left padding can be trimmed off exactly because they can be calculated but right padding cannot be
calculated without additional information.
Example: Suppose the last window is:
``[17, 18, 0, 0, 0]`` vs ``[18, 0, 0, 0, 0]``
The :attr:`n_fft`, :attr:`hop_length`, :attr:`win_length` are all the same which prevents the calculation
of right padding. These additional values could be zeros or a reflection of the signal so providing
:attr:`length` could be useful. If :attr:`length` is ``None`` then padding will be aggressively removed
(some loss of signal).
[1] D. W. Griffin and J. S. Lim, "Signal estimation from modified short-time Fourier transform,"
IEEE Trans. ASSP, vol.32, no.2, pp.236-243, Apr. 1984.
Args:
input (Tensor): The input tensor. Expected to be in the format of :func:`~torch.stft`,
output. That is a complex tensor of shape `(B?, N, T)` where
- `B?` is an optional batch dimension
- `N` is the number of frequency samples, `(n_fft // 2) + 1`
for onesided input, or otherwise `n_fft`.
- `T` is the number of frames, `1 + length // hop_length` for centered stft,
or `1 + (length - n_fft) // hop_length` otherwise.
.. versionchanged:: 2.0
Real datatype inputs are no longer supported. Input must now have a
complex datatype, as returned by ``stft(..., return_complex=True)``.
n_fft (int): Size of Fourier transform
hop_length (Optional[int]): The distance between neighboring sliding window frames.
(Default: ``n_fft // 4``)
win_length (Optional[int]): The size of window frame and STFT filter. (Default: ``n_fft``)
window (Optional[torch.Tensor]): The optional window function.
Shape must be 1d and `<= n_fft`
(Default: ``torch.ones(win_length)``)
center (bool): Whether :attr:`input` was padded on both sides so that the :math:`t`-th frame is
centered at time :math:`t \times \text{hop\_length}`.
(Default: ``True``)
normalized (bool): Whether the STFT was normalized. (Default: ``False``)
onesided (Optional[bool]): Whether the STFT was onesided.
(Default: ``True`` if `n_fft != fft_size` in the input size)
length (Optional[int]): The amount to trim the signal by (i.e. the
original signal length). Defaults to `(T - 1) * hop_length` for
centered stft, or `n_fft + (T - 1) * hop_length` otherwise, where `T`
is the number of input frames.
return_complex (Optional[bool]):
Whether the output should be complex, or if the input should be
assumed to derive from a real signal and window.
Note that this is incompatible with ``onesided=True``.
(Default: ``False``)
Returns:
Tensor: Least squares estimation of the original signal of shape `(B?, length)` where
`B?` is an optional batch dimension from the input tensor.
torch.jagged
Python Library Documentation: layout object class layout(builtins.object) | Methods defined here: | | __repr__(self, /) | Return repr(self).
torch.jit
Python Library Documentation: package torch.jit in torch
NAME
torch.jit - # mypy: allow-untyped-defs
PACKAGE CONTENTS
_async
_await
_builtins
_check
_dataclass_impls
_decomposition_utils
_decompositions
_freeze
_fuser
_ir_utils
_logging
_monkeytype_config
_passes (package)
_pickle
_recursive
_script
_serialization
_shape_functions
_state
_trace
annotations
frontend
generate_bytecode
mobile (package)
quantized
supported_ops
unsupported_tensor_ops
CLASSES
builtins.Exception(builtins.BaseException)
Error
builtins.object
strict_fusion
builtins.tuple(builtins.object)
torch.jit._script.Attribute
pybind11_builtins.pybind11_object(builtins.object)
CompilationUnit
ScriptFunction
torch.Future(pybind11_builtins.pybind11_object)
Future(torch.Future, typing.Generic)
torch.nn.modules.module.Module(builtins.object)
torch.jit._script.ScriptModule
typing.Generic(builtins.object)
Future(torch.Future, typing.Generic)
class Attribute(builtins.tuple)
| Attribute(value, type)
|
| This method is a pass-through function that returns `value`, mostly
| used to indicate to the TorchScript compiler that the left-hand side
| expression is a class instance attribute with type of `type`. Note that
| `torch.jit.Attribute` should only be used in `__init__` method of `jit.ScriptModule`
| subclasses.
|
| Though TorchScript can infer correct type for most Python expressions, there are some cases where
| type inference can be wrong, including:
|
| - Empty containers like `[]` and `{}`, which TorchScript assumes to be container of `Tensor`
| - Optional types like `Optional[T]` but assigned a valid value of type `T`, TorchScript would assume
| it is type `T` rather than `Optional[T]`
|
| In eager mode, it is simply a pass-through function that returns `value`
| without other implications.
|
| Example:
|
| .. testcode::
|
| import torch
| from typing import Dict
|
| class AttributeModule(torch.jit.ScriptModule):
| def __init__(self) -> None:
| super().__init__()
| self.foo = torch.jit.Attribute(0.1, float)
|
| # we should be able to use self.foo as a float here
| assert 0.0 < self.foo
|
| self.names_ages = torch.jit.Attribute({}, Dict[str, int])
| self.names_ages["someone"] = 20
| assert isinstance(self.names_ages["someone"], int)
|
| m = AttributeModule()
| # m will contain two attributes
| # 1. foo of type float
| # 2. names_ages of type Dict[str, int]
|
| .. testcleanup::
|
| del AttributeModule
| del m
|
| Note: it's now preferred to instead use type annotations instead of `torch.jit.Attribute`:
|
| .. testcode::
|
| import torch
| from typing import Dict
|
| class AttributeModule(torch.nn.Module):
| names: Dict[str, int]
|
| def __init__(self) -> None:
| super().__init__()
| self.names = {}
|
| m = AttributeModule()
|
| .. testcleanup::
|
| del AttributeModule
| del m
|
| Args:
| value: An initial value to be assigned to attribute.
| type: A Python type
|
| Returns:
| Returns `value`
|
| Method resolution order:
| Attribute
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __getnewargs__(self) from collections.Attribute
| Return self as a plain tuple. Used by copy and pickle.
|
| __repr__(self) from collections.Attribute
| Return a nicely formatted representation string
|
| _asdict(self) from collections.Attribute
| Return a new dict which maps field names to their values.
|
| _replace(self, /, **kwds) from collections.Attribute
| Return a new Attribute object replacing specified fields with new values
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| _make(iterable) from collections.Attribute
| Make a new Attribute object from a sequence or iterable
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(_cls, value, type) from namedtuple_Attribute.Attribute
| Create new instance of Attribute(value, type)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| value
| Alias for field number 0
|
| type
| Alias for field number 1
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('value', 'type')
|
| _field_defaults = {}
|
| _fields = ('value', 'type')
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class CompilationUnit(pybind11_builtins.pybind11_object)
| Method resolution order:
| CompilationUnit
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __getattr__(...)
| __getattr__(self: torch._C.CompilationUnit, arg0: str) -> torch::jit::StrongFunctionPtr
|
| __init__(...)
| __init__(self: torch._C.CompilationUnit, lang: str = '', _frames_up: typing.SupportsInt | typing.SupportsIndex = 0) -> None
|
| create_function(...)
| create_function(self: torch._C.CompilationUnit, qualified_name: str, graph: torch._C.Graph, should_mangle: bool = False) -> torch::jit::StrongFunctionPtr
|
| define(...)
| define(self: torch._C.CompilationUnit, src: str, rcb: collections.abc.Callable[[str], object] = None, _frames_up: typing.SupportsInt | typing.SupportsIndex = 0) -> None
|
| drop_all_functions(...)
| drop_all_functions(self: torch._C.CompilationUnit) -> None
|
| find_function(...)
| find_function(self: torch._C.CompilationUnit, arg0: str) -> torch::jit::StrongFunctionPtr | None
|
| get_class(...)
| get_class(self: torch._C.CompilationUnit, arg0: str) -> torch._C.ClassType
|
| get_functions(...)
| get_functions(self: torch._C.CompilationUnit) -> list[torch::jit::StrongFunctionPtr]
|
| get_interface(...)
| get_interface(self: torch._C.CompilationUnit, arg0: str) -> torch._C.InterfaceType
|
| set_optimized(...)
| set_optimized(self: torch._C.CompilationUnit, arg0: bool) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Error(builtins.Exception)
| Method resolution order:
| Error
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class Future(torch.Future, typing.Generic)
| Future(*, devices: 'list[int | str | torch.device] | None' = None)
|
| Wrapper around a ``torch._C.Future`` which encapsulates an asynchronous
| execution of a callable, e.g. :meth:`~torch.distributed.rpc.rpc_async`. It
| also exposes a set of APIs to add callback functions and set results.
|
| .. warning:: GPU support is a beta feature, subject to changes.
|
| Method resolution order:
| Future
| torch.Future
| pybind11_builtins.pybind11_object
| typing.Generic
| builtins.object
|
| Methods defined here:
|
| __init__(self, *, devices: 'list[int | str | torch.device] | None' = None) from torch.futures.Future
| Create an empty unset ``Future``. If the future is intended to hold
| values containing CUDA tensors, (a superset of) their CUDA devices must
| be specified at construction. (This is only supported if
| ``torch.cuda.is_available()`` returns ``True``). This is needed to
| ensure proper CUDA stream synchronization. The child futures, returned
| by the ``then`` method, will inherit these devices.
|
| Args:
| devices(``List[Union[int, str, torch.device]]``, optional): the set
| of devices on which tensors contained in this future's value are
| allowed to reside and on which callbacks are allowed to operate.
|
| add_done_callback(self, callback: 'Callable[[Future[T]], None]') -> 'None' from torch.futures.Future
| Append the given callback function to this ``Future``, which will be run
| when the ``Future`` is completed. Multiple callbacks can be added to
| the same ``Future``, but the order in which they will be executed cannot
| be guaranteed. The callback must take one argument, which is the
| reference to this ``Future``. The callback function can use the
| :meth:`value` method to get the value. Note that if this ``Future`` is
| already completed, the given callback will be run inline.
|
| We recommend that you use the :meth:`then` method as it provides a way
| to synchronize after your callback has completed. ``add_done_callback``
| can be cheaper if your callback does not return anything. But both
| :meth:`then` and ``add_done_callback`` use the same callback
| registration API under the hood.
|
| With respect to GPU tensors, this method behaves in the same way as
| :meth:`then`.
|
| Args:
| callback(``Future``): a ``Callable`` that takes in one argument,
| which is the reference to this ``Future``.
|
| .. note:: Note that if the callback function throws, either
| through the original future being completed with an exception and
| calling ``fut.wait()``, or through other code in the callback,
| error handling must be carefully taken care of. For example, if
| this callback later completes additional futures, those futures are
| not marked as completed with an error and the user is responsible
| for handling completion/waiting on those futures independently.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_FUTURES)
| >>> def callback(fut):
| ... print("This will run after the future has finished.")
| ... print(fut.wait())
| >>> fut = torch.futures.Future()
| >>> fut.add_done_callback(callback)
| >>> fut.set_result(5)
| This will run after the future has finished.
| 5
|
| done(self) -> 'bool' from torch.futures.Future
| Return ``True`` if this ``Future`` is done. A ``Future`` is done if it
| has a result or an exception.
|
| If the value contains tensors that reside on GPUs, ``Future.done()``
| will return ``True`` even if the asynchronous kernels that are
| populating those tensors haven't yet completed running on the device,
| because at such stage the result is already usable, provided one
| performs the appropriate synchronizations (see :meth:`wait`).
|
| set_exception(self, result: 'T') -> 'None' from torch.futures.Future
| Set an exception for this ``Future``, which will mark this ``Future`` as
| completed with an error and trigger all attached callbacks. Note that
| when calling wait()/value() on this ``Future``, the exception set here
| will be raised inline.
|
| Args:
| result (BaseException): the exception for this ``Future``.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_FUTURES)
| >>> fut = torch.futures.Future()
| >>> fut.set_exception(ValueError("foo"))
| >>> fut.wait()
| Traceback (most recent call last):
| ...
| ValueError: foo
|
| set_result(self, result: 'T') -> 'None' from torch.futures.Future
| Set the result for this ``Future``, which will mark this ``Future`` as
| completed and trigger all attached callbacks. Note that a ``Future``
| cannot be marked completed twice.
|
| If the result contains tensors that reside on GPUs, this method can be
| called even if the asynchronous kernels that are populating those
| tensors haven't yet completed running on the device, provided that the
| streams on which those kernels were enqueued are set as the current ones
| when this method is called. Put simply, it's safe to call this method
| immediately after launching those kernels, without any additional
| synchronization, as long as one doesn't change streams in between. This
| method will record events on all the relevant current streams and will
| use them to ensure proper scheduling for all the consumers of this
| ``Future``.
|
| Args:
| result (object): the result object of this ``Future``.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_FUTURES)
| >>> import threading
| >>> import time
| >>> def slow_set_future(fut, value):
| ... time.sleep(0.5)
| ... fut.set_result(value)
| >>> fut = torch.futures.Future()
| >>> t = threading.Thread(
| ... target=slow_set_future,
| ... args=(fut, torch.ones(2) * 3)
| ... )
| >>> t.start()
| >>> print(fut.wait())
| tensor([3., 3.])
| >>> t.join()
|
| then(self, callback: 'Callable[[Future[T]], S]') -> 'Future[S]' from torch.futures.Future
| Append the given callback function to this ``Future``, which will be run
| when the ``Future`` is completed. Multiple callbacks can be added to
| the same ``Future``, but the order in which they will be executed cannot
| be guaranteed (to enforce a certain order consider chaining:
| ``fut.then(cb1).then(cb2)``). The callback must take one argument, which
| is the reference to this ``Future``. The callback function can use the
| :meth:`value` method to get the value. Note that if this ``Future`` is
| already completed, the given callback will be run immediately inline.
|
| If the ``Future``'s value contains tensors that reside on GPUs, the
| callback might be invoked while the async kernels that are populating
| those tensors haven't yet finished executing on the device. However, the
| callback will be invoked with some dedicated streams set as current
| (fetched from a global pool) which will be synchronized with those
| kernels. Hence any operation performed by the callback on these tensors
| will be scheduled on the device after the kernels complete. In other
| words, as long as the callback doesn't switch streams, it can safely
| manipulate the result without any additional synchronization. This is
| similar to the non-blocking behavior of :meth:`wait`.
|
| Similarly, if the callback returns a value that contains tensors that
| reside on a GPU, it can do so even if the kernels that are producing
| these tensors are still running on the device, as long as the callback
| didn't change streams during its execution. If one wants to change
| streams, one must be careful to re-synchronize them with the original
| streams, that is, those that were current when the callback was invoked.
|
| Args:
| callback(``Callable``): a ``Callable`` that takes this ``Future`` as
| the only argument.
|
| Returns:
| A new ``Future`` object that holds the return value of the
| ``callback`` and will be marked as completed when the given
| ``callback`` finishes.
|
| .. note:: Note that if the callback function throws, either
| through the original future being completed with an exception and
| calling ``fut.wait()``, or through other code in the callback, the
| future returned by ``then`` will be marked appropriately with the
| encountered error. However, if this callback later completes
| additional futures, those futures are not marked as completed with
| an error and the user is responsible for handling completion/waiting
| on those futures independently.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_FUTURES)
| >>> def callback(fut):
| ... print(f"RPC return value is {fut.wait()}.")
| >>> fut = torch.futures.Future()
| >>> # The inserted callback will print the return value when
| >>> # receiving the response from "worker1"
| >>> cb_fut = fut.then(callback)
| >>> chain_cb_fut = cb_fut.then(
| ... lambda x : print(f"Chained cb done. {x.wait()}")
| ... )
| >>> fut.set_result(5)
| RPC return value is 5.
| Chained cb done. None
|
| value(self) -> 'T' from torch.futures.Future
| Obtain the value of an already-completed future.
|
| This method should only be called after a call to :meth:`wait` has
| completed, or inside a callback function passed to :meth:`then`. In
| other cases this ``Future`` may not yet hold a value and calling
| ``value()`` could fail.
|
| If the value contains tensors that reside on GPUs, then this method will
| *not* perform any additional synchronization. This should be done
| beforehand, separately, through a call to :meth:`wait` (except within
| callbacks, for which it's already being taken care of by :meth:`then`).
|
| Returns:
| The value held by this ``Future``. If the function (callback or RPC)
| creating the value has thrown an error, this ``value()`` method will
| also throw an error.
|
| wait(self) -> 'T' from torch.futures.Future
| Block until the value of this ``Future`` is ready.
|
| If the value contains tensors that reside on GPUs, then an additional
| synchronization is performed with the kernels (executing on the device)
| which may be asynchronously populating those tensors. Such sync is
| non-blocking, which means that ``wait()`` will insert the necessary
| instructions in the current streams to ensure that further operations
| enqueued on those streams will be properly scheduled after the async
| kernels but, once that is done, ``wait()`` will return, even if those
| kernels are still running. No further synchronization is required when
| accessing and using the values, as long as one doesn't change streams.
|
| Returns:
| The value held by this ``Future``. If the function (callback or RPC)
| creating the value has thrown an error, this ``wait`` method will
| also throw an error.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __orig_bases__ = (<class 'torch.Future'>, typing.Generic[~T])
|
| __parameters__ = (~T,)
|
| ----------------------------------------------------------------------
| Methods inherited from torch.Future:
|
| __getstate__(...)
| __getstate__(self: torch._C.Future, /) -> tuple
|
| __setstate__(...)
| __setstate__(self: torch._C.Future, arg0: tuple) -> None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Class methods inherited from typing.Generic:
|
| __class_getitem__(...)
| Parameterizes a generic class.
|
| At least, parameterizing a generic class is the *main* thing this
| method does. For example, for some generic class `Foo`, this is called
| when we do `Foo[int]` - there, with `cls=Foo` and `params=int`.
|
| However, note that this method is also called when defining generic
| classes in the first place with `class Foo[T]: ...`.
|
| __init_subclass__(...)
| Function to initialize subclasses.
class ScriptFunction(pybind11_builtins.pybind11_object)
| Functionally equivalent to a :class:`ScriptModule`, but represents a single
| function and does not have any attributes or Parameters.
|
| Method resolution order:
| ScriptFunction
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __call__(...)
| __call__(*args, **kwargs) -> object
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce__ = _reduce(cls) from torch.jit._script
| # Throws an error if a jit function is pickled.
| # Helps to avoid Python crashes for Python versions 3.9.5 + when protocol 0 or 1 is given as an argument.
|
| get_debug_state(...)
| get_debug_state(self: torch._C.ScriptFunction) -> torch._C.GraphExecutorState
|
| graph_for = _graph_for(self, *args, **kwargs) from torch.jit._fuser
|
| save(...)
| save(self: torch._C.ScriptFunction, filename: str, _extra_files: collections.abc.Mapping[str, str] = {}) -> None
|
| save_to_buffer(...)
| save_to_buffer(self: torch._C.ScriptFunction, _extra_files: collections.abc.Mapping[str, str] = {}) -> bytes
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| code
|
| graph
|
| inlined_graph
|
| name
|
| qualified_name
|
| schema
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptModule(torch.nn.modules.module.Module)
| ScriptModule() -> None
|
| Wrapper for C++ torch::jit::Module with methods, attributes, and parameters.
|
| A wrapper around C++ ``torch::jit::Module``. ``ScriptModule``\s
| contain methods, attributes, parameters, and
| constants. These can be accessed the same way as on a normal ``nn.Module``.
|
| Method resolution order:
| ScriptModule
| torch.nn.modules.module.Module
| builtins.object
|
| Methods defined here:
|
| __getattr__(self, attr: str) -> Any
|
| __init__(self) -> None
| Initialize internal Module state, shared by both nn.Module and ScriptModule.
|
| __reduce_package__(self, exporter: torch.package.package_exporter.PackageExporter)
| Save a ScriptModule inside of a ``torch.package`` archive.
|
| Called by ``torch.package.PackageExporter``'s Pickler's ``persistent_id`` when
| saving TorchScript objects. Performs act of saving a ScriptModule inside of
| a ``torch.package`` archive.
|
| Returns method to load the ScriptModule from a ``torch.package.PackageImporter``'s
| Pickler's ``persistent_load`` function.
|
| __setattr__(self, attr: str, value: Any) -> None
| Implement setattr(self, name, value).
|
| define(self, src)
|
| forward
|
| forward_magic_method(self, method_name: str, *args: Any, **kwargs: Any) -> Any from torch.jit._script.RecursiveScriptModule
| # Python magic methods do method lookups on an object's class type, instead of looking up
| # the method defines on the class instance. In order to continue to expose the magic methods
| # of builtin-containers (ModuleList, Sequential, ModuleDict) to Python, we
| # define magic methods here as a shim to the correct attribute.
|
| get_debug_state(self, *args: Any, **kwargs: Any) -> Any from torch.jit._script.RecursiveScriptModule
|
| graph_for(self, *args: Any, **kwargs: Any) -> Any from torch.jit._script.RecursiveScriptModule
|
| save(self, f, **kwargs) from torch.jit._script.RecursiveScriptModule
| Save with a file-like object.
|
| save(f, _extra_files={})
|
| See :func:`torch.jit.save <torch.jit.save>` which accepts a file-like object.
| This function, torch.save(), converts the object to a string, treating it as a path.
| DO NOT confuse these two functions when it comes to the 'f' parameter functionality.
|
| save_to_buffer(self, *args: Any, **kwargs: Any) -> Any from torch.jit._script.RecursiveScriptModule
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| code
| Return a pretty-printed representation (as valid Python syntax) of the internal graph for the ``forward`` method.
|
| code_with_constants
| Return a tuple.
|
| Returns a tuple of:
|
| [0] a pretty-printed representation (as valid Python syntax) of
| the internal graph for the ``forward`` method. See `code`.
| [1] a ConstMap following the CONSTANT.cN format of the output in [0].
| The indices in the [0] output are keys to the underlying constant's values.
|
| graph
| Return a string representation of the internal graph for the ``forward`` method.
|
| inlined_graph
| Return a string representation of the internal graph for the ``forward`` method.
|
| This graph will be preprocessed to inline all function and method calls.
|
| original_name
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'forward': collections.abc.Callable[..., typing.Any...
|
| __jit_unused_properties__ = ['code', 'code_with_constants', 'graph', '...
|
| ----------------------------------------------------------------------
| Methods inherited from torch.nn.modules.module.Module:
|
| __call__ = _wrapped_call_impl(self, *args, **kwargs)
|
| __delattr__(self, name) -> None
| Implement delattr(self, name).
|
| __dir__(self)
| Default dir() implementation.
|
| __getstate__(self)
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setstate__(self, state)
|
| add_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Add a child module to the current module.
|
| The module can be accessed as an attribute using the given name.
|
| Args:
| name (str): name of the child module. The child module can be
| accessed from this module using the given name
| module (Module): child module to be added to the module.
|
| apply(self, fn: collections.abc.Callable[['Module'], None]) -> Self
| Apply ``fn`` recursively to every submodule (as returned by ``.children()``) as well as self.
|
| Typical use includes initializing the parameters of a model
| (see also :ref:`nn-init-doc`).
|
| Args:
| fn (:class:`Module` -> None): function to be applied to each submodule
|
| Returns:
| Module: self
|
| Example::
|
| >>> @torch.no_grad()
| >>> def init_weights(m):
| >>> print(m)
| >>> if type(m) is nn.Linear:
| >>> m.weight.fill_(1.0)
| >>> print(m.weight)
| >>> net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
| >>> net.apply(init_weights)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
|
| bfloat16(self) -> Self
| Casts all floating point parameters and buffers to ``bfloat16`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| buffers(self, recurse: bool = True) -> collections.abc.Iterator[torch.Tensor]
| Return an iterator over module buffers.
|
| Args:
| recurse (bool): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module.
|
| Yields:
| torch.Tensor: module buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for buf in model.buffers():
| >>> print(type(buf), buf.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| children(self) -> collections.abc.Iterator['Module']
| Return an iterator over immediate children modules.
|
| Yields:
| Module: a child module
|
| compile(self, *args, **kwargs) -> None
| Compile this Module's forward using :func:`torch.compile`.
|
| This Module's `__call__` method is compiled and all arguments are passed as-is
| to :func:`torch.compile`.
|
| See :func:`torch.compile` for details on the arguments for this function.
|
| cpu(self) -> Self
| Move all model parameters and buffers to the CPU.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| cuda(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the GPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on GPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| double(self) -> Self
| Casts all floating point parameters and buffers to ``double`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| eval(self) -> Self
| Set the module in evaluation mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e. whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| This is equivalent with :meth:`self.train(False) <torch.nn.Module.train>`.
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.eval()` and several similar mechanisms that may be confused with it.
|
| Returns:
| Module: self
|
| extra_repr(self) -> str
| Return the extra representation of the module.
|
| To print customized extra information, you should re-implement
| this method in your own modules. Both single-line and multi-line
| strings are acceptable.
|
| float(self) -> Self
| Casts all floating point parameters and buffers to ``float`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| get_buffer(self, target: str) -> torch.Tensor
| Return the buffer given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the buffer
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.Tensor: The buffer referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not a
| buffer
|
| get_extra_state(self) -> Any
| Return any extra state to include in the module's state_dict.
|
| Implement this and a corresponding :func:`set_extra_state` for your module
| if you need to store extra state. This function is called when building the
| module's `state_dict()`.
|
| Note that extra state should be picklable to ensure working serialization
| of the state_dict. We only provide backwards compatibility guarantees
| for serializing Tensors; other objects may break backwards compatibility if
| their serialized pickled form changes.
|
| Returns:
| object: Any extra state to store in the module's state_dict
|
| get_parameter(self, target: str) -> torch.nn.parameter.Parameter
| Return the parameter given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the Parameter
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Parameter: The Parameter referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not an
| ``nn.Parameter``
|
| get_submodule(self, target: str) -> 'Module'
| Return the submodule given by ``target`` if it exists, otherwise throw an error.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(16, 33, kernel_size=(3, 3), stride=(2, 2))
| )
| (linear): Linear(in_features=100, out_features=200, bias=True)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` which has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To check whether or not we have the ``linear`` submodule, we
| would call ``get_submodule("net_b.linear")``. To check whether
| we have the ``conv`` submodule, we would call
| ``get_submodule("net_b.net_c.conv")``.
|
| The runtime of ``get_submodule`` is bounded by the degree
| of module nesting in ``target``. A query against
| ``named_modules`` achieves the same result, but it is O(N) in
| the number of transitive modules. So, for a simple check to see
| if some submodule exists, ``get_submodule`` should always be
| used.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Module: The submodule referenced by ``target``
|
| Raises:
| AttributeError: If at any point along the path resulting from
| the target string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| half(self) -> Self
| Casts all floating point parameters and buffers to ``half`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| ipu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the IPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on IPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| load_state_dict(self, state_dict: collections.abc.Mapping[str, typing.Any], strict: bool = True, assign: bool = False)
| Copy parameters and buffers from :attr:`state_dict` into this module and its descendants.
|
| If :attr:`strict` is ``True``, then
| the keys of :attr:`state_dict` must exactly match the keys returned
| by this module's :meth:`~torch.nn.Module.state_dict` function.
|
| .. warning::
| If :attr:`assign` is ``True`` the optimizer must be created after
| the call to :attr:`load_state_dict` unless
| :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| Args:
| state_dict (dict): a dict containing parameters and
| persistent buffers.
| strict (bool, optional): whether to strictly enforce that the keys
| in :attr:`state_dict` match the keys returned by this module's
| :meth:`~torch.nn.Module.state_dict` function. Default: ``True``
| assign (bool, optional): When set to ``False``, the properties of the tensors
| in the current module are preserved whereas setting it to ``True`` preserves
| properties of the Tensors in the state dict. The only
| exception is the ``requires_grad`` field of :class:`~torch.nn.Parameter`
| for which the value from the module is preserved. Default: ``False``
|
| Returns:
| ``NamedTuple`` with ``missing_keys`` and ``unexpected_keys`` fields:
| * ``missing_keys`` is a list of str containing any keys that are expected
| by this module but missing from the provided ``state_dict``.
| * ``unexpected_keys`` is a list of str containing the keys that are not
| expected by this module but present in the provided ``state_dict``.
|
| Note:
| If a parameter or buffer is registered as ``None`` and its corresponding key
| exists in :attr:`state_dict`, :meth:`load_state_dict` will raise a
| ``RuntimeError``.
|
| modules(self, remove_duplicate: bool = True) -> collections.abc.Iterator['Module']
| Return an iterator over all modules in the network.
|
| Args:
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not.
|
| Yields:
| Module: a module in the network
|
| Note:
| Duplicate modules are returned only once by default. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.modules()):
| ... print(idx, '->', m)
|
| 0 -> Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
| 1 -> Linear(in_features=2, out_features=2, bias=True)
|
| mtia(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the MTIA.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on MTIA while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| named_buffers(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.Tensor]]
| Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
|
| Args:
| prefix (str): prefix to prepend to all buffer names.
| recurse (bool, optional): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module. Defaults to True.
| remove_duplicate (bool, optional): whether to remove the duplicated buffers in the result. Defaults to True.
|
| Yields:
| (str, torch.Tensor): Tuple containing the name and buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, buf in self.named_buffers():
| >>> if name in ['running_var']:
| >>> print(buf.size())
|
| named_children(self) -> collections.abc.Iterator[tuple[str, 'Module']]
| Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
|
| Yields:
| (str, Module): Tuple containing a name and child module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, module in model.named_children():
| >>> if name in ['conv4', 'conv5']:
| >>> print(module)
|
| named_modules(self, memo: set['Module'] | None = None, prefix: str = '', remove_duplicate: bool = True)
| Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
|
| Args:
| memo: a memo to store the set of modules already added to the result
| prefix: a prefix that will be added to the name of the module
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not
|
| Yields:
| (str, Module): Tuple of name and module
|
| Note:
| Duplicate modules are returned only once. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.named_modules()):
| ... print(idx, '->', m)
|
| 0 -> ('', Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| ))
| 1 -> ('0', Linear(in_features=2, out_features=2, bias=True))
|
| named_parameters(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.nn.parameter.Parameter]]
| Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
|
| Args:
| prefix (str): prefix to prepend to all parameter names.
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
| remove_duplicate (bool, optional): whether to remove the duplicated
| parameters in the result. Defaults to True.
|
| Yields:
| (str, Parameter): Tuple containing the name and parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, param in self.named_parameters():
| >>> if name in ['bias']:
| >>> print(param.size())
|
| parameters(self, recurse: bool = True) -> collections.abc.Iterator[torch.nn.parameter.Parameter]
| Return an iterator over module parameters.
|
| This is typically passed to an optimizer.
|
| Args:
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
|
| Yields:
| Parameter: module parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for param in model.parameters():
| >>> print(type(param), param.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| register_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None]) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| This function is deprecated in favor of :meth:`~torch.nn.Module.register_full_backward_hook` and
| the behavior of this function will change in future versions.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_buffer(self, name: str, tensor: torch.Tensor | None, persistent: bool = True) -> None
| Add a buffer to the module.
|
| This is typically used to register a buffer that should not be
| considered a model parameter. For example, BatchNorm's ``running_mean``
| is not a parameter, but is part of the module's state. Buffers, by
| default, are persistent and will be saved alongside parameters. This
| behavior can be changed by setting :attr:`persistent` to ``False``. The
| only difference between a persistent buffer and a non-persistent buffer
| is that the latter will not be a part of this module's
| :attr:`state_dict`.
|
| Buffers can be accessed as attributes using given names.
|
| Args:
| name (str): name of the buffer. The buffer can be accessed
| from this module using the given name
| tensor (Tensor or None): buffer to be registered. If ``None``, then operations
| that run on buffers, such as :attr:`cuda`, are ignored. If ``None``,
| the buffer is **not** included in the module's :attr:`state_dict`.
| persistent (bool): whether the buffer is part of this module's
| :attr:`state_dict`.
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> self.register_buffer('running_mean', torch.zeros(num_features))
|
| register_forward_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...], typing.Any], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any], typing.Any], typing.Any | None], *, prepend: bool = False, with_kwargs: bool = False, always_call: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward hook on the module.
|
| The hook will be called every time after :func:`forward` has computed an output.
|
| If ``with_kwargs`` is ``False`` or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| output. It can modify the input inplace but it will not have effect on
| forward since this is called after :func:`forward` is called. The hook
| should have the following signature::
|
| hook(module, args, output) -> None or modified output
|
| If ``with_kwargs`` is ``True``, the forward hook will be passed the
| ``kwargs`` given to the forward function and be expected to return the
| output possibly modified. The hook should have the following signature::
|
| hook(module, args, kwargs, output) -> None or modified output
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If ``True``, the provided ``hook`` will be fired
| before all existing ``forward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``forward`` hooks registered with
| :func:`register_module_forward_hook` will fire before all hooks
| registered by this method.
| Default: ``False``
| with_kwargs (bool): If ``True``, the ``hook`` will be passed the
| kwargs given to the forward function.
| Default: ``False``
| always_call (bool): If ``True`` the ``hook`` will be run regardless of
| whether an exception is raised while calling the Module.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_forward_pre_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...]], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[typing.Any, dict[str, typing.Any]] | None], *, prepend: bool = False, with_kwargs: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward pre-hook on the module.
|
| The hook will be called every time before :func:`forward` is invoked.
|
|
| If ``with_kwargs`` is false or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| input. User can either return a tuple or a single modified value in the
| hook. We will wrap the value into a tuple if a single value is returned
| (unless that value is already a tuple). The hook should have the
| following signature::
|
| hook(module, args) -> None or modified input
|
| If ``with_kwargs`` is true, the forward pre-hook will be passed the
| kwargs given to the forward function. And if the hook modifies the
| input, both the args and kwargs should be returned. The hook should have
| the following signature::
|
| hook(module, args, kwargs) -> None or a tuple of modified input and kwargs
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``forward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``forward_pre`` hooks registered with
| :func:`register_module_forward_pre_hook` will fire before all
| hooks registered by this method.
| Default: ``False``
| with_kwargs (bool): If true, the ``hook`` will be passed the kwargs
| given to the forward function.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| The hook will be called every time the gradients with respect to a module are computed, and its firing rules are as follows:
|
| 1. Ordinarily, the hook fires when the gradients are computed with respect to the module inputs.
| 2. If none of the module inputs require gradients, the hook will fire when the gradients are computed
| with respect to module outputs.
| 3. If none of the module outputs require gradients, then the hooks will not fire.
|
| The hook should have the following signature::
|
| hook(module, grad_input, grad_output) -> tuple(Tensor) or None
|
| The :attr:`grad_input` and :attr:`grad_output` are tuples that contain the gradients
| with respect to the inputs and outputs respectively. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the input that will be used in place of :attr:`grad_input` in
| subsequent computations. :attr:`grad_input` will only correspond to the inputs given
| as positional arguments and all kwarg arguments are ignored. Entries
| in :attr:`grad_input` and :attr:`grad_output` will be ``None`` for all non-Tensor
| arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs or outputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``backward`` hooks registered with
| :func:`register_module_full_backward_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_pre_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward pre-hook on the module.
|
| The hook will be called every time the gradients for the module are computed.
| The hook should have the following signature::
|
| hook(module, grad_output) -> tuple[Tensor, ...], Tensor or None
|
| The :attr:`grad_output` is a tuple. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the output that will be used in place of :attr:`grad_output` in
| subsequent computations. Entries in :attr:`grad_output` will be ``None`` for
| all non-Tensor arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``backward_pre`` hooks registered with
| :func:`register_module_full_backward_pre_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_post_hook(self, hook)
| Register a post-hook to be run after module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, incompatible_keys) -> None
|
| The ``module`` argument is the current module that this hook is registered
| on, and the ``incompatible_keys`` argument is a ``NamedTuple`` consisting
| of attributes ``missing_keys`` and ``unexpected_keys``. ``missing_keys``
| is a ``list`` of ``str`` containing the missing keys and
| ``unexpected_keys`` is a ``list`` of ``str`` containing the unexpected keys.
|
| The given incompatible_keys can be modified inplace if needed.
|
| Note that the checks performed when calling :func:`load_state_dict` with
| ``strict=True`` are affected by modifications the hook makes to
| ``missing_keys`` or ``unexpected_keys``, as expected. Additions to either
| set of keys will result in an error being thrown when ``strict=True``, and
| clearing out both missing and unexpected keys will avoid an error.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook)
| Register a pre-hook to be run before module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) -> None # noqa: B950
|
| Arguments:
| hook (Callable): Callable hook that will be invoked before
| loading the state dict.
|
| register_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Alias for :func:`add_module`.
|
| register_parameter(self, name: str, param: torch.nn.parameter.Parameter | None) -> None
| Add a parameter to the module.
|
| The parameter can be accessed as an attribute using given name.
|
| Args:
| name (str): name of the parameter. The parameter can be accessed
| from this module using the given name
| param (Parameter or None): parameter to be added to the module. If
| ``None``, then operations that run on parameters, such as :attr:`cuda`,
| are ignored. If ``None``, the parameter is **not** included in the
| module's :attr:`state_dict`.
|
| register_state_dict_post_hook(self, hook)
| Register a post-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata) -> None
|
| The registered hooks can modify the ``state_dict`` inplace.
|
| register_state_dict_pre_hook(self, hook)
| Register a pre-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, prefix, keep_vars) -> None
|
| The registered hooks can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| requires_grad_(self, requires_grad: bool = True) -> Self
| Change if autograd should record operations on parameters in this module.
|
| This method sets the parameters' :attr:`requires_grad` attributes
| in-place.
|
| This method is helpful for freezing part of the module for finetuning
| or training parts of a model individually (e.g., GAN training).
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.requires_grad_()` and several similar mechanisms that may be confused with it.
|
| Args:
| requires_grad (bool): whether autograd should record operations on
| parameters in this module. Default: ``True``.
|
| Returns:
| Module: self
|
| set_extra_state(self, state: Any) -> None
| Set extra state contained in the loaded `state_dict`.
|
| This function is called from :func:`load_state_dict` to handle any extra state
| found within the `state_dict`. Implement this function and a corresponding
| :func:`get_extra_state` for your module if you need to store extra state within its
| `state_dict`.
|
| Args:
| state (dict): Extra state from the `state_dict`
|
| set_submodule(self, target: str, module: 'Module', strict: bool = False) -> None
| Set the submodule given by ``target`` if it exists, otherwise throw an error.
|
| .. note::
| If ``strict`` is set to ``False`` (default), the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``strict`` is set to ``True``,
| the method will only attempt to replace an existing submodule and throw an error if
| the submodule does not exist.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(3, 3, 3)
| )
| (linear): Linear(3, 3)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To override the ``Conv2d`` with a new submodule ``Linear``, you
| could call ``set_submodule("net_b.net_c.conv", nn.Linear(1, 1))``
| where ``strict`` could be ``True`` or ``False``
|
| To add a new submodule ``Conv2d`` to the existing ``net_b`` module,
| you would call ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1))``.
|
| In the above if you set ``strict=True`` and call
| ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1), strict=True)``, an AttributeError
| will be raised because ``net_b`` does not have a submodule named ``conv``.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
| module: The module to set the submodule to.
| strict: If ``False``, the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``True``,
| the method will only attempt to replace an existing submodule and throw an error
| if the submodule doesn't already exist.
|
| Raises:
| ValueError: If the ``target`` string is empty or if ``module`` is not an instance of ``nn.Module``.
| AttributeError: If at any point along the path resulting from
| the ``target`` string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| share_memory(self) -> Self
| See :meth:`torch.Tensor.share_memory_`.
|
| state_dict(self, *args, destination=None, prefix='', keep_vars=False)
| Return a dictionary containing references to the whole state of the module.
|
| Both parameters and persistent buffers (e.g. running averages) are
| included. Keys are corresponding parameter and buffer names.
| Parameters and buffers set to ``None`` are not included.
|
| .. note::
| The returned object is a shallow copy. It contains references
| to the module's parameters and buffers.
|
| .. warning::
| Currently ``state_dict()`` also accepts positional arguments for
| ``destination``, ``prefix`` and ``keep_vars`` in order. However,
| this is being deprecated and keyword arguments will be enforced in
| future releases.
|
| .. warning::
| Please avoid the use of argument ``destination`` as it is not
| designed for end-users.
|
| Args:
| destination (dict, optional): If provided, the state of module will
| be updated into the dict and the same object is returned.
| Otherwise, an ``OrderedDict`` will be created and returned.
| Default: ``None``.
| prefix (str, optional): a prefix added to parameter and buffer
| names to compose the keys in state_dict. Default: ``''``.
| keep_vars (bool, optional): by default the :class:`~torch.Tensor` s
| returned in the state dict are detached from autograd. If it's
| set to ``True``, detaching will not be performed.
| Default: ``False``.
|
| Returns:
| dict:
| a dictionary containing a whole state of the module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> module.state_dict().keys()
| ['bias', 'weight']
|
| to(self, *args, **kwargs)
| Move and/or cast the parameters and buffers.
|
| This can be called as
|
| .. function:: to(device=None, dtype=None, non_blocking=False)
| :noindex:
|
| .. function:: to(dtype, non_blocking=False)
| :noindex:
|
| .. function:: to(tensor, non_blocking=False)
| :noindex:
|
| .. function:: to(memory_format=torch.channels_last)
| :noindex:
|
| Its signature is similar to :meth:`torch.Tensor.to`, but only accepts
| floating point or complex :attr:`dtype`\ s. In addition, this method will
| only cast the floating point or complex parameters and buffers to :attr:`dtype`
| (if given). The integral parameters and buffers will be moved
| :attr:`device`, if that is given, but with dtypes unchanged. When
| :attr:`non_blocking` is set, it tries to convert/move asynchronously
| with respect to the host if possible, e.g., moving CPU Tensors with
| pinned memory to CUDA devices.
|
| See below for examples.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (:class:`torch.device`): the desired device of the parameters
| and buffers in this module
| dtype (:class:`torch.dtype`): the desired floating point or complex dtype of
| the parameters and buffers in this module
| tensor (torch.Tensor): Tensor whose dtype and device are the desired
| dtype and device for all parameters and buffers in this module
| memory_format (:class:`torch.memory_format`): the desired memory
| format for 4D parameters and buffers in this module (keyword
| only argument)
|
| Returns:
| Module: self
|
| Examples::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> linear = nn.Linear(2, 2)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]])
| >>> linear.to(torch.double)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]], dtype=torch.float64)
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA1)
| >>> gpu1 = torch.device("cuda:1")
| >>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
| >>> cpu = torch.device("cpu")
| >>> linear.to(cpu)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16)
|
| >>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.3741+0.j, 0.2382+0.j],
| [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
| >>> linear(torch.ones(3, 2, dtype=torch.cdouble))
| tensor([[0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
|
| to_empty(self, *, device: str | torch.device | int | None, recurse: bool = True) -> Self
| Move the parameters and buffers to the specified device without copying storage.
|
| Args:
| device (:class:`torch.device`): The desired device of the parameters
| and buffers in this module.
| recurse (bool): Whether parameters and buffers of submodules should
| be recursively moved to the specified device.
|
| Returns:
| Module: self
|
| train(self, mode: bool = True) -> Self
| Set the module in training mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e., whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| Args:
| mode (bool): whether to set training mode (``True``) or evaluation
| mode (``False``). Default: ``True``.
|
| Returns:
| Module: self
|
| type(self, dst_type: torch.dtype | str) -> Self
| Casts all parameters and buffers to :attr:`dst_type`.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| dst_type (type or string): the desired type
|
| Returns:
| Module: self
|
| xpu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the XPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing optimizer if the module will
| live on XPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset gradients of all model parameters.
|
| See similar function under :class:`torch.optim.Optimizer` for more context.
|
| Args:
| set_to_none (bool): instead of setting to zero, set the grads to None.
| See :meth:`torch.optim.Optimizer.zero_grad` for details.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.nn.modules.module.Module:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.nn.modules.module.Module:
|
| T_destination = ~T_destination
|
| call_super_init = False
|
| dump_patches = False
class strict_fusion(builtins.object)
| strict_fusion() -> None
|
| Give errors if not all nodes have been fused in inference, or symbolically differentiated in training.
|
| .. deprecated:: 2.5
| TorchScript is deprecated, please use ``torch.compile`` instead.
|
| Example:
| Forcing fusion of additions.
|
| .. code-block:: python
|
| @torch.jit.script
| def foo(x):
| with torch.jit.strict_fusion():
| return x + x + x
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, type: Any, value: Any, tb: Any) -> None
|
| __init__(self) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
annotate(the_type, the_value)
Use to give type of `the_value` in TorchScript compiler.
.. deprecated:: 2.5
TorchScript is deprecated, please use ``torch.compile`` instead.
This method is a pass-through function that returns `the_value`, used to hint TorchScript
compiler the type of `the_value`. It is a no-op when running outside of TorchScript.
Though TorchScript can infer correct type for most Python expressions, there are some cases where
type inference can be wrong, including:
- Empty containers like `[]` and `{}`, which TorchScript assumes to be container of `Tensor`
- Optional types like `Optional[T]` but assigned a valid value of type `T`, TorchScript would assume
it is type `T` rather than `Optional[T]`
Note that `annotate()` does not help in `__init__` method of `torch.nn.Module` subclasses because it
is executed in eager mode. To annotate types of `torch.nn.Module` attributes,
use :meth:`~torch.jit.Attribute` instead.
Example:
.. testcode::
import torch
from typing import Dict
@torch.jit.script
def fn():
# Telling TorchScript that this empty dictionary is a (str -> int) dictionary
# instead of default dictionary type of (str -> Tensor).
d = torch.jit.annotate(Dict[str, int], {})
# Without `torch.jit.annotate` above, following statement would fail because of
# type mismatch.
d["name"] = 20
.. testcleanup::
del fn
Args:
the_type: Python type that should be passed to TorchScript compiler as type hint for `the_value`
the_value: Value or expression to hint type for.
Returns:
`the_value` is passed back as return value.
enable_onednn_fusion(enabled: bool) -> None
Enable or disables onednn JIT fusion based on the parameter `enabled`.
.. deprecated:: 2.5
TorchScript is deprecated, please use ``torch.compile`` instead.
export(fn: Callable[~_P, ~_R]) -> Callable[~_P, ~_R]
This decorator indicates that a method on an ``nn.Module`` is used as an entry point into a
:class:`ScriptModule` and should be compiled.
.. deprecated:: 2.5
Please use :func:`torch.compile` instead.
``forward`` implicitly is assumed to be an entry point, so it does not need this decorator.
Functions and methods called from ``forward`` are compiled as they are seen
by the compiler, so they do not need this decorator either.
Example (using ``@torch.jit.export`` on a method):
.. testcode::
import torch
import torch.nn as nn
class MyModule(nn.Module):
def implicitly_compiled_method(self, x):
return x + 99
# `forward` is implicitly decorated with `@torch.jit.export`,
# so adding it here would have no effect
def forward(self, x):
return x + 10
@torch.jit.export
def another_forward(self, x):
# When the compiler sees this call, it will compile
# `implicitly_compiled_method`
return self.implicitly_compiled_method(x)
def unused_method(self, x):
return x - 20
# `m` will contain compiled methods:
# `forward`
# `another_forward`
# `implicitly_compiled_method`
# `unused_method` will not be compiled since it was not called from
# any compiled methods and wasn't decorated with `@torch.jit.export`
m = torch.jit.script(MyModule())
export_opnames(m)
Generate new bytecode for a Script module.
Returns what the op list would be for a Script Module based off the current code base.
If you have a LiteScriptModule and want to get the currently present
list of ops call _export_operator_list instead.
fork(func, *args, **kwargs)
Create an asynchronous task executing `func` and a reference to the value of the result of this execution.
.. deprecated:: 2.5
TorchScript is deprecated, please use ``torch.compile`` instead.
`fork` will return immediately, so the return value of `func` may not have been computed yet. To force completion
of the task and access the return value invoke `torch.jit.wait` on the Future. `fork` invoked
with a `func` which returns `T` is typed as `torch.jit.Future[T]`. `fork` calls can be arbitrarily
nested, and may be invoked with positional and keyword arguments.
Asynchronous execution will only occur when run in TorchScript. If run in pure python,
`fork` will not execute in parallel. `fork` will also not execute in parallel when invoked
while tracing, however the `fork` and `wait` calls will be captured in the exported IR Graph.
.. warning::
`fork` tasks will execute non-deterministically. We recommend only spawning
parallel fork tasks for pure functions that do not modify their inputs,
module attributes, or global state.
Args:
func (callable or torch.nn.Module): A Python function or `torch.nn.Module`
that will be invoked. If executed in TorchScript, it will execute asynchronously,
otherwise it will not. Traced invocations of fork will be captured in the IR.
``*args``, ``**kwargs``: arguments to invoke `func` with.
Returns:
`torch.jit.Future[T]`: a reference to the execution of `func`. The value `T`
can only be accessed by forcing completion of `func` through `torch.jit.wait`.
Example (fork a free function):
.. code-block:: python
import torch
from torch import Tensor
def foo(a: Tensor, b: int) -> Tensor:
return a + b
def bar(a):
fut: torch.jit.Future[Tensor] = torch.jit.fork(foo, a, b=2)
return torch.jit.wait(fut)
script_bar = torch.jit.script(bar)
input = torch.tensor(2)
# only the scripted version executes asynchronously
assert script_bar(input) == bar(input)
# trace is not run asynchronously, but fork is captured in IR
graph = torch.jit.trace(bar, (input,)).graph
assert "fork" in str(graph)
Example (fork a module method):
.. code-block:: python
import torch
from torch import Tensor
class AddMod(torch.nn.Module):
def forward(self, a: Tensor, b: int):
return a + b
class Mod(torch.nn.Module):
def __init__(self) -> None:
super(self).__init__()
self.mod = AddMod()
def forward(self, input):
fut = torch.jit.fork(self.mod, a, b=2)
return torch.jit.wait(fut)
input = torch.tensor(2)
mod = Mod()
assert mod(input) == torch.jit.script(mod).forward(input)
freeze(mod, preserved_attrs: list[str] | None = None, optimize_numerics: bool = True)
Freeze ScriptModule, inline submodules, and attributes as constants.
.. deprecated:: 2.5
TorchScript is deprecated, please use ``torch.compile`` instead.
Freezing a :class:`ScriptModule` will clone it and attempt to inline the cloned
module's submodules, parameters, and attributes as constants in the TorchScript IR Graph.
By default, `forward` will be preserved, as well as attributes & methods specified in
`preserved_attrs`. Additionally, any attribute that is modified within a preserved
method will be preserved.
Freezing currently only accepts ScriptModules that are in eval mode.
Freezing applies generic optimization that will speed up your model regardless of machine.
To further optimize using server-specific settings, run `optimize_for_inference` after
freezing.
Args:
mod (:class:`ScriptModule`): a module to be frozen
preserved_attrs (Optional[List[str]]): a list of attributes to preserve in addition to the forward method.
Attributes modified in preserved methods will also be preserved.
optimize_numerics (bool): If ``True``, a set of optimization passes will be run that does not strictly
preserve numerics. Full details of optimization can be found at `torch.jit.run_frozen_optimizations`.
Returns:
Frozen :class:`ScriptModule`.
Example (Freezing a simple module with a Parameter):
.. testcode::
import torch
class MyModule(torch.nn.Module):
def __init__(self, N, M):
super().__init__()
self.weight = torch.nn.Parameter(torch.rand(N, M))
self.linear = torch.nn.Linear(N, M)
def forward(self, input):
output = self.weight.mm(input)
output = self.linear(output)
return output
scripted_module = torch.jit.script(MyModule(2, 3).eval())
frozen_module = torch.jit.freeze(scripted_module)
# parameters have been removed and inlined into the Graph as constants
assert len(list(frozen_module.named_parameters())) == 0
# See the compiled graph as Python code
print(frozen_module.code)
Example (Freezing a module with preserved attributes)
.. testcode::
import torch
class MyModule2(torch.nn.Module):
def __init__(self) -> None:
super().__init__()
self.modified_tensor = torch.tensor(10.)
self.version = 1
def forward(self, input):
self.modified_tensor += 1
return input + self.modified_tensor
scripted_module = torch.jit.script(MyModule2().eval())
frozen_module = torch.jit.freeze(scripted_module, preserved_attrs=["version"])
# we've manually preserved `version`, so it still exists on the frozen module and can be modified
assert frozen_module.version == 1
frozen_module.version = 2
# `modified_tensor` is detected as being mutated in the forward, so freezing preserves
# it to retain model semantics
assert frozen_module(torch.tensor(1)) == torch.tensor(12)
# now that we've run it once, the next result will be incremented by one
assert frozen_module(torch.tensor(1)) == torch.tensor(13)
Note:
Freezing submodule attributes is also supported:
frozen_module = torch.jit.freeze(scripted_module, preserved_attrs=["submodule.version"])
Note:
If you're not sure why an attribute is not being inlined as a constant, you can run
`dump_alias_db` on frozen_module.forward.graph to see if freezing has detected the
attribute is being modified.
Note:
Because freezing makes weights constants and removes module hierarchy, `to` and other
nn.Module methods to manipulate device or dtype no longer work. As a workaround,
You can remap devices by specifying `map_location` in `torch.jit.load`, however
device-specific logic may have been baked into the model.
ignore(drop=False, **kwargs)
This decorator indicates to the compiler that a function or method should
be ignored and left as a Python function. This allows you to leave code in
your model that is not yet TorchScript compatible. If called from TorchScript,
ignored functions will dispatch the call to the Python interpreter. Models with ignored
functions cannot be exported; use :func:`@torch.jit.unused <torch.jit.unused>` instead.
.. deprecated:: 2.5
Please use :func:`torch.compile` instead.
Example (using ``@torch.jit.ignore`` on a method)::
import torch
import torch.nn as nn
class MyModule(nn.Module):
@torch.jit.ignore
def debugger(self, x):
import pdb
pdb.set_trace()
def forward(self, x):
x += 10
# The compiler would normally try to compile `debugger`,
# but since it is `@ignore`d, it will be left as a call
# to Python
self.debugger(x)
return x
m = torch.jit.script(MyModule())
# Error! The call `debugger` cannot be saved since it calls into Python
m.save("m.pt")
Example (using ``@torch.jit.ignore(drop=True)`` on a method):
.. testcode::
import torch
import torch.nn as nn
class MyModule(nn.Module):
@torch.jit.ignore(drop=True)
def training_method(self, x):
import pdb
pdb.set_trace()
def forward(self, x):
if self.training:
self.training_method(x)
return x
m = torch.jit.script(MyModule())
# This is OK since `training_method` is not saved, the call is replaced
# with a `raise`.
m.save("m.pt")
.. testcleanup::
import os
os.remove('m.pt')
interface(obj: ~_T) -> ~_T
Decorate to annotate classes or modules of different types.
.. deprecated:: 2.5
TorchScript is deprecated, please use ``torch.compile`` instead.
This decorator can be used to define an interface that can be used to annotate
classes or modules of different types. This can be used for to annotate a submodule
or attribute class that could have different types that implement the same
interface, or which could be swapped at runtime; or to store a list of modules or
classes of varying types.
It is sometimes used to implement "Callables" - functions or modules that implement
an interface but whose implementations differ and which can be swapped out.
Example:
.. testcode::
import torch
from typing import List
@torch.jit.interface
class InterfaceType:
def run(self, x: torch.Tensor) -> torch.Tensor:
pass
# implements InterfaceType
@torch.jit.script
class Impl1:
def run(self, x: torch.Tensor) -> torch.Tensor:
return x.relu()
class Impl2(torch.nn.Module):
def __init__(self) -> None:
super().__init__()
self.val = torch.rand(())
@torch.jit.export
def run(self, x: torch.Tensor) -> torch.Tensor:
return x + self.val
def user_fn(impls: List[InterfaceType], idx: int, val: torch.Tensor) -> torch.Tensor:
return impls[idx].run(val)
user_fn_jit = torch.jit.script(user_fn)
impls = [Impl1(), torch.jit.script(Impl2())]
val = torch.rand(4, 4)
user_fn_jit(impls, 0, val)
user_fn_jit(impls, 1, val)
isinstance(obj, target_type)
Provide container type refinement in TorchScript.
.. deprecated:: 2.5
TorchScript is deprecated, please use ``torch.compile`` instead.
It can refine parameterized containers of the List, Dict, Tuple, and Optional types. E.g. ``List[str]``,
``Dict[str, List[torch.Tensor]]``, ``Optional[Tuple[int,str,int]]``. It can also
refine basic types such as bools and ints that are available in TorchScript.
Args:
obj: object to refine the type of
target_type: type to try to refine obj to
Returns:
``bool``: True if obj was successfully refined to the type of target_type,
False otherwise with no new type refinement
Example (using ``torch.jit.isinstance`` for type refinement):
.. testcode::
import torch
from typing import Any, Dict, List
class MyModule(torch.nn.Module):
def __init__(self) -> None:
super().__init__()
def forward(self, input: Any): # note the Any type
if torch.jit.isinstance(input, List[torch.Tensor]):
for t in input:
y = t.clamp(0, 0.5)
elif torch.jit.isinstance(input, Dict[str, str]):
for val in input.values():
print(val)
m = torch.jit.script(MyModule())
x = [torch.rand(3,3), torch.rand(4,3)]
m(x)
y = {"key1":"val1","key2":"val2"}
m(y)
load(f, map_location=None, _extra_files=None, _restore_shapes=False)
Load a :class:`ScriptModule` or :class:`ScriptFunction` previously saved with :func:`torch.jit.save <torch.jit.save>`.
All previously saved modules, no matter their device, are first loaded onto CPU,
and then are moved to the devices they were saved from. If this fails (e.g.
because the run time system doesn't have certain devices), an exception is
raised.
Args:
f: a file-like object (has to implement read, readline, tell, and seek),
or a string containing a file name
map_location (string or torch.device): A simplified version of
``map_location`` in `torch.jit.save` used to dynamically remap
storages to an alternative set of devices.
_extra_files (dictionary of filename to content): The extra
filenames given in the map would be loaded and their content
would be stored in the provided map.
_restore_shapes (bool): Whether or not to retrace the module on load using stored inputs
Returns:
A :class:`ScriptModule` object.
.. warning::
It is possible to construct malicious pickle data which will execute arbitrary code
during func:`torch.jit.load`. Never load data that could have come from an untrusted
source, or that could have been tampered with. **Only load data you trust**.
Example:
.. testcode::
import torch
import io
torch.jit.load('scriptmodule.pt')
# Load ScriptModule from io.BytesIO object
with open('scriptmodule.pt', 'rb') as f:
buffer = io.BytesIO(f.read())
# Load all tensors to the original device
torch.jit.load(buffer)
# Load all tensors onto CPU, using a device
buffer.seek(0)
torch.jit.load(buffer, map_location=torch.device('cpu'))
# Load all tensors onto CPU, using a string
buffer.seek(0)
torch.jit.load(buffer, map_location='cpu')
# Load with extra files.
extra_files = {'foo.txt': ''} # values will be replaced with data
torch.jit.load('scriptmodule.pt', _extra_files=extra_files)
print(extra_files['foo.txt'])
.. testoutput::
:hide:
...
.. testcleanup::
import os
os.remove("scriptmodule.pt")
onednn_fusion_enabled()
Return whether onednn JIT fusion is enabled.
.. deprecated:: 2.5
TorchScript is deprecated, please use ``torch.compile`` instead.
optimize_for_inference(mod: torch.jit._script.ScriptModule, other_methods: list[str] | None = None) -> torch.jit._script.ScriptModule
Perform a set of optimization passes to optimize a model for the purposes of inference.
.. deprecated:: 2.5
TorchScript is deprecated, please use ``torch.compile`` instead.
If the model is not already frozen, optimize_for_inference
will invoke `torch.jit.freeze` automatically.
In addition to generic optimizations that should speed up your model regardless
of environment, prepare for inference will also bake in build specific settings
such as the presence of CUDNN or MKLDNN, and may in the future make transformations
which speed things up on one machine but slow things down on another. Accordingly,
serialization is not implemented following invoking `optimize_for_inference` and
is not guaranteed.
This is still in prototype, and may have the potential to slow down your model.
Primary use cases that have been targeted so far have been vision models on cpu
and gpu to a lesser extent.
Example (optimizing a module with Conv->Batchnorm)::
import torch
in_channels, out_channels = 3, 32
conv = torch.nn.Conv2d(
in_channels, out_channels, kernel_size=3, stride=2, bias=True
)
bn = torch.nn.BatchNorm2d(out_channels, eps=0.001)
mod = torch.nn.Sequential(conv, bn)
frozen_mod = torch.jit.optimize_for_inference(torch.jit.script(mod.eval()))
assert "batch_norm" not in str(frozen_mod.graph)
# if built with MKLDNN, convolution will be run with MKLDNN weights
assert "MKLDNN" in frozen_mod.graph
save(m, f, _extra_files=None) -> None
Save an offline version of this module for use in a separate process.
The saved module serializes all of the methods, submodules, parameters, and
attributes of this module. It can be loaded into the C++ API using
``torch::jit::load(filename)`` or into the Python API with
:func:`torch.jit.load <torch.jit.load>`.
To be able to save a module, it must not make any calls to native Python
functions. This means that all submodules must be subclasses of
:class:`ScriptModule` as well.
.. DANGER::
All modules, no matter their device, are always loaded onto the CPU
during loading. This is different from :func:`torch.load`'s semantics
and may change in the future.
Args:
m: A :class:`ScriptModule` to save.
f: A file-like object (has to implement write and flush) or a string
containing a file name.
_extra_files: Map from filename to contents which will be stored as part of `f`.
.. note::
torch.jit.save attempts to preserve the behavior of some operators
across versions. For example, dividing two integer tensors in
PyTorch 1.5 performed floor division, and if the module
containing that code is saved in PyTorch 1.5 and loaded in PyTorch 1.6
its division behavior will be preserved. The same module saved in
PyTorch 1.6 will fail to load in PyTorch 1.5, however, since the
behavior of division changed in 1.6, and 1.5 does not know how to
replicate the 1.6 behavior.
Example:
.. testcode::
import torch
import io
class MyModule(torch.nn.Module):
def forward(self, x):
return x + 10
m = torch.jit.script(MyModule())
# Save to file
torch.jit.save(m, 'scriptmodule.pt')
# This line is equivalent to the previous
m.save("scriptmodule.pt")
# Save to io.BytesIO buffer
buffer = io.BytesIO()
torch.jit.save(m, buffer)
# Save with extra files
extra_files = {'foo.txt': b'bar'}
torch.jit.save(m, 'scriptmodule.pt', _extra_files=extra_files)
script(obj: Any, optimize: None = None, _frames_up: int = 0, _rcb: collections.abc.Callable[[str], typing.Any] | None = None, example_inputs: list[tuple] | dict[collections.abc.Callable, list[tuple]] | None = None) -> Any
Script the function.
Scripting a function or ``nn.Module`` will inspect the source code, compile
it as TorchScript code using the TorchScript compiler, and return a :class:`ScriptModule` or
:class:`ScriptFunction`. TorchScript itself is a subset of the Python language, so not all
features in Python work, but we provide enough functionality to compute on
tensors and do control-dependent operations. For a complete guide, see the
:ref:`language-reference`.
Scripting a dictionary or list copies the data inside it into a TorchScript instance than can be
subsequently passed by reference between Python and TorchScript with zero copy overhead.
``torch.jit.script`` can be used as a function for modules, functions, dictionaries and lists
and as a decorator ``@torch.jit.script`` for torchscript-classes and functions.
Args:
obj (Callable, class, or nn.Module): The ``nn.Module``, function, class type,
dictionary, or list to compile.
example_inputs (Union[List[Tuple], Dict[Callable, List[Tuple]], None]): Provide example inputs
to annotate the arguments for a function or ``nn.Module``.
Returns:
If ``obj`` is ``nn.Module``, ``script`` returns
a :class:`ScriptModule` object. The returned :class:`ScriptModule` will
have the same set of sub-modules and parameters as the
original ``nn.Module``. If ``obj`` is a standalone function,
a :class:`ScriptFunction` will be returned. If ``obj`` is a ``dict``, then
``script`` returns an instance of `torch._C.ScriptDict`. If ``obj`` is a ``list``,
then ``script`` returns an instance of `torch._C.ScriptList`.
**Scripting a function**
The ``@torch.jit.script`` decorator will construct a :class:`ScriptFunction`
by compiling the body of the function.
Example (scripting a function):
.. testcode::
import torch
@torch.jit.script
def foo(x, y):
if x.max() > y.max():
r = x
else:
r = y
return r
print(type(foo)) # torch.jit.ScriptFunction
# See the compiled graph as Python code
print(foo.code)
# Call the function using the TorchScript interpreter
foo(torch.ones(2, 2), torch.ones(2, 2))
.. testoutput::
:hide:
...
****Scripting a function using example_inputs**
Example inputs can be used to annotate a function arguments.
Example (annotating a function before scripting):
.. testcode::
import torch
def test_sum(a, b):
return a + b
# Annotate the arguments to be int
scripted_fn = torch.jit.script(test_sum, example_inputs=[(3, 4)])
print(type(scripted_fn)) # torch.jit.ScriptFunction
# See the compiled graph as Python code
print(scripted_fn.code)
# Call the function using the TorchScript interpreter
scripted_fn(20, 100)
.. testoutput::
:hide:
...
**Scripting an nn.Module**
Scripting an ``nn.Module`` by default will compile the ``forward`` method and recursively
compile any methods, submodules, and functions called by ``forward``. If a ``nn.Module`` only uses
features supported in TorchScript, no changes to the original module code should be necessary. ``script``
will construct :class:`ScriptModule` that has copies of the attributes, parameters, and methods of
the original module.
Example (scripting a simple module with a Parameter):
.. testcode::
import torch
class MyModule(torch.nn.Module):
def __init__(self, N, M):
super().__init__()
# This parameter will be copied to the new ScriptModule
self.weight = torch.nn.Parameter(torch.rand(N, M))
# When this submodule is used, it will be compiled
self.linear = torch.nn.Linear(N, M)
def forward(self, input):
output = self.weight.mv(input)
# This calls the `forward` method of the `nn.Linear` module, which will
# cause the `self.linear` submodule to be compiled to a `ScriptModule` here
output = self.linear(output)
return output
scripted_module = torch.jit.script(MyModule(2, 3))
Example (scripting a module with traced submodules):
.. testcode::
import torch
import torch.nn as nn
import torch.nn.functional as F
class MyModule(nn.Module):
def __init__(self) -> None:
super().__init__()
# torch.jit.trace produces a ScriptModule's conv1 and conv2
self.conv1 = torch.jit.trace(nn.Conv2d(1, 20, 5), torch.rand(1, 1, 16, 16))
self.conv2 = torch.jit.trace(nn.Conv2d(20, 20, 5), torch.rand(1, 20, 16, 16))
def forward(self, input):
input = F.relu(self.conv1(input))
input = F.relu(self.conv2(input))
return input
scripted_module = torch.jit.script(MyModule())
To compile a method other than ``forward`` (and recursively compile anything it calls), add
the :func:`@torch.jit.export <torch.jit.export>` decorator to the method. To opt out of compilation
use :func:`@torch.jit.ignore <torch.jit.ignore>` or :func:`@torch.jit.unused <torch.jit.unused>`.
Example (an exported and ignored method in a module)::
import torch
import torch.nn as nn
class MyModule(nn.Module):
def __init__(self) -> None:
super().__init__()
@torch.jit.export
def some_entry_point(self, input):
return input + 10
@torch.jit.ignore
def python_only_fn(self, input):
# This function won't be compiled, so any
# Python APIs can be used
import pdb
pdb.set_trace()
def forward(self, input):
if self.training:
self.python_only_fn(input)
return input * 99
scripted_module = torch.jit.script(MyModule())
print(scripted_module.some_entry_point(torch.randn(2, 2)))
print(scripted_module(torch.randn(2, 2)))
Example ( Annotating forward of nn.Module using example_inputs)::
import torch
import torch.nn as nn
from typing import NamedTuple
class MyModule(NamedTuple):
result: List[int]
class TestNNModule(torch.nn.Module):
def forward(self, a) -> MyModule:
result = MyModule(result=a)
return result
pdt_model = TestNNModule()
# Runs the pdt_model in eager model with the inputs provided and annotates the arguments of forward
scripted_model = torch.jit.script(pdt_model, example_inputs={pdt_model: [([10, 20, ], ), ], })
# Run the scripted_model with actual inputs
print(scripted_model([20]))
script_if_tracing(fn)
Compiles ``fn`` when it is first called during tracing.
.. deprecated:: 2.5
TorchScript is deprecated, please use ``torch.compile`` instead.
``torch.jit.script`` has a non-negligible start up time when it is first called due to
lazy-initializations of many compiler builtins. Therefore you should not use
it in library code. However, you may want to have parts of your library work
in tracing even if they use control flow. In these cases, you should use
``@torch.jit.script_if_tracing`` to substitute for
``torch.jit.script``.
Args:
fn: A function to compile.
Returns:
If called during tracing, a :class:`ScriptFunction` created by `torch.jit.script` is returned.
Otherwise, the original function `fn` is returned.
set_fusion_strategy(strategy: list[tuple[str, int]])
Set the type and number of specializations that can occur during fusion.
.. deprecated:: 2.5
TorchScript is deprecated, please use ``torch.compile`` instead.
Usage: provide a list of pairs (type, depth) where type is one of "STATIC" or "DYNAMIC"
and depth is an integer.
Behavior - static vs dynamic:
In STATIC fusion, fused ops are compiled to have fixed input shapes. The shape is determined
based on some initial profiling runs.
In DYNAMIC fusion, fused ops are compiled to have variable input shapes, so that multiple
shapes are possible.
In both cases, we also recompile on new striding behavior, device, or dtype.
Behavior - fallback functions & depth:
When an input doesn't match the format required by the specialized compiled op, it will run
a fallback function. Fallback functions are recursively be compiled and specialized based
on the observed tensor shapes. Since compilation can be slow, the "depth" parameter is provided to
limit the number of specializations that can be compiled, before giving up on recompiling and
falling back to a completely un-fused, un-specialized implementation.
The list of (type, depth) pairs controls the type of specializations and the number of
specializations. For example: [("STATIC", 2), ("DYNAMIC", 2)] indicates that the first
two specializations will use static fusions, the following two specializations will use
dynamic fusion, and any inputs that satisfy none of the 4 options will run an
unfused implementation.
NB: in the future, if more as more fusion backends are added there may be more granular
apis for specific fusers.
trace(func, example_inputs=None, optimize=None, check_trace=True, check_inputs=None, check_tolerance=1e-05, strict=True, _force_outplace=False, _module_class=None, _compilation_unit=<torch.jit.CompilationUnit object at 0x00000199DD3EBC30>, example_kwarg_inputs=None, _store_inputs=True)
Trace a function and return an executable or :class:`ScriptFunction` that will be optimized using just-in-time compilation.
Tracing is ideal for code that operates only on
``Tensor``\\s and lists, dictionaries, and
tuples of ``Tensor``\\s.
Using `torch.jit.trace` and `torch.jit.trace_module`, you can turn an
existing module or Python function into a TorchScript
:class:`ScriptFunction` or :class:`ScriptModule`. You must provide example
inputs, and we run the function, recording the operations performed on all
the tensors.
* The resulting recording of a standalone function produces `ScriptFunction`.
* The resulting recording of `nn.Module.forward` or `nn.Module` produces
`ScriptModule`.
This module also contains any parameters that the original
module had as well.
Warning:
Tracing only correctly records functions and modules which are not data
dependent (e.g., do not have conditionals on data in tensors) and do not have
any untracked external dependencies (e.g., perform input/output or
access global variables). Tracing only records operations done when the given
function is run on the given tensors. Therefore, the returned
`ScriptModule` will always run the same traced graph on any input. This
has some important implications when your module is expected to run
different sets of operations, depending on the input and/or the module
state. For example,
* Tracing will not record any control-flow like if-statements or loops.
When this control-flow is constant across your module, this is fine
and it often inlines the control-flow decisions. But sometimes the
control-flow is actually part of the model itself. For instance, a
recurrent network is a loop over the (possibly dynamic) length of an
input sequence.
* In the returned :class:`ScriptModule`, operations that have different
behaviors in ``training`` and ``eval`` modes will always behave as if
it is in the mode it was in during tracing, no matter which mode the
`ScriptModule` is in.
In cases like these, tracing would not be appropriate and
:func:`scripting <torch.jit.script>` is a better choice. If you trace
such models, you may silently get incorrect results on subsequent
invocations of the model. The tracer will try to emit warnings when
doing something that may cause an incorrect trace to be produced.
Args:
func (callable or torch.nn.Module): A Python function or `torch.nn.Module`
that will be run with `example_inputs`. `func` arguments and return
values must be tensors or (possibly nested) tuples that contain
tensors. When a module is passed `torch.jit.trace`, only the
``forward`` method is run and traced (see :func:`torch.jit.trace
<torch.jit.trace_module>` for details).
Keyword arguments:
example_inputs (tuple or torch.Tensor or None, optional): A tuple of example
inputs that will be passed to the function while tracing.
Default: ``None``. Either this argument or ``example_kwarg_inputs``
should be specified. The resulting trace can be run with inputs of
different types and shapes assuming the traced operations support those
types and shapes. `example_inputs` may also be a single Tensor in which
case it is automatically wrapped in a tuple. When the value is None,
``example_kwarg_inputs`` should be specified.
check_trace (``bool``, optional): Check if the same inputs run through
traced code produce the same outputs. Default: ``True``. You might want
to disable this if, for example, your network contains non-
deterministic ops or if you are sure that the network is correct despite
a checker failure.
check_inputs (list of tuples, optional): A list of tuples of input
arguments that should be used to check the trace against what is
expected. Each tuple is equivalent to a set of input arguments that
would be specified in ``example_inputs``. For best results, pass in
a set of checking inputs representative of the space of shapes and
types of inputs you expect the network to see. If not specified,
the original ``example_inputs`` are used for checking
check_tolerance (float, optional): Floating-point comparison tolerance
to use in the checker procedure. This can be used to relax the
checker strictness in the event that results diverge numerically
for a known reason, such as operator fusion.
strict (``bool``, optional): run the tracer in a strict mode or not
(default: ``True``). Only turn this off when you want the tracer to
record your mutable container types (currently ``list``/``dict``)
and you are sure that the container you are using in your
problem is a ``constant`` structure and does not get used as
control flow (if, for) conditions.
example_kwarg_inputs (dict, optional): This parameter is a pack of keyword
arguments of example inputs that will be passed to the function while
tracing. Default: ``None``. Either this argument or ``example_inputs``
should be specified. The dict will be unpacking by the arguments name
of the traced function. If the keys of the dict don't not match with
the traced function's arguments name, a runtime exception will be raised.
Returns:
If `func` is `nn.Module` or ``forward`` of `nn.Module`, `trace` returns
a :class:`ScriptModule` object with a single ``forward`` method
containing the traced code. The returned `ScriptModule` will
have the same set of sub-modules and parameters as the original
``nn.Module``. If ``func`` is a standalone function, ``trace``
returns `ScriptFunction`.
Example (tracing a function):
.. testcode::
import torch
def foo(x, y):
return 2 * x + y
# Run `foo` with the provided inputs and record the tensor operations
traced_foo = torch.jit.trace(foo, (torch.rand(3), torch.rand(3)))
# `traced_foo` can now be run with the TorchScript interpreter or saved
# and loaded in a Python-free environment
Example (tracing an existing module)::
import torch
import torch.nn as nn
class Net(nn.Module):
def __init__(self) -> None:
super().__init__()
self.conv = nn.Conv2d(1, 1, 3)
def forward(self, x):
return self.conv(x)
n = Net()
example_weight = torch.rand(1, 1, 3, 3)
example_forward_input = torch.rand(1, 1, 3, 3)
# Trace a specific method and construct `ScriptModule` with
# a single `forward` method
module = torch.jit.trace(n.forward, example_forward_input)
# Trace a module (implicitly traces `forward`) and construct a
# `ScriptModule` with a single `forward` method
module = torch.jit.trace(n, example_forward_input)
trace_module(mod, inputs, optimize=None, check_trace=True, check_inputs=None, check_tolerance=1e-05, strict=True, _force_outplace=False, _module_class=None, _compilation_unit=<torch.jit.CompilationUnit object at 0x00000199DD3EBC30>, example_inputs_is_kwarg=False, _store_inputs=True)
Trace a module and return an executable :class:`ScriptModule` that will be optimized using just-in-time compilation.
When a module is passed to :func:`torch.jit.trace <torch.jit.trace>`, only
the ``forward`` method is run and traced. With ``trace_module``, you can specify a dictionary of
method names to example inputs to trace (see the ``inputs``) argument below.
See :func:`torch.jit.trace <torch.jit.trace>` for more information on tracing.
Args:
mod (torch.nn.Module): A ``torch.nn.Module`` containing methods whose names are
specified in ``inputs``. The given methods will be compiled
as a part of a single `ScriptModule`.
inputs (dict): A dict containing sample inputs indexed by method names in ``mod``.
The inputs will be passed to methods whose names correspond to inputs'
keys while tracing.
``{ 'forward' : example_forward_input, 'method2': example_method2_input}``
Keyword arguments:
check_trace (``bool``, optional): Check if the same inputs run through
traced code produce the same outputs. Default: ``True``. You might want
to disable this if, for example, your network contains non-
deterministic ops or if you are sure that the network is correct despite
a checker failure.
check_inputs (list of dicts, optional): A list of dicts of input arguments that should be used
to check the trace against what is expected. Each tuple
is equivalent to a set of input arguments that would
be specified in ``inputs``. For best results, pass in a
set of checking inputs representative of the space of
shapes and types of inputs you expect the network to see.
If not specified, the original ``inputs`` are used for checking
check_tolerance (float, optional): Floating-point comparison tolerance to use in the checker procedure.
This can be used to relax the checker strictness in the event that
results diverge numerically for a known reason, such as operator fusion.
example_inputs_is_kwarg (``bool``, optional): This parameter indicate whether the example inputs is a pack
pack of keyword arguments. Default: ``False``.
Returns:
A :class:`ScriptModule` object with a single ``forward`` method containing the traced code.
When ``func`` is a ``torch.nn.Module``, the returned :class:`ScriptModule` will have the same set of
sub-modules and parameters as ``func``.
Example (tracing a module with multiple methods)::
import torch
import torch.nn as nn
class Net(nn.Module):
def __init__(self) -> None:
super().__init__()
self.conv = nn.Conv2d(1, 1, 3)
def forward(self, x):
return self.conv(x)
def weighted_kernel_sum(self, weight):
return weight * self.conv.weight
n = Net()
example_weight = torch.rand(1, 1, 3, 3)
example_forward_input = torch.rand(1, 1, 3, 3)
# Trace a specific method and construct `ScriptModule` with
# a single `forward` method
module = torch.jit.trace(n.forward, example_forward_input)
# Trace a module (implicitly traces `forward`) and construct a
# `ScriptModule` with a single `forward` method
module = torch.jit.trace(n, example_forward_input)
# Trace specific methods on a module (specified in `inputs`), constructs
# a `ScriptModule` with `forward` and `weighted_kernel_sum` methods
inputs = {
"forward": example_forward_input,
"weighted_kernel_sum": example_weight,
}
module = torch.jit.trace_module(n, inputs)
unused(fn: Callable[~_P, ~_R]) -> Callable[~_P, ~_R]
This decorator indicates to the compiler that a function or method should
be ignored and replaced with the raising of an exception. This allows you
to leave code in your model that is not yet TorchScript compatible and still
export your model.
Example (using ``@torch.jit.unused`` on a method)::
import torch
import torch.nn as nn
class MyModule(nn.Module):
def __init__(self, use_memory_efficient):
super().__init__()
self.use_memory_efficient = use_memory_efficient
@torch.jit.unused
def memory_efficient(self, x):
import pdb
pdb.set_trace()
return x + 10
def forward(self, x):
# Use not-yet-scriptable memory efficient mode
if self.use_memory_efficient:
return self.memory_efficient(x)
else:
return x + 10
m = torch.jit.script(MyModule(use_memory_efficient=False))
m.save("m.pt")
m = torch.jit.script(MyModule(use_memory_efficient=True))
# exception raised
m(torch.rand(100))
wait(future)
Force completion of a `torch.jit.Future[T]` asynchronous task, returning the result of the task.
.. deprecated:: 2.5
TorchScript is deprecated, please use ``torch.compile`` instead.
See :func:`~fork` for docs and examples.
Args:
future (torch.jit.Future[T]): an asynchronous task reference, created through `torch.jit.fork`
Returns:
`T`: the return value of the completed task
DATA
__all__ = ['Attribute', 'CompilationUnit', 'Error', 'Future', 'ScriptF...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\jit\__init__.py
torch.kaiser_window
Python Library Documentation: built-in function kaiser_window in module torch
kaiser_window(...)
kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Computes the Kaiser window with window length :attr:`window_length` and shape parameter :attr:`beta`.
Let I_0 be the zeroth order modified Bessel function of the first kind (see :func:`torch.i0`) and
``N = L - 1`` if :attr:`periodic` is False and ``L`` if :attr:`periodic` is True,
where ``L`` is the :attr:`window_length`. This function computes:
.. math::
out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )
Calling ``torch.kaiser_window(L, B, periodic=True)`` is equivalent to calling
``torch.kaiser_window(L + 1, B, periodic=False)[:-1])``.
The :attr:`periodic` argument is intended as a helpful shorthand
to produce a periodic window as input to functions like :func:`torch.stft`.
.. note::
If :attr:`window_length` is one, then the returned window is a single element tensor containing a one.
Args:
window_length (int): length of the window.
periodic (bool, optional): If True, returns a periodic window suitable for use in spectral analysis.
If False, returns a symmetric window suitable for use in filter design.
beta (float, optional): shape parameter for the window.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
torch.kl_div
Python Library Documentation: built-in function kl_div in module torch kl_div(...)
torch.kron
Python Library Documentation: built-in function kron in module torch
kron(...)
kron(input, other, *, out=None) -> Tensor
Computes the Kronecker product, denoted by :math:`\otimes`, of :attr:`input` and :attr:`other`.
If :attr:`input` is a :math:`(a_0 \times a_1 \times \dots \times a_n)` tensor and :attr:`other` is a
:math:`(b_0 \times b_1 \times \dots \times b_n)` tensor, the result will be a
:math:`(a_0*b_0 \times a_1*b_1 \times \dots \times a_n*b_n)` tensor with the following entries:
.. math::
(\text{input} \otimes \text{other})_{k_0, k_1, \dots, k_n} =
\text{input}_{i_0, i_1, \dots, i_n} * \text{other}_{j_0, j_1, \dots, j_n},
where :math:`k_t = i_t * b_t + j_t` for :math:`0 \leq t \leq n`.
If one tensor has fewer dimensions than the other it is unsqueezed until it has the same number of dimensions.
Supports real-valued and complex-valued inputs.
.. note::
This function generalizes the typical definition of the Kronecker product for two matrices to two tensors,
as described above. When :attr:`input` is a :math:`(m \times n)` matrix and :attr:`other` is a
:math:`(p \times q)` matrix, the result will be a :math:`(p*m \times q*n)` block matrix:
.. math::
\mathbf{A} \otimes \mathbf{B}=\begin{bmatrix}
a_{11} \mathbf{B} & \cdots & a_{1 n} \mathbf{B} \\
\vdots & \ddots & \vdots \\
a_{m 1} \mathbf{B} & \cdots & a_{m n} \mathbf{B} \end{bmatrix}
where :attr:`input` is :math:`\mathbf{A}` and :attr:`other` is :math:`\mathbf{B}`.
Arguments:
input (Tensor)
other (Tensor)
Keyword args:
out (Tensor, optional): The output tensor. Ignored if ``None``. Default: ``None``
Examples::
>>> mat1 = torch.eye(2)
>>> mat2 = torch.ones(2, 2)
>>> torch.kron(mat1, mat2)
tensor([[1., 1., 0., 0.],
[1., 1., 0., 0.],
[0., 0., 1., 1.],
[0., 0., 1., 1.]])
>>> mat1 = torch.eye(2)
>>> mat2 = torch.arange(1, 5).reshape(2, 2)
>>> torch.kron(mat1, mat2)
tensor([[1., 2., 0., 0.],
[3., 4., 0., 0.],
[0., 0., 1., 2.],
[0., 0., 3., 4.]])
torch.kthvalue
Python Library Documentation: built-in function kthvalue in module torch
kthvalue(...)
kthvalue(input, k, dim=None, keepdim=False, *, out=None) -> (Tensor, LongTensor)
Returns a namedtuple ``(values, indices)`` where ``values`` is the :attr:`k` th
smallest element of each row of the :attr:`input` tensor in the given dimension
:attr:`dim`. And ``indices`` is the index location of each element found.
If :attr:`dim` is not given, the last dimension of the `input` is chosen.
If :attr:`keepdim` is ``True``, both the :attr:`values` and :attr:`indices` tensors
are the same size as :attr:`input`, except in the dimension :attr:`dim` where
they are of size 1. Otherwise, :attr:`dim` is squeezed
(see :func:`torch.squeeze`), resulting in both the :attr:`values` and
:attr:`indices` tensors having 1 fewer dimension than the :attr:`input` tensor.
.. note::
When :attr:`input` is a CUDA tensor and there are multiple valid
:attr:`k` th values, this function may nondeterministically return
:attr:`indices` for any of them.
Args:
input (Tensor): the input tensor.
k (int): k for the k-th smallest element
dim (int, optional): the dimension to find the kth value along
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (tuple, optional): the output tuple of (Tensor, LongTensor)
can be optionally given to be used as output buffers
Example::
>>> x = torch.arange(1., 6.)
>>> x
tensor([ 1., 2., 3., 4., 5.])
>>> torch.kthvalue(x, 4)
torch.return_types.kthvalue(values=tensor(4.), indices=tensor(3))
>>> x=torch.arange(1.,7.).resize_(2,3)
>>> x
tensor([[ 1., 2., 3.],
[ 4., 5., 6.]])
>>> torch.kthvalue(x, 2, 0, True)
torch.return_types.kthvalue(values=tensor([[4., 5., 6.]]), indices=tensor([[1, 1, 1]]))
torch.layer_norm
Python Library Documentation: built-in function layer_norm in module torch layer_norm(...)
torch.layout
Python Library Documentation: class layout in module torch class layout(builtins.object) | Methods defined here: | | __repr__(self, /) | Return repr(self).
torch.lcm
Python Library Documentation: built-in function lcm in module torch
lcm(...)
lcm(input, other, *, out=None) -> Tensor
Computes the element-wise least common multiple (LCM) of :attr:`input` and :attr:`other`.
Both :attr:`input` and :attr:`other` must have integer types.
.. note::
This defines :math:`lcm(0, 0) = 0` and :math:`lcm(0, a) = 0`.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([5, 10, 15])
>>> b = torch.tensor([3, 4, 5])
>>> torch.lcm(a, b)
tensor([15, 20, 15])
>>> c = torch.tensor([3])
>>> torch.lcm(a, c)
tensor([15, 30, 15])
torch.lcm_
Python Library Documentation: built-in function lcm_ in module torch lcm_(...)
torch.ldexp
Python Library Documentation: built-in function ldexp in module torch
ldexp(...)
ldexp(input, other, *, out=None) -> Tensor
Multiplies :attr:`input` by 2 ** :attr:`other`.
.. math::
\text{{out}}_i = \text{{input}}_i * 2^\text{{other}}_i
Typically this function is used to construct floating point numbers by multiplying
mantissas in :attr:`input` with integral powers of two created from the exponents
in :attr:`other`.
Args:
input (Tensor): the input tensor.
other (Tensor): a tensor of exponents, typically integers.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.ldexp(torch.tensor([1.]), torch.tensor([1]))
tensor([2.])
>>> torch.ldexp(torch.tensor([1.0]), torch.tensor([1, 2, 3, 4]))
tensor([ 2., 4., 8., 16.])
torch.ldexp_
Python Library Documentation: built-in function ldexp_ in module torch ldexp_(...)
torch.le
Python Library Documentation: built-in function le in module torch
le(...)
le(input, other, *, out=None) -> Tensor
Computes :math:`\text{input} \leq \text{other}` element-wise.
The second argument can be a number or a tensor whose shape is
:ref:`broadcastable <broadcasting-semantics>` with the first argument.
Args:
input (Tensor): the tensor to compare
other (Tensor or Scalar): the tensor or value to compare
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
A boolean tensor that is True where :attr:`input` is less than or equal to
:attr:`other` and False elsewhere
Example::
>>> torch.le(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[True, False], [True, True]])
torch.legacy_contiguous_format
Python Library Documentation: memory_format object class memory_format(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self).
torch.lerp
Python Library Documentation: built-in function lerp in module torch
lerp(...)
lerp(input, end, weight, *, out=None)
Does a linear interpolation of two tensors :attr:`start` (given by :attr:`input`) and :attr:`end` based
on a scalar or tensor :attr:`weight` and returns the resulting :attr:`out` tensor.
.. math::
\text{out}_i = \text{start}_i + \text{weight}_i \times (\text{end}_i - \text{start}_i)
The shapes of :attr:`start` and :attr:`end` must be
:ref:`broadcastable <broadcasting-semantics>`. If :attr:`weight` is a tensor, then
the shapes of :attr:`weight`, :attr:`start`, and :attr:`end` must be :ref:`broadcastable <broadcasting-semantics>`.
Args:
input (Tensor): the tensor with the starting points
end (Tensor): the tensor with the ending points
weight (float or tensor): the weight for the interpolation formula
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> start = torch.arange(1., 5.)
>>> end = torch.empty(4).fill_(10)
>>> start
tensor([ 1., 2., 3., 4.])
>>> end
tensor([ 10., 10., 10., 10.])
>>> torch.lerp(start, end, 0.5)
tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
>>> torch.lerp(start, end, torch.full_like(start, 0.5))
tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
torch.less
Python Library Documentation: built-in function less in module torch
less(...)
less(input, other, *, out=None) -> Tensor
Alias for :func:`torch.lt`.
torch.less_equal
Python Library Documentation: built-in function less_equal in module torch
less_equal(...)
less_equal(input, other, *, out=None) -> Tensor
Alias for :func:`torch.le`.
torch.lgamma
Python Library Documentation: built-in function lgamma in module torch
lgamma(...)
lgamma(input, *, out=None) -> Tensor
Computes the natural logarithm of the absolute value of the gamma function on :attr:`input`.
.. math::
\text{out}_{i} = \ln |\Gamma(\text{input}_{i})|
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.arange(0.5, 2, 0.5)
>>> torch.lgamma(a)
tensor([ 0.5724, 0.0000, -0.1208])
torch.library
Python Library Documentation: module torch.library in torch
NAME
torch.library - # mypy: allow-untyped-defs
CLASSES
builtins.object
Library
class Library(builtins.object)
| Library(ns, kind, dispatch_key='')
|
| A class to create libraries that can be used to register new operators or
| override operators in existing libraries from Python.
| A user can optionally pass in a dispatch keyname if they only want to register
| kernels corresponding to only one specific dispatch key.
|
| To create a library to override operators in an existing library (with name ns), set the kind to "IMPL".
| To create a new library (with name ns) to register new operators, set the kind to "DEF".
| To create a fragment of a possibly existing library to register operators (and bypass
| the limitation that there is only one library for a given namespace), set the kind to
| "FRAGMENT".
|
| Args:
| ns: library name
| kind: "DEF", "IMPL", "FRAGMENT"
| dispatch_key: PyTorch dispatch key (default: "")
|
| Methods defined here:
|
| __init__(self, ns, kind, dispatch_key='')
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| define(self, schema, alias_analysis='', *, tags=())
| Defines a new operator and its semantics in the ns namespace.
|
| Args:
| schema: function schema to define a new operator.
| alias_analysis (optional): Indicates if the aliasing properties of the operator arguments can be
| inferred from the schema (default behavior) or not ("CONSERVATIVE").
| tags (Tag | Sequence[Tag]): one or more torch.Tag to apply to this
| operator. Tagging an operator changes the operator's behavior
| under various PyTorch subsystems; please read the docs for the
| torch.Tag carefully before applying it.
|
| Returns:
| name of the operator as inferred from the schema.
|
| Example::
|
| >>> my_lib = Library("mylib", "DEF")
| >>> my_lib.define("sum(Tensor self) -> Tensor")
|
| fallback(self, fn, dispatch_key='', *, with_keyset=False)
| Registers the function implementation as the fallback for the given key.
|
| This function only works for a library with global namespace ("_").
|
| Args:
| fn: function used as fallback for the given dispatch key or :func:`~fallthrough_kernel`
| to register a fallthrough.
| dispatch_key: dispatch key that the input function should be registered for. By default, it uses
| the dispatch key that the library was created with.
| with_keyset: flag controlling if the current dispatcher call keyset should be passed as the first argument
| to :attr:`fn` when calling. This should be used to create the appropriate keyset for redispatch calls.
|
| Example::
|
| >>> my_lib = Library("_", "IMPL")
| >>> def fallback_kernel(op, *args, **kwargs):
| >>> # Handle all autocast ops generically
| >>> # ...
| >>> my_lib.fallback(fallback_kernel, "Autocast")
|
| impl(self, op_name, fn, dispatch_key='', *, with_keyset=False, allow_override=True)
| Registers the function implementation for an operator defined in the library.
|
| Args:
| op_name: operator name (along with the overload) or OpOverload object.
| fn: function that's the operator implementation for the input dispatch key or :func:`~fallthrough_kernel`
| to register a fallthrough.
| dispatch_key: dispatch key that the input function should be registered for. By default, it uses
| the dispatch key that the library was created with.
| with_keyset: flag controlling if the current dispatcher call keyset should be passed as the first argument
| to :attr:`fn` when calling. This should be used to create the appropriate keyset for redispatch calls.
| allow_override: Flag controlling if we want to override an
| existing registered kernel implementation. This is on
| by default; pass ``False`` to error if a kernel is
| already registered for this dispatch key.
|
| Example::
| >>> # xdoctest: +SKIP("Requires Python <= 3.11")
| >>> my_lib = Library("aten", "IMPL")
| >>> def div_cpu(self, other):
| >>> return self * (1 / other)
| >>> my_lib.impl("div.Tensor", div_cpu, "CPU")
|
| register_symm_mem_args(self, op_name, arg_names)
| Registers which arguments require symmetric memory allocation for an operator.
|
| This method allows operators to declaratively specify which arguments need
| symmetric memory treatment. When used with ``torch.compile``, Inductor
| automatically allocates these arguments in P2P-accessible NVLink memory
| (``empty_strided_p2p``), enabling zero-copy inter-GPU communication.
|
| The operator's schema should include a ``group_name`` (``str``) argument.
| Inductor's ``FallbackKernel._maybe_realize_symm_mem_args`` extracts
| ``group_name`` at compile time to allocate P2P buffers for the correct
| process group. Without ``group_name``, the automatic realization is skipped.
|
| Args:
| op_name: operator name (along with the overload) or OpOverload object.
| arg_names: list of argument names that require symmetric memory allocation.
|
| Example::
| >>> # xdoctest: +SKIP(reason="illustrative example, not runnable")
| >>> my_lib = Library("symm_mem", "FRAGMENT")
| >>> my_lib.define("one_shot_all_reduce(Tensor input, str reduce_op, str group_name) -> Tensor")
| >>> my_lib.register_symm_mem_args("one_shot_all_reduce", ["input"])
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
custom_op(name: str, fn: collections.abc.Callable | None = None, /, *, mutates_args: str | collections.abc.Iterable[str], device_types: str | collections.abc.Sequence[str] | None = None, schema: str | None = None, tags: torch.Tag | collections.abc.Sequence[torch.Tag] | None = None) -> Union[collections.abc.Callable[[collections.abc.Callable[..., object]], 'CustomOpDef'], ForwardRef('CustomOpDef')]
Wraps a function into custom operator.
Reasons why you may want to create a custom op include:
- Wrapping a third-party library or custom kernel to work with PyTorch
subsystems like Autograd.
- Preventing torch.compile/export/FX tracing from peeking inside your function.
This API is used as a decorator around a function (please see examples).
The provided function must have type hints; these are needed to interface
with PyTorch's various subsystems.
Args:
name (str): A name for the custom op that looks like "{namespace}::{name}",
e.g. "mylib::my_linear". The name is used as the op's stable identifier
in PyTorch subsystems (e.g. torch.export, FX graphs).
To avoid name collisions, please use your project name as the namespace;
e.g. all custom ops in pytorch/fbgemm use "fbgemm" as the namespace.
mutates_args (Iterable[str] or "unknown"): The names of args that the function mutates.
This MUST be accurate, otherwise, the behavior is undefined. If "unknown",
it pessimistically assumes that all inputs to the operator are being mutated.
device_types (str | None | Sequence[str]): The device type(s) the function
is valid for. If no device type is provided, then the function
is used as the default implementation for all device types.
Examples: "cpu", "cuda".
When registering a device-specific implementation for an operator that accepts no Tensors,
we require the operator to have a "device: torch.device argument".
schema (str | None): A schema string for the operator. If None
(recommended) we'll infer a schema for the operator from its type
annotations. We recommend letting us infer a schema unless you
have a specific reason not to.
Example: "(Tensor x, int y) -> (Tensor, Tensor)".
tags (Tag | Sequence[Tag] | None): one or more tags to apply to the
operator. Use ``torch.Tag.inplace`` for operators that mutate their
first Tensor argument and return it. Use ``torch.Tag.out`` for
operators that mutate keyword-only output tensors and return them.
Like PyTorch's built-in ``out=`` operators, ``torch.Tag.out``
custom ops do not support autograd.
The following types are supported for the wrapped function's input parameters:
- Scalars: ``int``, ``float``, ``bool``, ``str``, ``torch.types.Number``
- Tensors: ``torch.Tensor``
- Enums/devices: ``torch.dtype``, ``torch.device``
- Flat list of the same type: ``list[torch.Tensor]``,
``list[int]``, ``list[float]``, ``list[bool]``,
``list[torch.types.Number]``
- Optionals: ``Optional`` of any of the above scalar/tensor types
- Types registered via :func:`torch.library.register_opaque_type`
The following types are supported for the return value:
``torch.Tensor``, ``list[torch.Tensor]``, ``int``, ``float``,
``bool``, ``torch.types.Number``.
.. note::
We recommend not passing in a ``schema`` arg and instead letting us infer
it from the type annotations. It is error-prone to write your own schema.
You may wish to provide your own schema if our interpretation of
the type annotation is not what you want.
For more info on how to write a schema string, see
`here <https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/README.md#func>`_
Examples::
>>> import torch
>>> from torch import Tensor
>>> from torch.library import custom_op
>>> import numpy as np
>>>
>>> @custom_op("mylib::numpy_sin", mutates_args=())
>>> def numpy_sin(x: Tensor) -> Tensor:
>>> x_np = x.cpu().numpy()
>>> y_np = np.sin(x_np)
>>> return torch.from_numpy(y_np).to(device=x.device)
>>>
>>> x = torch.randn(3)
>>> y = numpy_sin(x)
>>> assert torch.allclose(y, x.sin())
>>>
>>> # Example of a custom op that only works for one device type.
>>> @custom_op("mylib::numpy_sin_cpu", mutates_args=(), device_types="cpu")
>>> def numpy_sin_cpu(x: Tensor) -> Tensor:
>>> x_np = x.numpy()
>>> y_np = np.sin(x_np)
>>> return torch.from_numpy(y_np)
>>>
>>> x = torch.randn(3)
>>> y = numpy_sin_cpu(x)
>>> assert torch.allclose(y, x.sin())
>>>
>>> # Example of a custom op that mutates an input
>>> @custom_op("mylib::numpy_sin_inplace", mutates_args={"x"}, device_types="cpu")
>>> def numpy_sin_inplace(x: Tensor) -> None:
>>> x_np = x.numpy()
>>> np.sin(x_np, out=x_np)
>>>
>>> x = torch.randn(3)
>>> expected = x.sin()
>>> numpy_sin_inplace(x)
>>> assert torch.allclose(x, expected)
>>>
>>> # Example of a custom op with inplace semantics
>>> @custom_op(
>>> "mylib::numpy_sin_",
>>> mutates_args={"x"},
>>> device_types="cpu",
>>> tags=torch.Tag.inplace,
>>> )
>>> def numpy_sin_(x: Tensor) -> Tensor:
>>> x_np = x.numpy()
>>> np.sin(x_np, out=x_np)
>>> return x
>>>
>>> x = torch.randn(3)
>>> expected = x.sin()
>>> result = numpy_sin_(x)
>>> assert result is x
>>> assert torch.allclose(x, expected)
>>>
>>> # Example of a custom op with out= semantics
>>> @custom_op(
>>> "mylib::numpy_sin_out",
>>> mutates_args={"out"},
>>> device_types="cpu",
>>> tags=torch.Tag.out,
>>> )
>>> def numpy_sin_out(x: Tensor, *, out: Tensor) -> Tensor:
>>> x_np = x.numpy()
>>> out_np = out.numpy()
>>> np.sin(x_np, out=out_np)
>>> return out
>>>
>>> x = torch.randn(3)
>>> out = torch.empty_like(x)
>>> result = numpy_sin_out(x, out=out)
>>> assert result is out
>>> assert torch.allclose(out, x.sin())
>>>
>>> # Example of a factory function
>>> @torch.library.custom_op("mylib::bar", mutates_args={}, device_types="cpu")
>>> def bar(device: torch.device) -> Tensor:
>>> return torch.ones(3)
>>>
>>> bar("cpu")
>>>
>>> # Example of a custom op with list inputs
>>> @custom_op("mylib::weighted_sum", mutates_args=())
>>> def weighted_sum(
>>> tensors: list[Tensor],
>>> weights: list[float],
>>> ) -> Tensor:
>>> return sum(t * w for t, w in zip(tensors, weights))
>>>
>>> x = torch.randn(3)
>>> y = torch.randn(3)
>>> out = weighted_sum([x, y], [0.3, 0.7])
define(qualname, schema, *, lib=None, tags=())
Defines a new operator.
In PyTorch, defining an op (short for "operator") is a two step-process:
- we need to define the op (by providing an operator name and schema)
- we need to implement behavior for how the operator interacts with
various PyTorch subsystems, like CPU/CUDA Tensors, Autograd, etc.
This entrypoint defines the custom operator (the first step)
you must then perform the second step by calling various
``impl_*`` APIs, like :func:`torch.library.impl` or
:func:`torch.library.register_fake`.
Args:
qualname (str): The qualified name for the operator. Should be
a string that looks like "namespace::name", e.g. "aten::sin".
Operators in PyTorch need a namespace to
avoid name collisions; a given operator may only be created once.
If you are writing a Python library, we recommend the namespace to
be the name of your top-level module.
schema (str): The schema of the operator. E.g. "(Tensor x) -> Tensor"
for an op that accepts one Tensor and returns one Tensor. It does
not contain the operator name (that is passed in ``qualname``).
lib (Optional[Library]): If provided, the lifetime of this operator
will be tied to the lifetime of the Library object.
tags (Tag | Sequence[Tag]): one or more torch.Tag to apply to this
operator. Tagging an operator changes the operator's behavior
under various PyTorch subsystems; please read the docs for the
torch.Tag carefully before applying it.
Example::
>>> import torch
>>> import numpy as np
>>>
>>> # Define the operator
>>> torch.library.define("mylib::sin", "(Tensor x) -> Tensor")
>>>
>>> # Add implementations for the operator
>>> @torch.library.impl("mylib::sin", "cpu")
>>> def f(x):
>>> return torch.from_numpy(np.sin(x.numpy()))
>>>
>>> # Call the new operator from torch.ops.
>>> x = torch.randn(3)
>>> y = torch.ops.mylib.sin(x)
>>> assert torch.allclose(y, x.sin())
fallthrough_kernel()
A dummy function to pass to ``Library.impl`` in order to register a fallthrough.
get_ctx() -> 'torch._library.fake_impl.FakeImplCtx'
get_ctx() returns the current AbstractImplCtx object.
Calling ``get_ctx()`` is only valid inside of an fake impl
(see :func:`torch.library.register_fake` for more usage details.
get_kernel(op: Union[str, ForwardRef('torch._ops.OpOverload'), ForwardRef('torch._library.custom_ops.CustomOpDef')], dispatch_key: str | torch.DispatchKey) -> torch._C._SafeKernelFunction
Returns the computed kernel for a given operator and dispatch key.
This function retrieves the kernel that would be executed for a given
operator and dispatch key combination. The returned SafeKernelFunction
can be used to call the kernel in a boxed fashion. The intended use
case for this function is to retrieve the original kernel for a given
dispatch key and then register another kernel to the same dispatch key
that calls into the original kernel for certain cases.
Args:
op: Operator name (along with the overload) or OpOverload object
Can be a string (e.g., "aten::add.Tensor"), an OpOverload, or a CustomOpDef.
dispatch_key (str | torch.DispatchKey): The dispatch key to get the kernel for.
Can be a string (e.g., "CPU", "CUDA") or a DispatchKey enum value.
Returns:
torch._C._SafeKernelFunction: A safe kernel function that can be used to
call the kernel.
Raises:
RuntimeError: If the operator does not exist.
Example:
>>> # Get the CPU kernel for torch.add
>>> kernel = torch.library.get_kernel("aten::add.Tensor", "CPU")
>>>
>>> # You can also use DispatchKey enum
>>> kernel = torch.library.get_kernel("aten::add.Tensor", torch.DispatchKey.CPU)
>>>
>>> # Or use an OpOverload directly
>>> kernel = torch.library.get_kernel(torch.ops.aten.add.Tensor, "CPU")
>>>
>>> # Example: Using get_kernel in a custom op with conditional dispatch
>>> # Get the original kernel for torch.sin
>>> original_sin_kernel = torch.library.get_kernel("aten::sin", "CPU")
>>>
>>> # If input has negative values, use original sin, otherwise return zeros
>>> def conditional_sin_impl(dispatch_keys, x):
>>> if (x < 0).any():
>>> return original_sin_kernel.call_boxed(dispatch_keys, x)
>>> else:
>>> return torch.zeros_like(x)
>>>
>>> lib = torch.library.Library("aten", "IMPL")
>>> # with_keyset=True so the first argument to the impl is the current DispatchKeySet
>>> which needs to be the first argument to ``kernel.call_boxed``
>>> lib.impl("sin", conditional_sin_impl, "CPU", with_keyset=True)
>>>
>>> # Test the conditional behavior
>>> x_positive = torch.tensor([1.0, 2.0])
>>> x_mixed = torch.tensor([-1.0, 2.0])
>>> torch.sin(x_positive)
tensor([0., 0.])
>>> torch.sin(x_mixed)
tensor([-0.8415, 0.9093])
impl(qualname: str, types: str | collections.abc.Sequence[str], func: collections.abc.Callable[~_P, ~_T] | None = None, *, lib: torch.library.Library | None = None) -> object
Register an implementation for a device type for this operator.
You may pass "default" for ``types`` to register this implementation as the
default implementation for ALL device types.
Please only use this if the implementation truly supports all device types;
for example, this is true if it is a composition of built-in PyTorch operators.
This API may be used as a decorator. You can use nested decorators
with this API provided they return a function and are placed inside
this API (see Example 2).
Some valid types are: "cpu", "cuda", "xla", "mps", "ipu", "xpu".
Args:
qualname (str): Should be a string that looks like "namespace::operator_name".
types (str | Sequence[str]): The device types to register an impl to.
lib (Optional[Library]): If provided, the lifetime of this registration
will be tied to the lifetime of the Library object.
Examples:
>>> # xdoctest: +SKIP("Requires Python <= 3.11")
>>> import torch
>>> import numpy as np
>>> # Example 1: Register function.
>>> # Define the operator
>>> torch.library.define("mylib::mysin", "(Tensor x) -> Tensor")
>>>
>>> # Add implementations for the cpu device
>>> @torch.library.impl("mylib::mysin", "cpu")
>>> def f(x):
>>> return torch.from_numpy(np.sin(x.numpy()))
>>>
>>> x = torch.randn(3)
>>> y = torch.ops.mylib.mysin(x)
>>> assert torch.allclose(y, x.sin())
>>>
>>> # Example 2: Register function with decorator.
>>> def custom_decorator(func):
>>> def wrapper(*args, **kwargs):
>>> return func(*args, **kwargs) + 1
>>> return wrapper
>>>
>>> # Define the operator
>>> torch.library.define("mylib::sin_plus_one", "(Tensor x) -> Tensor")
>>>
>>> # Add implementations for the operator
>>> @torch.library.impl("mylib::sin_plus_one", "cpu")
>>> @custom_decorator
>>> def f(x):
>>> return torch.from_numpy(np.sin(x.numpy()))
>>>
>>> # Call the new operator from torch.ops.
>>> x = torch.randn(3)
>>>
>>> y1 = torch.ops.mylib.sin_plus_one(x)
>>> y2 = torch.sin(x) + 1
>>> assert torch.allclose(y1, y2)
impl_abstract(qualname, func=None, *, lib=None, _stacklevel=1)
This API was renamed to :func:`torch.library.register_fake` in PyTorch 2.4.
Please use that instead.
infer_schema(prototype_function: Callable, /, *, mutates_args, op_name: str | None = None, tags: Union[torch.Tag, Sequence[torch.Tag], NoneType] = ()) -> str
Parses the schema of a given function with type hints. The schema is inferred from the
function's type hints, and can be used to define a new operator.
We make the following assumptions:
* None of the outputs alias any of the inputs or each other.
* | String type annotations "device, dtype, Tensor, types" without library specification are
| assumed to be torch.*. Similarly, string type annotations "Optional, List, Sequence, Union"
| without library specification are assumed to be typing.*.
* | Only the args listed in ``mutates_args`` are being mutated. If ``mutates_args`` is "unknown",
| it assumes that all inputs to the operator are being mutates.
Callers (e.g. the custom ops API) are responsible for checking these assumptions.
Args:
prototype_function: The function from which to infer a schema for from its type annotations.
op_name (Optional[str]): The name of the operator in the schema. If ``name`` is None, then the
name is not included in the inferred schema. Note that the input schema to
``torch.library.Library.define`` requires an operator name.
mutates_args ("unknown" | Iterable[str]): The arguments that are mutated in the function.
tags (Tag | Sequence[Tag] | None): one or more tags to apply to the
inferred schema. Use ``torch.Tag.inplace`` or ``torch.Tag.out`` to
infer the conventional aliasing for those operator kinds.
Returns:
The inferred schema.
Example:
>>> def foo_impl(x: torch.Tensor) -> torch.Tensor:
>>> return x.sin()
>>>
>>> infer_schema(foo_impl, op_name="foo", mutates_args={})
foo(Tensor x) -> Tensor
>>>
>>> infer_schema(foo_impl, mutates_args={})
(Tensor x) -> Tensor
register_autocast(op: Union[str, ForwardRef('torch._ops.OpOverload'), ForwardRef('torch._library.custom_ops.CustomOpDef')], device_type: str, cast_inputs: torch.dtype, /, *, lib: torch.library.Library | None = None)
Register an autocast dispatch rule for this custom op.
Valid ``device_type`` values include any device type that supports autocast.
See :func:`torch.amp.is_autocast_available` for details.
Args:
op (str | OpOverload): The operator to register an autocast dispatch rule to.
device_type(str): Device type to use. 'cuda', 'cpu', 'xpu', or any other device type that supports autocast.
The type is the same as the `type` attribute of a :class:`torch.device`.
Thus, you may obtain the device type of a tensor using `Tensor.device.type`.
cast_inputs (:class:`torch.dtype`): When custom op runs in an autocast-enabled region,
casts incoming floating-point Tensors to the target dtype (non-floating-point Tensors
are not affected), then executes custom op with autocast disabled.
lib (Optional[Library]): If provided, the lifetime of this registration
Examples::
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
>>> import torch
>>> from torch import Tensor
>>> from torch.library import custom_op
>>>
>>> # Create a custom op that works on cuda
>>> @torch.library.custom_op("mylib::my_sin", mutates_args=())
>>> def my_sin(x: Tensor) -> Tensor:
>>> return torch.sin(x)
>>>
>>> # Register autocast dispatch rule for the cuda device
>>> torch.library.register_autocast("mylib::my_sin", "cuda", torch.float16)
>>>
>>> x = torch.randn(3, dtype=torch.float32, device="cuda")
>>> with torch.autocast("cuda", dtype=torch.float16):
>>> y = torch.ops.mylib.my_sin(x)
>>> assert y.dtype == torch.float16
register_fake(op: Union[str, ForwardRef('torch._ops.OpOverload'), ForwardRef('torch._library.custom_ops.CustomOpDef')], func: collections.abc.Callable | None = None, /, *, lib: torch.library.Library | None = None, _stacklevel: int = 1, allow_override: bool = True)
Register a FakeTensor implementation ("fake impl") for this operator.
Also sometimes known as a "meta kernel", "abstract impl".
An "FakeTensor implementation" specifies the behavior of this operator on
Tensors that carry no data ("FakeTensor"). Given some input Tensors with
certain properties (sizes/strides/storage_offset/device), it specifies
what the properties of the output Tensors are.
The FakeTensor implementation has the same signature as the operator.
It is run for both FakeTensors and meta tensors. To write a FakeTensor
implementation, assume that all Tensor inputs to the operator are
regular CPU/CUDA/Meta tensors, but they do not have storage, and
you are trying to return regular CPU/CUDA/Meta tensor(s) as output.
The FakeTensor implementation must consist of only PyTorch operations
(and may not directly access the storage or data of any input or
intermediate Tensors).
This API may be used as a decorator (see examples).
For a detailed guide on custom ops, please see
https://pytorch.org/tutorials/advanced/custom_ops_landing_page.html
Args:
op_name: Operator name (along with the overload) or OpOverload object.
func: Fake tensor implementation.
lib (Optional[Library]): Library to register the fake tensor to.
allow_override: Flag controlling if we want to override an
existing registered fake impl. This is on by default;
pass ``False`` to error if the operator already has a
fake impl. This also only applies if the custom operator
was not created via torch.library.custom_op, as
overriding an existing fake impl is already allowed.
Examples:
>>> import torch
>>> import numpy as np
>>> from torch import Tensor
>>>
>>> # Example 1: an operator without data-dependent output shape
>>> @torch.library.custom_op("mylib::custom_linear", mutates_args=())
>>> def custom_linear(x: Tensor, weight: Tensor, bias: Tensor) -> Tensor:
>>> raise NotImplementedError("Implementation goes here")
>>>
>>> @torch.library.register_fake("mylib::custom_linear")
>>> def _(x, weight, bias):
>>> assert x.dim() == 2
>>> assert weight.dim() == 2
>>> assert bias.dim() == 1
>>> assert x.shape[1] == weight.shape[1]
>>> assert weight.shape[0] == bias.shape[0]
>>> assert x.device == weight.device
>>>
>>> return (x @ weight.t()) + bias
>>>
>>> with torch._subclasses.fake_tensor.FakeTensorMode():
>>> x = torch.randn(2, 3)
>>> w = torch.randn(3, 3)
>>> b = torch.randn(3)
>>> y = torch.ops.mylib.custom_linear(x, w, b)
>>>
>>> assert y.shape == (2, 3)
>>>
>>> # Example 2: an operator with data-dependent output shape
>>> @torch.library.custom_op("mylib::custom_nonzero", mutates_args=())
>>> def custom_nonzero(x: Tensor) -> Tensor:
>>> x_np = x.numpy(force=True)
>>> res = np.stack(np.nonzero(x_np), axis=1)
>>> return torch.tensor(res, device=x.device)
>>>
>>> @torch.library.register_fake("mylib::custom_nonzero")
>>> def _(x):
>>> # Number of nonzero-elements is data-dependent.
>>> # Since we cannot peek at the data in an fake impl,
>>> # we use the ctx object to construct a new symint that
>>> # represents the data-dependent size.
>>> ctx = torch.library.get_ctx()
>>> nnz = ctx.new_dynamic_size()
>>> shape = [nnz, x.dim()]
>>> result = x.new_empty(shape, dtype=torch.int64)
>>> return result
>>>
>>> from torch.fx.experimental.proxy_tensor import make_fx
>>>
>>> x = torch.tensor([0, 1, 2, 3, 4, 0])
>>> trace = make_fx(torch.ops.mylib.custom_nonzero, tracing_mode="symbolic")(x)
>>> trace.print_readable()
>>>
>>> assert torch.allclose(trace(x), torch.ops.mylib.custom_nonzero(x))
register_torch_dispatch(op: Union[str, ForwardRef('torch._ops.OpOverload'), ForwardRef('torch._library.custom_ops.CustomOpDef')], torch_dispatch_class: Any, func: collections.abc.Callable | None = None, /, *, lib: torch.library.Library | None = None)
Registers a torch_dispatch rule for the given operator and ``torch_dispatch_class``.
This allows for open registration to specify the behavior between the operator
and the ``torch_dispatch_class`` without needing to modify the ``torch_dispatch_class``
or the operator directly.
The ``torch_dispatch_class`` is either a Tensor subclass with ``__torch_dispatch__`` or a
TorchDispatchMode.
If it is a Tensor subclass, we expect ``func`` to have the following signature:
``(cls, func: OpOverload, types: Tuple[type, ...], args, kwargs) -> Any``
If it is a TorchDispatchMode, we expect ``func`` to have the following signature:
``(mode, func: OpOverload, types: Tuple[type, ...], args, kwargs) -> Any``
``args`` and ``kwargs`` will have been normalized the same way they are
in ``__torch_dispatch__`` (see :ref:`torch-dispatch-calling-convention`).
Examples:
>>> import torch
>>>
>>> @torch.library.custom_op("mylib::foo", mutates_args={})
>>> def foo(x: torch.Tensor) -> torch.Tensor:
>>> return x.clone()
>>>
>>> class MyMode(torch.utils._python_dispatch.TorchDispatchMode):
>>> def __torch_dispatch__(self, func, types, args=(), kwargs=None):
>>> return func(*args, **kwargs)
>>>
>>> @torch.library.register_torch_dispatch("mylib::foo", MyMode)
>>> def _(mode, func, types, args, kwargs):
>>> x, = args
>>> return x + 1
>>>
>>> x = torch.randn(3)
>>> y = foo(x)
>>> assert torch.allclose(y, x)
>>>
>>> with MyMode():
>>> y = foo(x)
>>> assert torch.allclose(y, x + 1)
register_vmap(op: Union[str, ForwardRef('torch._ops.OpOverload'), ForwardRef('torch._library.custom_ops.CustomOpDef')], func: collections.abc.Callable | None = None, /, *, lib=None)
Register a vmap implementation to support :func:`torch.vmap` for this custom op.
This API may be used as a decorator (see examples).
In order for an operator to work with :func:`torch.vmap`, you may need to register a
vmap implementation in the following signature:
``vmap_func(info, in_dims: Tuple[Optional[int]], *args, **kwargs)``,
where ``*args`` and ``**kwargs`` are the arguments and kwargs for ``op``.
We do not support kwarg-only Tensor args.
It specifies how do we compute the batched version of ``op`` given inputs with an additional
dimension (specified by ``in_dims``).
For each arg in ``args``, ``in_dims`` has a corresponding ``Optional[int]``. It is ``None``
if the arg is not a Tensor or if the arg is not being vmapped over, otherwise, it is an integer
specifying what dimension of the Tensor is being vmapped over.
``info`` is a collection of additional metadata that may be helpful:
``info.batch_size`` specifies the size of the dimension being vmapped over, while
``info.randomness`` is the ``randomness`` option that was passed to :func:`torch.vmap`.
The return of the function ``func`` is a tuple of ``(output, out_dims)``. Similar to ``in_dims``,
``out_dims`` should be of the same structure as ``output`` and contain one ``out_dim``
per output that specifies if the output has the vmapped dimension and what index it is in.
Examples:
>>> import torch
>>> import numpy as np
>>> from torch import Tensor
>>> from typing import Tuple
>>>
>>> def to_numpy(tensor):
>>> return tensor.cpu().numpy()
>>>
>>> lib = torch.library.Library("mylib", "FRAGMENT")
>>> @torch.library.custom_op("mylib::numpy_cube", mutates_args=())
>>> def numpy_cube(x: Tensor) -> Tuple[Tensor, Tensor]:
>>> x_np = to_numpy(x)
>>> dx = torch.tensor(3 * x_np ** 2, device=x.device)
>>> return torch.tensor(x_np ** 3, device=x.device), dx
>>>
>>> def numpy_cube_vmap(info, in_dims, x):
>>> result = numpy_cube(x)
>>> return result, (in_dims[0], in_dims[0])
>>>
>>> torch.library.register_vmap(numpy_cube, numpy_cube_vmap)
>>>
>>> x = torch.randn(3)
>>> torch.vmap(numpy_cube)(x)
>>>
>>> @torch.library.custom_op("mylib::numpy_mul", mutates_args=())
>>> def numpy_mul(x: Tensor, y: Tensor) -> Tensor:
>>> return torch.tensor(to_numpy(x) * to_numpy(y), device=x.device)
>>>
>>> @torch.library.register_vmap("mylib::numpy_mul")
>>> def numpy_mul_vmap(info, in_dims, x, y):
>>> x_bdim, y_bdim = in_dims
>>> x = x.movedim(x_bdim, -1) if x_bdim is not None else x.unsqueeze(-1)
>>> y = y.movedim(y_bdim, -1) if y_bdim is not None else y.unsqueeze(-1)
>>> result = x * y
>>> result = result.movedim(-1, 0)
>>> return result, 0
>>>
>>>
>>> x = torch.randn(3)
>>> y = torch.randn(3)
>>> torch.vmap(numpy_mul)(x, y)
.. note::
The vmap function should aim to preserve the semantics of the entire custom operator.
That is, ``grad(vmap(op))`` should be replaceable with a ``grad(map(op))``.
If your custom operator has any custom behavior in the backward pass, please
keep this in mind.
triton_op(name: str, fn: collections.abc.Callable | None = None, /, *, mutates_args: str | collections.abc.Iterable[str], schema: str | None = None) -> collections.abc.Callable
Create a custom operator whose implementation is backed by 1+ triton kernels.
This is a more structured way of using triton kernels with PyTorch.
Prefer using triton kernels with no ``torch.library`` custom operator wrappers
(like :func:`torch.library.custom_op`, :func:`torch.library.triton_op`) because
that is simpler;
only use :func:`torch.library.custom_op`/:func:`torch.library.triton_op` if you
want to create an operator that behaves like PyTorch built-in operators.
For example, you may use a ``torch.library`` wrapper API to define the
behavior of the triton kernel when passed a tensor subclass or under
a TorchDispatchMode.
Use :func:`torch.library.triton_op` instead of :func:`torch.library.custom_op`
when the implementation
consists of 1+ triton kernels. :func:`torch.library.custom_op` treats
custom operators as opaque (:func:`torch.compile` and
:func:`torch.export.export` will never trace into them), but ``triton_op``
makes the implementation visible to these subsystems, allowing them
to optimize the triton kernel(s).
Note that ``fn`` must only consist of calls to PyTorch-understood
operators and triton kernels. Any triton kernels called inside ``fn``
must be wrapped in a call to :func:`torch.library.wrap_triton`.
Args:
name (str): A name for the custom op that looks like "{namespace}::{name}",
e.g. "mylib::my_linear". The name is used as the op's stable identifier
in PyTorch subsystems (e.g. torch.export, FX graphs).
To avoid name collisions, please use your project name as the namespace;
e.g. all custom ops in pytorch/fbgemm use "fbgemm" as the namespace.
mutates_args (Iterable[str] or "unknown"): The names of args that the function mutates.
This MUST be accurate, otherwise, the behavior is undefined. If "unknown",
it pessimistically assumes that all inputs to the operator are being mutated.
schema (str | None): A schema string for the operator. If None
(recommended) we'll infer a schema for the operator from its type
annotations. We recommend letting us infer a schema unless you
have a specific reason not to.
Example: "(Tensor x, int y) -> (Tensor, Tensor)".
Example::
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
>>> import torch
>>> from torch.library import triton_op, wrap_triton
>>>
>>> import triton
>>> from triton import language as tl
>>>
>>> @triton.jit
>>> def add_kernel(
>>> in_ptr0,
>>> in_ptr1,
>>> out_ptr,
>>> n_elements,
>>> BLOCK_SIZE: "tl.constexpr",
>>> ):
>>> pid = tl.program_id(axis=0)
>>> block_start = pid * BLOCK_SIZE
>>> offsets = block_start + tl.arange(0, BLOCK_SIZE)
>>> mask = offsets < n_elements
>>> x = tl.load(in_ptr0 + offsets, mask=mask)
>>> y = tl.load(in_ptr1 + offsets, mask=mask)
>>> output = x + y
>>> tl.store(out_ptr + offsets, output, mask=mask)
>>>
>>> @triton_op("mylib::add", mutates_args={})
>>> def add(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
>>> output = torch.empty_like(x)
>>> n_elements = output.numel()
>>>
>>> def grid(meta):
>>> return (triton.cdiv(n_elements, meta["BLOCK_SIZE"]),)
>>>
>>> # NB: we need to wrap the triton kernel in a call to wrap_triton
>>> wrap_triton(add_kernel)[grid](x, y, output, n_elements, 16)
>>> return output
>>>
>>> @torch.compile
>>> def f(x, y):
>>> return add(x, y)
>>>
>>> x = torch.randn(3, device="cuda")
>>> y = torch.randn(3, device="cuda")
>>>
>>> z = f(x, y)
>>> assert torch.allclose(z, x + y)
wrap_triton(triton_kernel: collections.abc.Callable, /) -> Any
Allows capture of a triton kernel into a graph via make_fx or
non-strict ``torch.export``.
These technologies perform Dispatcher-based tracing (via
``__torch_dispatch__``) and cannot see calls to raw triton kernels.
The ``wrap_triton`` API wraps a triton kernel into a callable that
can actually be traced into a graph.
Please use this API together with :func:`torch.library.triton_op`.
Examples:
>>> # xdoctest: +SKIP
>>> import torch
>>> import triton
>>> from triton import language as tl
>>> from torch.fx.experimental.proxy_tensor import make_fx
>>> from torch.library import wrap_triton
>>>
>>> @triton.jit
>>> def add_kernel(
>>> in_ptr0,
>>> in_ptr1,
>>> out_ptr,
>>> n_elements,
>>> BLOCK_SIZE: "tl.constexpr",
>>> ):
>>> pid = tl.program_id(axis=0)
>>> block_start = pid * BLOCK_SIZE
>>> offsets = block_start + tl.arange(0, BLOCK_SIZE)
>>> mask = offsets < n_elements
>>> x = tl.load(in_ptr0 + offsets, mask=mask)
>>> y = tl.load(in_ptr1 + offsets, mask=mask)
>>> output = x + y
>>> tl.store(out_ptr + offsets, output, mask=mask)
>>>
>>> def add(x, y):
>>> output = torch.empty_like(x)
>>> n_elements = output.numel()
>>>
>>> def grid_fn(meta):
>>> return (triton.cdiv(n_elements, meta["BLOCK_SIZE"]),)
>>>
>>> wrap_triton(add_kernel)[grid_fn](x, y, output, n_elements, 16)
>>> return output
>>>
>>> x = torch.randn(3, device="cuda")
>>> y = torch.randn(3, device="cuda")
>>> gm = make_fx(add)(x, y)
>>> print(gm.code)
>>> # def forward(self, x_1, y_1):
>>> # empty_like = torch.ops.aten.empty_like.default(x_1, pin_memory = False)
>>> # triton_kernel_wrapper_mutation_proxy = triton_kernel_wrapper_mutation(
>>> # kernel_idx = 0, constant_args_idx = 0,
>>> # grid = [(1, 1, 1)], kwargs = {
>>> # 'in_ptr0': x_1, 'in_ptr1': y_1, 'out_ptr': empty_like,
>>> # 'n_elements': 3, 'BLOCK_SIZE': 16
>>> # })
>>> # return empty_like
DATA
__all__ = ['Library', 'impl', 'define', 'fallthrough_kernel', 'impl_ab...
__annotations__ = {'_defs': set[str], '_impls': set[str], '_keep_alive...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\library.py
torch.linalg
Python Library Documentation: package torch.linalg in torch
NAME
torch.linalg
PACKAGE CONTENTS
FUNCTIONS
cholesky = linalg_cholesky(...)
linalg.cholesky(A, *, upper=False, out=None) -> Tensor
Computes the Cholesky decomposition of a complex Hermitian or real symmetric positive-definite matrix.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
the **Cholesky decomposition** of a complex Hermitian or real symmetric positive-definite matrix
:math:`A \in \mathbb{K}^{n \times n}` is defined as
.. math::
A = LL^{\text{H}}\mathrlap{\qquad L \in \mathbb{K}^{n \times n}}
where :math:`L` is a lower triangular matrix with real positive diagonal (even in the complex case) and
:math:`L^{\text{H}}` is the conjugate transpose when :math:`L` is complex, and the transpose when :math:`L` is real-valued.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
.. note:: When inputs are on a CUDA device, this function synchronizes that device with the CPU. For a version of this function that does not synchronize, see :func:`torch.linalg.cholesky_ex`.
.. seealso::
:func:`torch.linalg.cholesky_ex` for a version of this operation that
skips the (slow) error checking by default and instead returns the debug
information. This makes it a faster way to check if a matrix is
positive-definite.
:func:`torch.linalg.eigh` for a different decomposition of a Hermitian matrix.
The eigenvalue decomposition gives more information about the matrix but it
slower to compute than the Cholesky decomposition.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
consisting of symmetric or Hermitian positive-definite matrices.
Keyword args:
upper (bool, optional): whether to return an upper triangular matrix.
The tensor returned with upper=True is the conjugate transpose of the tensor
returned with upper=False.
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Raises:
RuntimeError: if the :attr:`A` matrix or any matrix in a batched :attr:`A` is not Hermitian
(resp. symmetric) positive-definite. If :attr:`A` is a batch of matrices,
the error message will include the batch index of the first matrix that fails
to meet this condition.
Examples::
>>> A = torch.randn(2, 2, dtype=torch.complex128)
>>> A = A @ A.T.conj() + torch.eye(2) # creates a Hermitian positive-definite matrix
>>> A
tensor([[2.5266+0.0000j, 1.9586-2.0626j],
[1.9586+2.0626j, 9.4160+0.0000j]], dtype=torch.complex128)
>>> L = torch.linalg.cholesky(A)
>>> L
tensor([[1.5895+0.0000j, 0.0000+0.0000j],
[1.2322+1.2976j, 2.4928+0.0000j]], dtype=torch.complex128)
>>> torch.dist(L @ L.T.conj(), A)
tensor(4.4692e-16, dtype=torch.float64)
>>> A = torch.randn(3, 2, 2, dtype=torch.float64)
>>> A = A @ A.mT + torch.eye(2) # batch of symmetric positive-definite matrices
>>> L = torch.linalg.cholesky(A)
>>> torch.dist(L @ L.mT, A)
tensor(5.8747e-16, dtype=torch.float64)
cholesky_ex = linalg_cholesky_ex(...)
linalg.cholesky_ex(A, *, upper=False, check_errors=False, out=None) -> (Tensor, Tensor)
Computes the Cholesky decomposition of a complex Hermitian or real
symmetric positive-definite matrix.
This function skips the (slow) error checking and error message construction
of :func:`torch.linalg.cholesky`, instead directly returning the LAPACK
error codes as part of a named tuple ``(L, info)``. This makes this function
a faster way to check if a matrix is positive-definite, and it provides an
opportunity to handle decomposition errors more gracefully or performantly
than :func:`torch.linalg.cholesky` does.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
If :attr:`A` is not a Hermitian positive-definite matrix, or if it's a batch of matrices
and one or more of them is not a Hermitian positive-definite matrix,
then ``info`` stores a positive integer for the corresponding matrix.
The positive integer indicates the order of the leading minor that is not positive-definite,
and the decomposition could not be completed.
``info`` filled with zeros indicates that the decomposition was successful.
If ``check_errors=True`` and ``info`` contains positive integers, then a RuntimeError is thrown.
.. note:: When the inputs are on a CUDA device, this function synchronizes only when :attr:`check_errors`\ `= True`.
.. warning:: This function is "experimental" and it may change in a future PyTorch release.
.. seealso::
:func:`torch.linalg.cholesky` is a NumPy compatible variant that always checks for errors.
Args:
A (Tensor): the Hermitian `n \times n` matrix or the batch of such matrices of size
`(*, n, n)` where `*` is one or more batch dimensions.
Keyword args:
upper (bool, optional): whether to return an upper triangular matrix.
The tensor returned with upper=True is the conjugate transpose of the tensor
returned with upper=False.
check_errors (bool, optional): controls whether to check the content of ``infos``. Default: `False`.
out (tuple, optional): tuple of two tensors to write the output to. Ignored if `None`. Default: `None`.
Examples::
>>> A = torch.randn(2, 2, dtype=torch.complex128)
>>> A = A @ A.t().conj() # creates a Hermitian positive-definite matrix
>>> L, info = torch.linalg.cholesky_ex(A)
>>> A
tensor([[ 2.3792+0.0000j, -0.9023+0.9831j],
[-0.9023-0.9831j, 0.8757+0.0000j]], dtype=torch.complex128)
>>> L
tensor([[ 1.5425+0.0000j, 0.0000+0.0000j],
[-0.5850-0.6374j, 0.3567+0.0000j]], dtype=torch.complex128)
>>> info
tensor(0, dtype=torch.int32)
cond = linalg_cond(...)
linalg.cond(A, p=None, *, out=None) -> Tensor
Computes the condition number of a matrix with respect to a matrix norm.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
the **condition number** :math:`\kappa` of a matrix
:math:`A \in \mathbb{K}^{n \times n}` is defined as
.. math::
\kappa(A) = \|A\|_p\|A^{-1}\|_p
The condition number of :attr:`A` measures the numerical stability of the linear system `AX = B`
with respect to a matrix norm.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
:attr:`p` defines the matrix norm that is computed. The following norms are supported:
========= =================================
:attr:`p` matrix norm
========= =================================
`None` `2`-norm (largest singular value)
`'fro'` Frobenius norm
`'nuc'` nuclear norm
`inf` `max(sum(abs(x), dim=1))`
`-inf` `min(sum(abs(x), dim=1))`
`1` `max(sum(abs(x), dim=0))`
`-1` `min(sum(abs(x), dim=0))`
`2` largest singular value
`-2` smallest singular value
========= =================================
where `inf` refers to `float('inf')`, NumPy's `inf` object, or any equivalent object.
For :attr:`p` is one of `('fro', 'nuc', inf, -inf, 1, -1)`, this function uses
:func:`torch.linalg.norm` and :func:`torch.linalg.inv`.
As such, in this case, the matrix (or every matrix in the batch) :attr:`A` has to be square
and invertible.
For :attr:`p` in `(2, -2)`, this function can be computed in terms of the singular values
:math:`\sigma_1 \geq \ldots \geq \sigma_n`
.. math::
\kappa_2(A) = \frac{\sigma_1}{\sigma_n}\qquad \kappa_{-2}(A) = \frac{\sigma_n}{\sigma_1}
In these cases, it is computed using :func:`torch.linalg.svdvals`. For these norms, the matrix
(or every matrix in the batch) :attr:`A` may have any shape.
.. note :: When inputs are on a CUDA device, this function synchronizes that device with the CPU
if :attr:`p` is one of `('fro', 'nuc', inf, -inf, 1, -1)`.
.. seealso::
:func:`torch.linalg.solve` for a function that solves linear systems of square matrices.
:func:`torch.linalg.lstsq` for a function that solves linear systems of general matrices.
Args:
A (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions
for :attr:`p` in `(2, -2)`, and of shape `(*, n, n)` where every matrix
is invertible for :attr:`p` in `('fro', 'nuc', inf, -inf, 1, -1)`.
p (int, inf, -inf, 'fro', 'nuc', optional):
the type of the matrix norm to use in the computations (see above). Default: `None`
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Returns:
A real-valued tensor, even when :attr:`A` is complex.
Raises:
RuntimeError:
if :attr:`p` is one of `('fro', 'nuc', inf, -inf, 1, -1)`
and the :attr:`A` matrix or any matrix in the batch :attr:`A` is not square
or invertible.
Examples::
>>> A = torch.randn(3, 4, 4, dtype=torch.complex64)
>>> torch.linalg.cond(A)
>>> A = torch.tensor([[1., 0, -1], [0, 1, 0], [1, 0, 1]])
>>> torch.linalg.cond(A)
tensor([1.4142])
>>> torch.linalg.cond(A, 'fro')
tensor(3.1623)
>>> torch.linalg.cond(A, 'nuc')
tensor(9.2426)
>>> torch.linalg.cond(A, float('inf'))
tensor(2.)
>>> torch.linalg.cond(A, float('-inf'))
tensor(1.)
>>> torch.linalg.cond(A, 1)
tensor(2.)
>>> torch.linalg.cond(A, -1)
tensor(1.)
>>> torch.linalg.cond(A, 2)
tensor([1.4142])
>>> torch.linalg.cond(A, -2)
tensor([0.7071])
>>> A = torch.randn(2, 3, 3)
>>> torch.linalg.cond(A)
tensor([[9.5917],
[3.2538]])
>>> A = torch.randn(2, 3, 3, dtype=torch.complex64)
>>> torch.linalg.cond(A)
tensor([[4.6245],
[4.5671]])
cross = linalg_cross(...)
linalg.cross(input, other, *, dim=-1, out=None) -> Tensor
Computes the cross product of two 3-dimensional vectors.
Supports input of float, double, cfloat and cdouble dtypes. Also supports batches
of vectors, for which it computes the product along the dimension :attr:`dim`.
It broadcasts over the batch dimensions.
Args:
input (Tensor): the first input tensor.
other (Tensor): the second input tensor.
dim (int, optional): the dimension along which to take the cross-product. Default: `-1`.
Keyword args:
out (Tensor, optional): the output tensor. Ignored if `None`. Default: `None`.
Example:
>>> a = torch.randn(4, 3)
>>> a
tensor([[-0.3956, 1.1455, 1.6895],
[-0.5849, 1.3672, 0.3599],
[-1.1626, 0.7180, -0.0521],
[-0.1339, 0.9902, -2.0225]])
>>> b = torch.randn(4, 3)
>>> b
tensor([[-0.0257, -1.4725, -1.2251],
[-1.1479, -0.7005, -1.9757],
[-1.3904, 0.3726, -1.1836],
[-0.9688, -0.7153, 0.2159]])
>>> torch.linalg.cross(a, b)
tensor([[ 1.0844, -0.5281, 0.6120],
[-2.4490, -1.5687, 1.9792],
[-0.8304, -1.3037, 0.5650],
[-1.2329, 1.9883, 1.0551]])
>>> a = torch.randn(1, 3) # a is broadcast to match shape of b
>>> a
tensor([[-0.9941, -0.5132, 0.5681]])
>>> torch.linalg.cross(a, b)
tensor([[ 1.4653, -1.2325, 1.4507],
[ 1.4119, -2.6163, 0.1073],
[ 0.3957, -1.9666, -1.0840],
[ 0.2956, -0.3357, 0.2139]])
det = linalg_det(...)
linalg.det(A, *, out=None) -> Tensor
Computes the determinant of a square matrix.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
.. seealso::
:func:`torch.linalg.slogdet` computes the sign and natural logarithm of the absolute
value of the determinant of square matrices.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions.
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Examples::
>>> A = torch.randn(3, 3)
>>> torch.linalg.det(A)
tensor(0.0934)
>>> A = torch.randn(3, 2, 2)
>>> torch.linalg.det(A)
tensor([1.1990, 0.4099, 0.7386])
diagonal = linalg_diagonal(...)
linalg.diagonal(A, *, offset=0, dim1=-2, dim2=-1) -> Tensor
Alias for :func:`torch.diagonal` with defaults :attr:`dim1`\ `= -2`, :attr:`dim2`\ `= -1`.
eig = linalg_eig(...)
linalg.eig(A, *, out=None) -> (Tensor, Tensor)
Computes the eigenvalue decomposition of a square matrix if it exists.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
the **eigenvalue decomposition** of a square matrix
:math:`A \in \mathbb{K}^{n \times n}` (if it exists) is defined as
.. math::
A = V \operatorname{diag}(\Lambda) V^{-1}\mathrlap{\qquad V \in \mathbb{C}^{n \times n}, \Lambda \in \mathbb{C}^n}
This decomposition exists if and only if :math:`A` is `diagonalizable`_.
This is the case when all its eigenvalues are different.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
The returned eigenvalues are not guaranteed to be in any specific order.
.. note:: The eigenvalues and eigenvectors of a real matrix may be complex.
.. note:: When inputs are on a CUDA device, this function synchronizes that device with the CPU.
.. warning:: This function assumes that :attr:`A` is `diagonalizable`_ (for example, when all the
eigenvalues are different). If it is not diagonalizable, the returned
eigenvalues will be correct but :math:`A \neq V \operatorname{diag}(\Lambda)V^{-1}`.
.. warning:: The returned eigenvectors are normalized to have norm `1`.
Even then, the eigenvectors of a matrix are not unique, nor are they continuous with respect to
:attr:`A`. Due to this lack of uniqueness, different hardware and software may compute
different eigenvectors.
This non-uniqueness is caused by the fact that multiplying an eigenvector by
by :math:`e^{i \phi}, \phi \in \mathbb{R}` produces another set of valid eigenvectors
of the matrix. For this reason, the loss function shall not depend on the phase of the
eigenvectors, as this quantity is not well-defined.
This is checked when computing the gradients of this function. As such,
when inputs are on a CUDA device, the computation of the gradients
of this function synchronizes that device with the CPU.
.. warning:: Gradients computed using the `eigenvectors` tensor will only be finite when
:attr:`A` has distinct eigenvalues.
Furthermore, if the distance between any two eigenvalues is close to zero,
the gradient will be numerically unstable, as it depends on the eigenvalues
:math:`\lambda_i` through the computation of
:math:`\frac{1}{\min_{i \neq j} \lambda_i - \lambda_j}`.
.. seealso::
:func:`torch.linalg.eigvals` computes only the eigenvalues.
Unlike :func:`torch.linalg.eig`, the gradients of :func:`~eigvals` are always
numerically stable.
:func:`torch.linalg.eigh` for a (faster) function that computes the eigenvalue decomposition
for Hermitian and symmetric matrices.
:func:`torch.linalg.svd` for a function that computes another type of spectral
decomposition that works on matrices of any shape.
:func:`torch.linalg.qr` for another (much faster) decomposition that works on matrices of
any shape.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
consisting of diagonalizable matrices.
Keyword args:
out (tuple, optional): output tuple of two tensors. Ignored if `None`. Default: `None`.
Returns:
A named tuple `(eigenvalues, eigenvectors)` which corresponds to :math:`\Lambda` and :math:`V` above.
`eigenvalues` and `eigenvectors` will always be complex-valued, even when :attr:`A` is real. The eigenvectors
will be given by the columns of `eigenvectors`.
Examples::
>>> A = torch.randn(2, 2, dtype=torch.complex128)
>>> A
tensor([[ 0.9828+0.3889j, -0.4617+0.3010j],
[ 0.1662-0.7435j, -0.6139+0.0562j]], dtype=torch.complex128)
>>> L, V = torch.linalg.eig(A)
>>> L
tensor([ 1.1226+0.5738j, -0.7537-0.1286j], dtype=torch.complex128)
>>> V
tensor([[ 0.9218+0.0000j, 0.1882-0.2220j],
[-0.0270-0.3867j, 0.9567+0.0000j]], dtype=torch.complex128)
>>> torch.dist(V @ torch.diag(L) @ torch.linalg.inv(V), A)
tensor(7.7119e-16, dtype=torch.float64)
>>> A = torch.randn(3, 2, 2, dtype=torch.float64)
>>> L, V = torch.linalg.eig(A)
>>> torch.dist(V @ torch.diag_embed(L) @ torch.linalg.inv(V), A)
tensor(3.2841e-16, dtype=torch.float64)
.. _diagonalizable:
https://en.wikipedia.org/wiki/Diagonalizable_matrix#Definition
eigh = linalg_eigh(...)
linalg.eigh(A, UPLO='L', *, out=None) -> (Tensor, Tensor)
Computes the eigenvalue decomposition of a complex Hermitian or real symmetric matrix.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
the **eigenvalue decomposition** of a complex Hermitian or real symmetric matrix
:math:`A \in \mathbb{K}^{n \times n}` is defined as
.. math::
A = Q \operatorname{diag}(\Lambda) Q^{\text{H}}\mathrlap{\qquad Q \in \mathbb{K}^{n \times n}, \Lambda \in \mathbb{R}^n}
where :math:`Q^{\text{H}}` is the conjugate transpose when :math:`Q` is complex, and the transpose when :math:`Q` is real-valued.
:math:`Q` is orthogonal in the real case and unitary in the complex case.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
:attr:`A` is assumed to be Hermitian (resp. symmetric), but this is not checked internally, instead:
- If :attr:`UPLO`\ `= 'L'` (default), only the lower triangular part of the matrix is used in the computation.
- If :attr:`UPLO`\ `= 'U'`, only the upper triangular part of the matrix is used.
The eigenvalues are returned in ascending order.
.. note:: When inputs are on a CUDA device, this function synchronizes that device with the CPU.
.. note:: The eigenvalues of real symmetric or complex Hermitian matrices are always real.
.. warning:: The eigenvectors of a symmetric matrix are not unique, nor are they continuous with
respect to :attr:`A`. Due to this lack of uniqueness, different hardware and
software may compute different eigenvectors.
This non-uniqueness is caused by the fact that multiplying an eigenvector by
`-1` in the real case or by :math:`e^{i \phi}, \phi \in \mathbb{R}` in the complex
case produces another set of valid eigenvectors of the matrix.
For this reason, the loss function shall not depend on the phase of the eigenvectors, as
this quantity is not well-defined.
This is checked for complex inputs when computing the gradients of this function. As such,
when inputs are complex and are on a CUDA device, the computation of the gradients
of this function synchronizes that device with the CPU.
.. warning:: Gradients computed using the `eigenvectors` tensor will only be finite when
:attr:`A` has distinct eigenvalues.
Furthermore, if the distance between any two eigenvalues is close to zero,
the gradient will be numerically unstable, as it depends on the eigenvalues
:math:`\lambda_i` through the computation of
:math:`\frac{1}{\min_{i \neq j} \lambda_i - \lambda_j}`.
.. warning:: User may see pytorch crashes if running `eigh` on CUDA devices with CUDA versions before 12.1 update 1
with large ill-conditioned matrices as inputs.
Refer to :ref:`Linear Algebra Numerical Stability<Linear Algebra Stability>` for more details.
If this is the case, user may (1) tune their matrix inputs to be less ill-conditioned,
or (2) use :func:`torch.backends.cuda.preferred_linalg_library` to
try other supported backends.
.. seealso::
:func:`torch.linalg.eigvalsh` computes only the eigenvalues of a Hermitian matrix.
Unlike :func:`torch.linalg.eigh`, the gradients of :func:`~eigvalsh` are always
numerically stable.
:func:`torch.linalg.cholesky` for a different decomposition of a Hermitian matrix.
The Cholesky decomposition gives less information about the matrix but is much faster
to compute than the eigenvalue decomposition.
:func:`torch.linalg.eig` for a (slower) function that computes the eigenvalue decomposition
of a not necessarily Hermitian square matrix.
:func:`torch.linalg.svd` for a (slower) function that computes the more general SVD
decomposition of matrices of any shape.
:func:`torch.linalg.qr` for another (much faster) decomposition that works on general
matrices.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
consisting of symmetric or Hermitian matrices.
UPLO ('L', 'U', optional): controls whether to use the upper or lower triangular part
of :attr:`A` in the computations. Default: `'L'`.
Keyword args:
out (tuple, optional): output tuple of two tensors. Ignored if `None`. Default: `None`.
Returns:
A named tuple `(eigenvalues, eigenvectors)` which corresponds to :math:`\Lambda` and :math:`Q` above.
`eigenvalues` will always be real-valued, even when :attr:`A` is complex.
It will also be ordered in ascending order.
`eigenvectors` will have the same dtype as :attr:`A` and will contain the eigenvectors as its columns.
Examples::
>>> A = torch.randn(2, 2, dtype=torch.complex128)
>>> A = A + A.T.conj() # creates a Hermitian matrix
>>> A
tensor([[2.9228+0.0000j, 0.2029-0.0862j],
[0.2029+0.0862j, 0.3464+0.0000j]], dtype=torch.complex128)
>>> L, Q = torch.linalg.eigh(A)
>>> L
tensor([0.3277, 2.9415], dtype=torch.float64)
>>> Q
tensor([[-0.0846+-0.0000j, -0.9964+0.0000j],
[ 0.9170+0.3898j, -0.0779-0.0331j]], dtype=torch.complex128)
>>> torch.dist(Q @ torch.diag(L.cdouble()) @ Q.T.conj(), A)
tensor(6.1062e-16, dtype=torch.float64)
>>> A = torch.randn(3, 2, 2, dtype=torch.float64)
>>> A = A + A.mT # creates a batch of symmetric matrices
>>> L, Q = torch.linalg.eigh(A)
>>> torch.dist(Q @ torch.diag_embed(L) @ Q.mH, A)
tensor(1.5423e-15, dtype=torch.float64)
eigvals = linalg_eigvals(...)
linalg.eigvals(A, *, out=None) -> Tensor
Computes the eigenvalues of a square matrix.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
the **eigenvalues** of a square matrix :math:`A \in \mathbb{K}^{n \times n}` are defined
as the roots (counted with multiplicity) of the polynomial `p` of degree `n` given by
.. math::
p(\lambda) = \operatorname{det}(A - \lambda \mathrm{I}_n)\mathrlap{\qquad \lambda \in \mathbb{C}}
where :math:`\mathrm{I}_n` is the `n`-dimensional identity matrix.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
The returned eigenvalues are not guaranteed to be in any specific order.
.. note:: The eigenvalues of a real matrix may be complex, as the roots of a real polynomial may be complex.
The eigenvalues of a matrix are always well-defined, even when the matrix is not diagonalizable.
.. note:: When inputs are on a CUDA device, this function synchronizes that device with the CPU.
.. seealso::
:func:`torch.linalg.eig` computes the full eigenvalue decomposition.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions.
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Returns:
A complex-valued tensor containing the eigenvalues even when :attr:`A` is real.
Examples::
>>> A = torch.randn(2, 2, dtype=torch.complex128)
>>> L = torch.linalg.eigvals(A)
>>> L
tensor([ 1.1226+0.5738j, -0.7537-0.1286j], dtype=torch.complex128)
>>> torch.dist(L, torch.linalg.eig(A).eigenvalues)
tensor(2.4576e-07)
eigvalsh = linalg_eigvalsh(...)
linalg.eigvalsh(A, UPLO='L', *, out=None) -> Tensor
Computes the eigenvalues of a complex Hermitian or real symmetric matrix.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
the **eigenvalues** of a complex Hermitian or real symmetric matrix :math:`A \in \mathbb{K}^{n \times n}`
are defined as the roots (counted with multiplicity) of the polynomial `p` of degree `n` given by
.. math::
p(\lambda) = \operatorname{det}(A - \lambda \mathrm{I}_n)\mathrlap{\qquad \lambda \in \mathbb{R}}
where :math:`\mathrm{I}_n` is the `n`-dimensional identity matrix.
The eigenvalues of a real symmetric or complex Hermitian matrix are always real.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
The eigenvalues are returned in ascending order.
:attr:`A` is assumed to be Hermitian (resp. symmetric), but this is not checked internally, instead:
- If :attr:`UPLO`\ `= 'L'` (default), only the lower triangular part of the matrix is used in the computation.
- If :attr:`UPLO`\ `= 'U'`, only the upper triangular part of the matrix is used.
.. note:: When inputs are on a CUDA device, this function synchronizes that device with the CPU.
.. seealso::
:func:`torch.linalg.eigh` computes the full eigenvalue decomposition.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
consisting of symmetric or Hermitian matrices.
UPLO ('L', 'U', optional): controls whether to use the upper or lower triangular part
of :attr:`A` in the computations. Default: `'L'`.
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Returns:
A real-valued tensor containing the eigenvalues even when :attr:`A` is complex.
The eigenvalues are returned in ascending order.
Examples::
>>> A = torch.randn(2, 2, dtype=torch.complex128)
>>> A = A + A.T.conj() # creates a Hermitian matrix
>>> A
tensor([[2.9228+0.0000j, 0.2029-0.0862j],
[0.2029+0.0862j, 0.3464+0.0000j]], dtype=torch.complex128)
>>> torch.linalg.eigvalsh(A)
tensor([0.3277, 2.9415], dtype=torch.float64)
>>> A = torch.randn(3, 2, 2, dtype=torch.float64)
>>> A = A + A.mT # creates a batch of symmetric matrices
>>> torch.linalg.eigvalsh(A)
tensor([[ 2.5797, 3.4629],
[-4.1605, 1.3780],
[-3.1113, 2.7381]], dtype=torch.float64)
householder_product = linalg_householder_product(...)
householder_product(A, tau, *, out=None) -> Tensor
Computes the first `n` columns of a product of Householder matrices.
Let :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`, and
let :math:`A \in \mathbb{K}^{m \times n}` be a matrix with columns :math:`a_i \in \mathbb{K}^m`
for :math:`i=1,\ldots,m` with :math:`m \geq n`. Denote by :math:`b_i` the vector resulting from
zeroing out the first :math:`i-1` components of :math:`a_i` and setting to `1` the :math:`i`-th.
For a vector :math:`\tau \in \mathbb{K}^k` with :math:`k \leq n`, this function computes the
first :math:`n` columns of the matrix
.. math::
H_1H_2 ... H_k \qquad\text{with}\qquad H_i = \mathrm{I}_m - \tau_i b_i b_i^{\text{H}}
where :math:`\mathrm{I}_m` is the `m`-dimensional identity matrix and :math:`b^{\text{H}}` is the
conjugate transpose when :math:`b` is complex, and the transpose when :math:`b` is real-valued.
The output matrix is the same size as the input matrix :attr:`A`.
See `Representation of Orthogonal or Unitary Matrices`_ for further details.
Supports inputs of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if the inputs are batches of matrices then
the output has the same batch dimensions.
.. seealso::
:func:`torch.geqrf` can be used together with this function to form the `Q` from the
:func:`~qr` decomposition.
:func:`torch.ormqr` is a related function that computes the matrix multiplication
of a product of Householder matrices with another matrix.
However, that function is not supported by autograd.
.. warning::
Gradient computations are only well-defined if :math:`\tau_i \neq \frac{1}{||a_i||^2}`.
If this condition is not met, no error will be thrown, but the gradient produced may contain `NaN`.
Args:
A (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
tau (Tensor): tensor of shape `(*, k)` where `*` is zero or more batch dimensions.
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Raises:
RuntimeError: if :attr:`A` doesn't satisfy the requirement `m >= n`,
or :attr:`tau` doesn't satisfy the requirement `n >= k`.
Examples::
>>> A = torch.randn(2, 2)
>>> h, tau = torch.geqrf(A)
>>> Q = torch.linalg.householder_product(h, tau)
>>> torch.dist(Q, torch.linalg.qr(A).Q)
tensor(0.)
>>> h = torch.randn(3, 2, 2, dtype=torch.complex128)
>>> tau = torch.randn(3, 1, dtype=torch.complex128)
>>> Q = torch.linalg.householder_product(h, tau)
>>> Q
tensor([[[ 1.8034+0.4184j, 0.2588-1.0174j],
[-0.6853+0.7953j, 2.0790+0.5620j]],
[[ 1.4581+1.6989j, -1.5360+0.1193j],
[ 1.3877-0.6691j, 1.3512+1.3024j]],
[[ 1.4766+0.5783j, 0.0361+0.6587j],
[ 0.6396+0.1612j, 1.3693+0.4481j]]], dtype=torch.complex128)
.. _Representation of Orthogonal or Unitary Matrices:
https://www.netlib.org/lapack/lug/node128.html
inv = linalg_inv(...)
linalg.inv(A, *, out=None) -> Tensor
Computes the inverse of a square matrix if it exists.
Throws a `RuntimeError` if the matrix is not invertible.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
for a matrix :math:`A \in \mathbb{K}^{n \times n}`,
its **inverse matrix** :math:`A^{-1} \in \mathbb{K}^{n \times n}` (if it exists) is defined as
.. math::
A^{-1}A = AA^{-1} = \mathrm{I}_n
where :math:`\mathrm{I}_n` is the `n`-dimensional identity matrix.
The inverse matrix exists if and only if :math:`A` is `invertible`_. In this case,
the inverse is unique.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices
then the output has the same batch dimensions.
.. note:: When inputs are on a CUDA device, this function synchronizes that device with the CPU. For a version of this function that does not synchronize, see :func:`torch.linalg.inv_ex`.
.. note::
Consider using :func:`torch.linalg.solve` if possible for multiplying a matrix on the left by
the inverse, as::
linalg.solve(A, B) == linalg.inv(A) @ B # When B is a matrix
It is always preferred to use :func:`~solve` when possible, as it is faster and more
numerically stable than computing the inverse explicitly.
.. seealso::
:func:`torch.linalg.pinv` computes the pseudoinverse (Moore-Penrose inverse) of matrices
of any shape.
:func:`torch.linalg.solve` computes :attr:`A`\ `.inv() @ \ `:attr:`B` with a
numerically stable algorithm.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
consisting of invertible matrices.
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Raises:
RuntimeError: if the matrix :attr:`A` or any matrix in the batch of matrices :attr:`A` is not invertible.
Examples::
>>> A = torch.randn(4, 4)
>>> Ainv = torch.linalg.inv(A)
>>> torch.dist(A @ Ainv, torch.eye(4))
tensor(1.1921e-07)
>>> A = torch.randn(2, 3, 4, 4) # Batch of matrices
>>> Ainv = torch.linalg.inv(A)
>>> torch.dist(A @ Ainv, torch.eye(4))
tensor(1.9073e-06)
>>> A = torch.randn(4, 4, dtype=torch.complex128) # Complex matrix
>>> Ainv = torch.linalg.inv(A)
>>> torch.dist(A @ Ainv, torch.eye(4))
tensor(7.5107e-16, dtype=torch.float64)
.. _invertible:
https://en.wikipedia.org/wiki/Invertible_matrix#The_invertible_matrix_theorem
inv_ex = linalg_inv_ex(...)
linalg.inv_ex(A, *, check_errors=False, out=None) -> (Tensor, Tensor)
Computes the inverse of a square matrix if it is invertible.
Returns a namedtuple ``(inverse, info)``. ``inverse`` contains the result of
inverting :attr:`A` and ``info`` stores the LAPACK error codes.
If :attr:`A` is not an invertible matrix, or if it's a batch of matrices
and one or more of them is not an invertible matrix,
then ``info`` stores a positive integer for the corresponding matrix.
The positive integer indicates the diagonal element of the LU decomposition of
the input matrix that is exactly zero.
``info`` filled with zeros indicates that the inversion was successful.
If ``check_errors=True`` and ``info`` contains positive integers, then a RuntimeError is thrown.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
.. note:: When the inputs are on a CUDA device, this function synchronizes only when :attr:`check_errors`\ `= True`.
.. warning:: This function is "experimental" and it may change in a future PyTorch release.
.. seealso::
:func:`torch.linalg.inv` is a NumPy compatible variant that always checks for errors.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
consisting of square matrices.
check_errors (bool, optional): controls whether to check the content of ``info``. Default: `False`.
Keyword args:
out (tuple, optional): tuple of two tensors to write the output to. Ignored if `None`. Default: `None`.
Examples::
>>> A = torch.randn(3, 3)
>>> Ainv, info = torch.linalg.inv_ex(A)
>>> torch.dist(torch.linalg.inv(A), Ainv)
tensor(0.)
>>> info
tensor(0, dtype=torch.int32)
ldl_factor = linalg_ldl_factor(...)
linalg.ldl_factor(A, *, hermitian=False, out=None) -> (Tensor, Tensor)
Computes a compact representation of the LDL factorization of a Hermitian or symmetric (possibly indefinite) matrix.
When :attr:`A` is complex valued it can be Hermitian (:attr:`hermitian`\ `= True`)
or symmetric (:attr:`hermitian`\ `= False`).
The factorization is of the form :math:`A = L D L^T`.
If :attr:`hermitian` is `True` then transpose operation is the conjugate transpose.
:math:`L` (or :math:`U`) and :math:`D` are stored in compact form in ``LD``.
They follow the format specified by `LAPACK's sytrf`_ function.
These tensors may be used in :func:`torch.linalg.ldl_solve` to solve linear systems.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
.. note:: When inputs are on a CUDA device, this function synchronizes that device with the CPU. For a version of this function that does not synchronize, see :func:`torch.linalg.ldl_factor_ex`.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
consisting of symmetric or Hermitian matrices.
Keyword args:
hermitian (bool, optional): whether to consider the input to be Hermitian or symmetric.
For real-valued matrices, this switch has no effect. Default: `False`.
out (tuple, optional): tuple of two tensors to write the output to. Ignored if `None`. Default: `None`.
Returns:
A named tuple `(LD, pivots)`.
Examples::
>>> A = torch.randn(3, 3)
>>> A = A @ A.mT # make symmetric
>>> A
tensor([[7.2079, 4.2414, 1.9428],
[4.2414, 3.4554, 0.3264],
[1.9428, 0.3264, 1.3823]])
>>> LD, pivots = torch.linalg.ldl_factor(A)
>>> LD
tensor([[ 7.2079, 0.0000, 0.0000],
[ 0.5884, 0.9595, 0.0000],
[ 0.2695, -0.8513, 0.1633]])
>>> pivots
tensor([1, 2, 3], dtype=torch.int32)
.. _LAPACK's sytrf:
https://www.netlib.org/lapack/explore-html-3.6.1/d3/db6/group__double_s_ycomputational_gad91bde1212277b3e909eb6af7f64858a.html
ldl_factor_ex = linalg_ldl_factor_ex(...)
linalg.ldl_factor_ex(A, *, hermitian=False, check_errors=False, out=None) -> (Tensor, Tensor, Tensor)
This is a version of :func:`~ldl_factor` that does not perform error checks unless :attr:`check_errors`\ `= True`.
It also returns the :attr:`info` tensor returned by `LAPACK's sytrf`_.
``info`` stores integer error codes from the backend library.
A positive integer indicates the diagonal element of :math:`D` that is zero.
Division by 0 will occur if the result is used for solving a system of linear equations.
``info`` filled with zeros indicates that the factorization was successful.
If ``check_errors=True`` and ``info`` contains positive integers, then a `RuntimeError` is thrown.
.. note:: When the inputs are on a CUDA device, this function synchronizes only when :attr:`check_errors`\ `= True`.
.. warning:: This function is "experimental" and it may change in a future PyTorch release.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
consisting of symmetric or Hermitian matrices.
Keyword args:
hermitian (bool, optional): whether to consider the input to be Hermitian or symmetric.
For real-valued matrices, this switch has no effect. Default: `False`.
check_errors (bool, optional): controls whether to check the content of ``info`` and raise
an error if it is non-zero. Default: `False`.
out (tuple, optional): tuple of three tensors to write the output to. Ignored if `None`. Default: `None`.
Returns:
A named tuple `(LD, pivots, info)`.
Examples::
>>> A = torch.randn(3, 3)
>>> A = A @ A.mT # make symmetric
>>> A
tensor([[7.2079, 4.2414, 1.9428],
[4.2414, 3.4554, 0.3264],
[1.9428, 0.3264, 1.3823]])
>>> LD, pivots, info = torch.linalg.ldl_factor_ex(A)
>>> LD
tensor([[ 7.2079, 0.0000, 0.0000],
[ 0.5884, 0.9595, 0.0000],
[ 0.2695, -0.8513, 0.1633]])
>>> pivots
tensor([1, 2, 3], dtype=torch.int32)
>>> info
tensor(0, dtype=torch.int32)
.. _LAPACK's sytrf:
https://www.netlib.org/lapack/explore-html-3.6.1/d3/db6/group__double_s_ycomputational_gad91bde1212277b3e909eb6af7f64858a.html
ldl_solve = linalg_ldl_solve(...)
linalg.ldl_solve(LD, pivots, B, *, hermitian=False, out=None) -> Tensor
Computes the solution of a system of linear equations using the LDL factorization.
:attr:`LD` and :attr:`pivots` are the compact representation of the LDL factorization and
are expected to be computed by :func:`torch.linalg.ldl_factor_ex`.
:attr:`hermitian` argument to this function should be the same
as the corresponding arguments in :func:`torch.linalg.ldl_factor_ex`.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
.. warning:: This function is "experimental" and it may change in a future PyTorch release.
Args:
LD (Tensor): the `n \times n` matrix or the batch of such matrices of size
`(*, n, n)` where `*` is one or more batch dimensions.
pivots (Tensor): the pivots corresponding to the LDL factorization of :attr:`LD`.
B (Tensor): right-hand side tensor of shape `(*, n, k)`.
Keyword args:
hermitian (bool, optional): whether to consider the decomposed matrix to be Hermitian or symmetric.
For real-valued matrices, this switch has no effect. Default: `False`.
out (tuple, optional): output tensor. `B` may be passed as `out` and the result is computed in-place on `B`.
Ignored if `None`. Default: `None`.
Examples::
>>> A = torch.randn(2, 3, 3)
>>> A = A @ A.mT # make symmetric
>>> LD, pivots, info = torch.linalg.ldl_factor_ex(A)
>>> B = torch.randn(2, 3, 4)
>>> X = torch.linalg.ldl_solve(LD, pivots, B)
>>> torch.linalg.norm(A @ X - B)
>>> tensor(0.0001)
lstsq = linalg_lstsq(...)
torch.linalg.lstsq(A, B, rcond=None, *, driver=None) -> (Tensor, Tensor, Tensor, Tensor)
Computes a solution to the least squares problem of a system of linear equations.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
the **least squares problem** for a linear system :math:`AX = B` with
:math:`A \in \mathbb{K}^{m \times n}, B \in \mathbb{K}^{m \times k}` is defined as
.. math::
\min_{X \in \mathbb{K}^{n \times k}} \|AX - B\|_F
where :math:`\|-\|_F` denotes the Frobenius norm.
Supports inputs of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if the inputs are batches of matrices then
the output has the same batch dimensions.
:attr:`driver` chooses the backend function that will be used.
For CPU inputs the valid values are `'gels'`, `'gelsy'`, `'gelsd`, `'gelss'`.
To choose the best driver on CPU consider:
- If :attr:`A` is well-conditioned (its `condition number`_ is not too large), or you do not mind some precision loss.
- For a general matrix: `'gelsy'` (QR with pivoting) (default)
- If :attr:`A` is full-rank: `'gels'` (QR)
- If :attr:`A` is not well-conditioned.
- `'gelsd'` (tridiagonal reduction and SVD)
- But if you run into memory issues: `'gelss'` (full SVD).
For CUDA input, the only valid driver is `'gels'`, which assumes that :attr:`A` is full-rank.
See also the `full description of these drivers`_
:attr:`rcond` is used to determine the effective rank of the matrices in :attr:`A`
when :attr:`driver` is one of (`'gelsy'`, `'gelsd'`, `'gelss'`).
In this case, if :math:`\sigma_i` are the singular values of `A` in decreasing order,
:math:`\sigma_i` will be rounded down to zero if :math:`\sigma_i \leq \text{rcond} \cdot \sigma_1`.
If :attr:`rcond`\ `= None` (default), :attr:`rcond` is set to the machine precision of the dtype of :attr:`A` times `max(m, n)`.
This function returns the solution to the problem and some extra information in a named tuple of
four tensors `(solution, residuals, rank, singular_values)`. For inputs :attr:`A`, :attr:`B`
of shape `(*, m, n)`, `(*, m, k)` respectively, it contains
- `solution`: the least squares solution. It has shape `(*, n, k)`.
- `residuals`: the squared residuals of the solutions, that is, :math:`\|AX - B\|_F^2`.
It has shape `(*, k)`.
It is computed when `m > n` and every matrix in :attr:`A` is full-rank,
otherwise, it is an empty tensor.
If :attr:`A` is a batch of matrices and any matrix in the batch is not full rank,
then an empty tensor is returned. This behavior may change in a future PyTorch release.
- `rank`: tensor of ranks of the matrices in :attr:`A`.
It has shape equal to the batch dimensions of :attr:`A`.
It is computed when :attr:`driver` is one of (`'gelsy'`, `'gelsd'`, `'gelss'`),
otherwise it is an empty tensor.
- `singular_values`: tensor of singular values of the matrices in :attr:`A`.
It has shape `(*, min(m, n))`.
It is computed when :attr:`driver` is one of (`'gelsd'`, `'gelss'`),
otherwise it is an empty tensor.
.. note::
This function computes `X = \ `:attr:`A`\ `.pinverse() @ \ `:attr:`B` in a faster and
more numerically stable way than performing the computations separately.
.. warning::
The default value of :attr:`rcond` may change in a future PyTorch release.
It is therefore recommended to use a fixed value to avoid potential
breaking changes.
Args:
A (Tensor): lhs tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
B (Tensor): rhs tensor of shape `(*, m, k)` where `*` is zero or more batch dimensions.
rcond (float, optional): used to determine the effective rank of :attr:`A`.
If :attr:`rcond`\ `= None`, :attr:`rcond` is set to the machine
precision of the dtype of :attr:`A` times `max(m, n)`. Default: `None`.
Keyword args:
driver (str, optional): name of the LAPACK/MAGMA method to be used.
If `None`, `'gelsy'` is used for CPU inputs and `'gels'` for CUDA inputs.
Default: `None`.
Returns:
A named tuple `(solution, residuals, rank, singular_values)`.
Examples::
>>> A = torch.randn(1,3,3)
>>> A
tensor([[[-1.0838, 0.0225, 0.2275],
[ 0.2438, 0.3844, 0.5499],
[ 0.1175, -0.9102, 2.0870]]])
>>> B = torch.randn(2,3,3)
>>> B
tensor([[[-0.6772, 0.7758, 0.5109],
[-1.4382, 1.3769, 1.1818],
[-0.3450, 0.0806, 0.3967]],
[[-1.3994, -0.1521, -0.1473],
[ 1.9194, 1.0458, 0.6705],
[-1.1802, -0.9796, 1.4086]]])
>>> X = torch.linalg.lstsq(A, B).solution # A is broadcasted to shape (2, 3, 3)
>>> torch.dist(X, torch.linalg.pinv(A) @ B)
tensor(1.5152e-06)
>>> S = torch.linalg.lstsq(A, B, driver='gelsd').singular_values
>>> torch.dist(S, torch.linalg.svdvals(A))
tensor(2.3842e-07)
>>> A[:, 0].zero_() # Decrease the rank of A
>>> rank = torch.linalg.lstsq(A, B).rank
>>> rank
tensor([2])
.. _condition number:
https://pytorch.org/docs/main/linalg.html#torch.linalg.cond
.. _full description of these drivers:
https://www.netlib.org/lapack/lug/node27.html
lu = linalg_lu(...)
lu(A, *, pivot=True, out=None) -> (Tensor, Tensor, Tensor)
Computes the LU decomposition with partial pivoting of a matrix.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
the **LU decomposition with partial pivoting** of a matrix
:math:`A \in \mathbb{K}^{m \times n}` is defined as
.. math::
A = PLU\mathrlap{\qquad P \in \mathbb{K}^{m \times m}, L \in \mathbb{K}^{m \times k}, U \in \mathbb{K}^{k \times n}}
where `k = min(m,n)`, :math:`P` is a `permutation matrix`_, :math:`L` is lower triangular with ones on the diagonal
and :math:`U` is upper triangular.
If :attr:`pivot`\ `= False` and :attr:`A` is on GPU, then the **LU decomposition without pivoting** is computed
.. math::
A = LU\mathrlap{\qquad L \in \mathbb{K}^{m \times k}, U \in \mathbb{K}^{k \times n}}
When :attr:`pivot`\ `= False`, the returned matrix :attr:`P` will be empty.
The LU decomposition without pivoting `may not exist`_ if any of the principal minors of :attr:`A` is singular.
In this case, the output matrix may contain `inf` or `NaN`.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
.. seealso::
:func:`torch.linalg.solve` solves a system of linear equations using the LU decomposition
with partial pivoting.
.. warning:: The LU decomposition is almost never unique, as often there are different permutation
matrices that can yield different LU decompositions.
As such, different platforms, like SciPy, or inputs on different devices,
may produce different valid decompositions.
.. warning:: Gradient computations are only supported if the input matrix is full-rank.
If this condition is not met, no error will be thrown, but the gradient
may not be finite.
This is because the LU decomposition with pivoting is not differentiable at these points.
Args:
A (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
pivot (bool, optional): Controls whether to compute the LU decomposition with partial pivoting or
no pivoting. Default: `True`.
Keyword args:
out (tuple, optional): output tuple of three tensors. Ignored if `None`. Default: `None`.
Returns:
A named tuple `(P, L, U)`.
Examples::
>>> A = torch.randn(3, 2)
>>> P, L, U = torch.linalg.lu(A)
>>> P
tensor([[0., 1., 0.],
[0., 0., 1.],
[1., 0., 0.]])
>>> L
tensor([[1.0000, 0.0000],
[0.5007, 1.0000],
[0.0633, 0.9755]])
>>> U
tensor([[0.3771, 0.0489],
[0.0000, 0.9644]])
>>> torch.dist(A, P @ L @ U)
tensor(5.9605e-08)
>>> A = torch.randn(2, 5, 7, device="cuda")
>>> P, L, U = torch.linalg.lu(A, pivot=False)
>>> P
tensor([], device='cuda:0')
>>> torch.dist(A, L @ U)
tensor(1.0376e-06, device='cuda:0')
.. _permutation matrix:
https://en.wikipedia.org/wiki/Permutation_matrix
.. _may not exist:
https://en.wikipedia.org/wiki/LU_decomposition#Definitions
lu_factor = linalg_lu_factor(...)
linalg.lu_factor(A, *, bool pivot=True, out=None) -> (Tensor, Tensor)
Computes a compact representation of the LU factorization with partial pivoting of a matrix.
This function computes a compact representation of the decomposition given by :func:`torch.linalg.lu`.
If the matrix is square, this representation may be used in :func:`torch.linalg.lu_solve`
to solve system of linear equations that share the matrix :attr:`A`.
The returned decomposition is represented as a named tuple `(LU, pivots)`.
The ``LU`` matrix has the same shape as the input matrix ``A``. Its upper and lower triangular
parts encode the non-constant elements of ``L`` and ``U`` of the LU decomposition of ``A``.
The returned permutation matrix is represented by a 1-indexed vector. `pivots[i] == j` represents
that in the `i`-th step of the algorithm, the `i`-th row was permuted with the `j-1`-th row.
On CUDA, one may use :attr:`pivot`\ `= False`. In this case, this function returns the LU
decomposition without pivoting if it exists.
Supports inputs of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if the inputs are batches of matrices then
the output has the same batch dimensions.
.. note:: When inputs are on a CUDA device, this function synchronizes that device with the CPU. For a version of this function that does not synchronize, see :func:`torch.linalg.lu_factor_ex`.
.. warning:: The LU decomposition is almost never unique, as often there are different permutation
matrices that can yield different LU decompositions.
As such, different platforms, like SciPy, or inputs on different devices,
may produce different valid decompositions.
Gradient computations are only supported if the input matrix is full-rank.
If this condition is not met, no error will be thrown, but the gradient may not be finite.
This is because the LU decomposition with pivoting is not differentiable at these points.
.. seealso::
:func:`torch.linalg.lu_solve` solves a system of linear equations given the output of this
function provided the input matrix was square and invertible.
:func:`torch.lu_unpack` unpacks the tensors returned by :func:`~lu_factor` into the three
matrices `P, L, U` that form the decomposition.
:func:`torch.linalg.lu` computes the LU decomposition with partial pivoting of a possibly
non-square matrix. It is a composition of :func:`~lu_factor` and :func:`torch.lu_unpack`.
:func:`torch.linalg.solve` solves a system of linear equations. It is a composition
of :func:`~lu_factor` and :func:`~lu_solve`.
Args:
A (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
Keyword args:
pivot (bool, optional): Whether to compute the LU decomposition with partial pivoting, or the regular LU
decomposition. :attr:`pivot`\ `= False` not supported on CPU. Default: `True`.
out (tuple, optional): tuple of two tensors to write the output to. Ignored if `None`. Default: `None`.
Returns:
A named tuple `(LU, pivots)`.
Raises:
RuntimeError: if the :attr:`A` matrix is not invertible or any matrix in a batched :attr:`A`
is not invertible.
Examples::
>>> A = torch.randn(2, 3, 3)
>>> B1 = torch.randn(2, 3, 4)
>>> B2 = torch.randn(2, 3, 7)
>>> LU, pivots = torch.linalg.lu_factor(A)
>>> X1 = torch.linalg.lu_solve(LU, pivots, B1)
>>> X2 = torch.linalg.lu_solve(LU, pivots, B2)
>>> torch.allclose(A @ X1, B1)
True
>>> torch.allclose(A @ X2, B2)
True
.. _invertible:
https://en.wikipedia.org/wiki/Invertible_matrix#The_invertible_matrix_theorem
lu_factor_ex = linalg_lu_factor_ex(...)
linalg.lu_factor_ex(A, *, pivot=True, check_errors=False, out=None) -> (Tensor, Tensor, Tensor)
This is a version of :func:`~lu_factor` that does not perform error checks unless :attr:`check_errors`\ `= True`.
It also returns the :attr:`info` tensor returned by `LAPACK's getrf`_.
.. note:: When the inputs are on a CUDA device, this function synchronizes only when :attr:`check_errors`\ `= True`.
.. warning:: This function is "experimental" and it may change in a future PyTorch release.
Args:
A (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
Keyword args:
pivot (bool, optional): Whether to compute the LU decomposition with partial pivoting, or the regular LU
decomposition. :attr:`pivot`\ `= False` not supported on CPU. Default: `True`.
check_errors (bool, optional): controls whether to check the content of ``infos`` and raise
an error if it is non-zero. Default: `False`.
out (tuple, optional): tuple of three tensors to write the output to. Ignored if `None`. Default: `None`.
Returns:
A named tuple `(LU, pivots, info)`.
.. _LAPACK's getrf:
https://www.netlib.org/lapack/explore-html-3.6.1/dd/d9a/group__double_g_ecomputational_ga0019443faea08275ca60a734d0593e60.html
lu_solve = linalg_lu_solve(...)
linalg.lu_solve(LU, pivots, B, *, left=True, adjoint=False, out=None) -> Tensor
Computes the solution of a square system of linear equations with a unique solution given an LU decomposition.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
this function computes the solution :math:`X \in \mathbb{K}^{n \times k}` of the **linear system** associated to
:math:`A \in \mathbb{K}^{n \times n}, B \in \mathbb{K}^{n \times k}`, which is defined as
.. math:: AX = B
where :math:`A` is given factorized as returned by :func:`~lu_factor`.
If :attr:`left`\ `= False`, this function returns the matrix :math:`X \in \mathbb{K}^{n \times k}` that solves the system
.. math::
XA = B\mathrlap{\qquad A \in \mathbb{K}^{k \times k}, B \in \mathbb{K}^{n \times k}.}
If :attr:`adjoint`\ `= True` (and :attr:`left`\ `= True`), given an LU factorization of :math:`A`
this function function returns the :math:`X \in \mathbb{K}^{n \times k}` that solves the system
.. math::
A^{\text{H}}X = B\mathrlap{\qquad A \in \mathbb{K}^{k \times k}, B \in \mathbb{K}^{n \times k}.}
where :math:`A^{\text{H}}` is the conjugate transpose when :math:`A` is complex, and the
transpose when :math:`A` is real-valued. The :attr:`left`\ `= False` case is analogous.
Supports inputs of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if the inputs are batches of matrices then
the output has the same batch dimensions.
Args:
LU (Tensor): tensor of shape `(*, n, n)` (or `(*, k, k)` if :attr:`left`\ `= True`)
where `*` is zero or more batch dimensions as returned by :func:`~lu_factor`.
pivots (Tensor): tensor of shape `(*, n)` (or `(*, k)` if :attr:`left`\ `= True`)
where `*` is zero or more batch dimensions as returned by :func:`~lu_factor`.
B (Tensor): right-hand side tensor of shape `(*, n, k)`.
Keyword args:
left (bool, optional): whether to solve the system :math:`AX=B` or :math:`XA = B`. Default: `True`.
adjoint (bool, optional): whether to solve the system :math:`AX=B` or :math:`A^{\text{H}}X = B`. Default: `False`.
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Examples::
>>> A = torch.randn(3, 3)
>>> LU, pivots = torch.linalg.lu_factor(A)
>>> B = torch.randn(3, 2)
>>> X = torch.linalg.lu_solve(LU, pivots, B)
>>> torch.allclose(A @ X, B)
True
>>> B = torch.randn(3, 3, 2) # Broadcasting rules apply: A is broadcasted
>>> X = torch.linalg.lu_solve(LU, pivots, B)
>>> torch.allclose(A @ X, B)
True
>>> B = torch.randn(3, 5, 3)
>>> X = torch.linalg.lu_solve(LU, pivots, B, left=False)
>>> torch.allclose(X @ A, B)
True
>>> B = torch.randn(3, 3, 4) # Now solve for A^T
>>> X = torch.linalg.lu_solve(LU, pivots, B, adjoint=True)
>>> torch.allclose(A.mT @ X, B)
True
.. _invertible:
https://en.wikipedia.org/wiki/Invertible_matrix#The_invertible_matrix_theorem
matmul = linalg_matmul(...)
linalg.matmul(input, other, *, out=None) -> Tensor
Alias for :func:`torch.matmul`
matrix_exp = linalg_matrix_exp(...)
linalg.matrix_exp(A) -> Tensor
Computes the matrix exponential of a square matrix.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
this function computes the **matrix exponential** of :math:`A \in \mathbb{K}^{n \times n}`, which is defined as
.. math::
\mathrm{matrix\_exp}(A) = \sum_{k=0}^\infty \frac{1}{k!}A^k \in \mathbb{K}^{n \times n}.
If the matrix :math:`A` has eigenvalues :math:`\lambda_i \in \mathbb{C}`,
the matrix :math:`\mathrm{matrix\_exp}(A)` has eigenvalues :math:`e^{\lambda_i} \in \mathbb{C}`.
Supports input of bfloat16, float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions.
Example::
>>> A = torch.empty(2, 2, 2)
>>> A[0, :, :] = torch.eye(2, 2)
>>> A[1, :, :] = 2 * torch.eye(2, 2)
>>> A
tensor([[[1., 0.],
[0., 1.]],
[[2., 0.],
[0., 2.]]])
>>> torch.linalg.matrix_exp(A)
tensor([[[2.7183, 0.0000],
[0.0000, 2.7183]],
[[7.3891, 0.0000],
[0.0000, 7.3891]]])
>>> import math
>>> A = torch.tensor([[0, math.pi/3], [-math.pi/3, 0]]) # A is skew-symmetric
>>> torch.linalg.matrix_exp(A) # matrix_exp(A) = [[cos(pi/3), sin(pi/3)], [-sin(pi/3), cos(pi/3)]]
tensor([[ 0.5000, 0.8660],
[-0.8660, 0.5000]])
matrix_norm = linalg_matrix_norm(...)
linalg.matrix_norm(A, ord='fro', dim=(-2, -1), keepdim=False, *, dtype=None, out=None) -> Tensor
Computes a matrix norm.
If :attr:`A` is complex valued, it computes the norm of :attr:`A`\ `.abs()`
Support input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices: the norm will be computed over the
dimensions specified by the 2-tuple :attr:`dim` and the other dimensions will
be treated as batch dimensions. The output will have the same batch dimensions.
:attr:`ord` defines the matrix norm that is computed. The following norms are supported:
====================== ========================================================
:attr:`ord` matrix norm
====================== ========================================================
`'fro'` (default) Frobenius norm
`'nuc'` nuclear norm
`inf` `max(sum(abs(x), dim=1))`
`-inf` `min(sum(abs(x), dim=1))`
`1` `max(sum(abs(x), dim=0))`
`-1` `min(sum(abs(x), dim=0))`
`2` largest singular value
`-2` smallest singular value
====================== ========================================================
where `inf` refers to `float('inf')`, NumPy's `inf` object, or any equivalent object.
Args:
A (Tensor): tensor with two or more dimensions. By default its
shape is interpreted as `(*, m, n)` where `*` is zero or more
batch dimensions, but this behavior can be controlled using :attr:`dim`.
ord (int, inf, -inf, 'fro', 'nuc', optional): order of norm. Default: `'fro'`
dim (Tuple[int, int], optional): dimensions over which to compute the norm. Default: `(-2, -1)`
keepdim (bool, optional): If set to `True`, the reduced dimensions are retained
in the result as dimensions with size one. Default: `False`
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
dtype (:class:`torch.dtype`, optional): If specified, the input tensor is cast to
:attr:`dtype` before performing the operation, and the returned tensor's type
will be :attr:`dtype`. Default: `None`
Returns:
A real-valued tensor, even when :attr:`A` is complex.
Examples::
>>> from torch import linalg as LA
>>> A = torch.arange(9, dtype=torch.float).reshape(3, 3)
>>> A
tensor([[0., 1., 2.],
[3., 4., 5.],
[6., 7., 8.]])
>>> LA.matrix_norm(A)
tensor(14.2829)
>>> LA.matrix_norm(A, ord=-1)
tensor(9.)
>>> B = A.expand(2, -1, -1)
>>> B
tensor([[[0., 1., 2.],
[3., 4., 5.],
[6., 7., 8.]],
[[0., 1., 2.],
[3., 4., 5.],
[6., 7., 8.]]])
>>> LA.matrix_norm(B)
tensor([14.2829, 14.2829])
>>> LA.matrix_norm(B, dim=(0, 2))
tensor([ 3.1623, 10.0000, 17.2627])
matrix_power = linalg_matrix_power(...)
matrix_power(A, n, *, out=None) -> Tensor
Computes the `n`-th power of a square matrix for an integer `n`.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
If :attr:`n`\ `= 0`, it returns the identity matrix (or batch) of the same shape
as :attr:`A`. If :attr:`n` is negative, it returns the inverse of each matrix
(if invertible) raised to the power of `abs(n)`.
.. note::
Consider using :func:`torch.linalg.solve` if possible for multiplying a matrix on the left by
a negative power as, if :attr:`n`\ `> 0`::
torch.linalg.solve(matrix_power(A, n), B) == matrix_power(A, -n) @ B
It is always preferred to use :func:`~solve` when possible, as it is faster and more
numerically stable than computing :math:`A^{-n}` explicitly.
.. seealso::
:func:`torch.linalg.solve` computes :attr:`A`\ `.inverse() @ \ `:attr:`B` with a
numerically stable algorithm.
Args:
A (Tensor): tensor of shape `(*, m, m)` where `*` is zero or more batch dimensions.
n (int): the exponent.
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Raises:
RuntimeError: if :attr:`n`\ `< 0` and the matrix :attr:`A` or any matrix in the
batch of matrices :attr:`A` is not invertible.
Examples::
>>> A = torch.randn(3, 3)
>>> torch.linalg.matrix_power(A, 0)
tensor([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])
>>> torch.linalg.matrix_power(A, 3)
tensor([[ 1.0756, 0.4980, 0.0100],
[-1.6617, 1.4994, -1.9980],
[-0.4509, 0.2731, 0.8001]])
>>> torch.linalg.matrix_power(A.expand(2, -1, -1), -2)
tensor([[[ 0.2640, 0.4571, -0.5511],
[-1.0163, 0.3491, -1.5292],
[-0.4899, 0.0822, 0.2773]],
[[ 0.2640, 0.4571, -0.5511],
[-1.0163, 0.3491, -1.5292],
[-0.4899, 0.0822, 0.2773]]])
matrix_rank = linalg_matrix_rank(...)
linalg.matrix_rank(A, *, atol=None, rtol=None, hermitian=False, out=None) -> Tensor
Computes the numerical rank of a matrix.
The matrix rank is computed as the number of singular values
(or eigenvalues in absolute value when :attr:`hermitian`\ `= True`)
that are greater than :math:`\max(\text{atol}, \sigma_1 * \text{rtol})` threshold,
where :math:`\sigma_1` is the largest singular value (or eigenvalue).
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
If :attr:`hermitian`\ `= True`, :attr:`A` is assumed to be Hermitian if complex or
symmetric if real, but this is not checked internally. Instead, just the lower
triangular part of the matrix is used in the computations.
If :attr:`rtol` is not specified and :attr:`A` is a matrix of dimensions `(m, n)`,
the relative tolerance is set to be :math:`\text{rtol} = \max(m, n) \varepsilon`
and :math:`\varepsilon` is the epsilon value for the dtype of :attr:`A` (see :class:`.finfo`).
If :attr:`rtol` is not specified and :attr:`atol` is specified to be larger than zero then
:attr:`rtol` is set to zero.
If :attr:`atol` or :attr:`rtol` is a :class:`torch.Tensor`, its shape must be broadcastable to that
of the singular values of :attr:`A` as returned by :func:`torch.linalg.svdvals`.
.. note::
This function has NumPy compatible variant `linalg.matrix_rank(A, tol, hermitian=False)`.
However, use of the positional argument :attr:`tol` is deprecated in favor of :attr:`atol` and :attr:`rtol`.
.. note:: The matrix rank is computed using a singular value decomposition
:func:`torch.linalg.svdvals` if :attr:`hermitian`\ `= False` (default) and the eigenvalue
decomposition :func:`torch.linalg.eigvalsh` when :attr:`hermitian`\ `= True`.
When inputs are on a CUDA device, this function synchronizes that device with the CPU.
Args:
A (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
tol (float, Tensor, optional): [NumPy Compat] Alias for :attr:`atol`. Default: `None`.
Keyword args:
atol (float, Tensor, optional): the absolute tolerance value. When `None` it's considered to be zero.
Default: `None`.
rtol (float, Tensor, optional): the relative tolerance value. See above for the value it takes when `None`.
Default: `None`.
hermitian(bool): indicates whether :attr:`A` is Hermitian if complex
or symmetric if real. Default: `False`.
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Examples::
>>> A = torch.eye(10)
>>> torch.linalg.matrix_rank(A)
tensor(10)
>>> B = torch.eye(10)
>>> B[0, 0] = 0
>>> torch.linalg.matrix_rank(B)
tensor(9)
>>> A = torch.randn(4, 3, 2)
>>> torch.linalg.matrix_rank(A)
tensor([2, 2, 2, 2])
>>> A = torch.randn(2, 4, 2, 3)
>>> torch.linalg.matrix_rank(A)
tensor([[2, 2, 2, 2],
[2, 2, 2, 2]])
>>> A = torch.randn(2, 4, 3, 3, dtype=torch.complex64)
>>> torch.linalg.matrix_rank(A)
tensor([[3, 3, 3, 3],
[3, 3, 3, 3]])
>>> torch.linalg.matrix_rank(A, hermitian=True)
tensor([[3, 3, 3, 3],
[3, 3, 3, 3]])
>>> torch.linalg.matrix_rank(A, atol=1.0, rtol=0.0)
tensor([[3, 2, 2, 2],
[1, 2, 1, 2]])
>>> torch.linalg.matrix_rank(A, atol=1.0, rtol=0.0, hermitian=True)
tensor([[2, 2, 2, 1],
[1, 2, 2, 2]])
multi_dot = linalg_multi_dot(...)
linalg.multi_dot(tensors, *, out=None)
Efficiently multiplies two or more matrices by reordering the multiplications so that
the fewest arithmetic operations are performed.
Supports inputs of float, double, cfloat and cdouble dtypes.
This function does not support batched inputs.
Every tensor in :attr:`tensors` must be 2D, except for the first and last which
may be 1D. If the first tensor is a 1D vector of shape `(n,)` it is treated as a row vector
of shape `(1, n)`, similarly if the last tensor is a 1D vector of shape `(n,)` it is treated
as a column vector of shape `(n, 1)`.
If the first and last tensors are matrices, the output will be a matrix.
However, if either is a 1D vector, then the output will be a 1D vector.
Differences with `numpy.linalg.multi_dot`:
- Unlike `numpy.linalg.multi_dot`, the first and last tensors must either be 1D or 2D
whereas NumPy allows them to be nD
.. warning:: This function does not broadcast.
.. note:: This function is implemented by chaining :func:`torch.mm` calls after
computing the optimal matrix multiplication order.
.. note:: The cost of multiplying two matrices with shapes `(a, b)` and `(b, c)` is
`a * b * c`. Given matrices `A`, `B`, `C` with shapes `(10, 100)`,
`(100, 5)`, `(5, 50)` respectively, we can calculate the cost of different
multiplication orders as follows:
.. math::
\begin{align*}
\operatorname{cost}((AB)C) &= 10 \times 100 \times 5 + 10 \times 5 \times 50 = 7500 \\
\operatorname{cost}(A(BC)) &= 10 \times 100 \times 50 + 100 \times 5 \times 50 = 75000
\end{align*}
In this case, multiplying `A` and `B` first followed by `C` is 10 times faster.
Args:
tensors (Sequence[Tensor]): two or more tensors to multiply. The first and last
tensors may be 1D or 2D. Every other tensor must be 2D.
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Examples::
>>> from torch.linalg import multi_dot
>>> multi_dot([torch.tensor([1, 2]), torch.tensor([2, 3])])
tensor(8)
>>> multi_dot([torch.tensor([[1, 2]]), torch.tensor([2, 3])])
tensor([8])
>>> multi_dot([torch.tensor([[1, 2]]), torch.tensor([[2], [3]])])
tensor([[8]])
>>> A = torch.arange(2 * 3).view(2, 3)
>>> B = torch.arange(3 * 2).view(3, 2)
>>> C = torch.arange(2 * 2).view(2, 2)
>>> multi_dot((A, B, C))
tensor([[ 26, 49],
[ 80, 148]])
norm = linalg_norm(...)
linalg.norm(input, ord=None, dim=None, keepdim=False, *, out=None, dtype=None) -> Tensor
Computes a vector or matrix norm.
Supports input of float, double, cfloat and cdouble dtypes.
Whether this function computes a vector or matrix norm is determined as follows:
- If :attr:`dim` is an `int`, the vector norm will be computed.
- If :attr:`dim` is a `2`-`tuple`, the matrix norm will be computed.
- If :attr:`dim`\ `= None` and :attr:`ord`\ `= None`,
:attr:`input` will be flattened to 1D and the `2`-norm of the resulting vector will be computed.
- If :attr:`dim`\ `= None` and :attr:`ord` `!= None`, :attr:`input` must be 1D or 2D.
:attr:`ord` defines the norm that is computed. The following norms are supported:
====================== ========================== ======================================================
:attr:`ord` norm for matrices norm for vectors
====================== ========================== ======================================================
`None` (default) Frobenius norm `2`-norm (see below)
`'fro'` Frobenius norm -- not supported --
`'nuc'` nuclear norm -- not supported --
`inf` `max(sum(abs(x), dim=1))` `max(abs(x))`
`-inf` `min(sum(abs(x), dim=1))` `min(abs(x))`
`0` -- not supported -- `sum(x != 0)`
`1` `max(sum(abs(x), dim=0))` as below
`-1` `min(sum(abs(x), dim=0))` as below
`2` largest `singular value`_ as below
`-2` smallest `singular value`_ as below
other `int` or `float` -- not supported -- `sum(abs(x)^{ord})^{(1 / ord)}`
====================== ========================== ======================================================
where `inf` refers to `float('inf')`, NumPy's `inf` object, or any equivalent object.
.. seealso::
:func:`torch.linalg.vector_norm` computes a vector norm.
:func:`torch.linalg.matrix_norm` computes a matrix norm.
The above functions are often clearer and more flexible than using :func:`torch.linalg.norm`.
For example, `torch.linalg.norm(input, ord=1, dim=(0, 1))` always
computes a matrix norm, but with `torch.linalg.vector_norm(input, ord=1, dim=(0, 1))` it is possible
to compute a vector norm over the two dimensions.
Args:
input (Tensor): tensor of shape `(*, n)` or `(*, m, n)` where `*` is zero or more batch dimensions
ord (int, float, inf, -inf, 'fro', 'nuc', optional): order of norm. Default: `None`
dim (int, Tuple[int], optional): dimensions over which to compute
the vector or matrix norm. See above for the behavior when :attr:`dim`\ `= None`.
Default: `None`
keepdim (bool, optional): If set to `True`, the reduced dimensions are retained
in the result as dimensions with size one. Default: `False`
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
dtype (:class:`torch.dtype`, optional): If specified, the input tensor is cast to
:attr:`dtype` before performing the operation, and the returned tensor's type
will be :attr:`dtype`. Default: `None`
Returns:
A real-valued tensor, even when :attr:`input` is complex.
Examples::
>>> from torch import linalg as LA
>>> a = torch.arange(9, dtype=torch.float) - 4
>>> a
tensor([-4., -3., -2., -1., 0., 1., 2., 3., 4.])
>>> B = a.reshape((3, 3))
>>> B
tensor([[-4., -3., -2.],
[-1., 0., 1.],
[ 2., 3., 4.]])
>>> LA.norm(a)
tensor(7.7460)
>>> LA.norm(B)
tensor(7.7460)
>>> LA.norm(B, 'fro')
tensor(7.7460)
>>> LA.norm(a, float('inf'))
tensor(4.)
>>> LA.norm(B, float('inf'))
tensor(9.)
>>> LA.norm(a, -float('inf'))
tensor(0.)
>>> LA.norm(B, -float('inf'))
tensor(2.)
>>> LA.norm(a, 1)
tensor(20.)
>>> LA.norm(B, 1)
tensor(7.)
>>> LA.norm(a, -1)
tensor(0.)
>>> LA.norm(B, -1)
tensor(6.)
>>> LA.norm(a, 2)
tensor(7.7460)
>>> LA.norm(B, 2)
tensor(7.3485)
>>> LA.norm(a, -2)
tensor(0.)
>>> LA.norm(B.double(), -2)
tensor(1.8570e-16, dtype=torch.float64)
>>> LA.norm(a, 3)
tensor(5.8480)
>>> LA.norm(a, -3)
tensor(0.)
Using the :attr:`dim` argument to compute vector norms::
>>> c = torch.tensor([[1., 2., 3.],
... [-1, 1, 4]])
>>> LA.norm(c, dim=0)
tensor([1.4142, 2.2361, 5.0000])
>>> LA.norm(c, dim=1)
tensor([3.7417, 4.2426])
>>> LA.norm(c, ord=1, dim=1)
tensor([6., 6.])
Using the :attr:`dim` argument to compute matrix norms::
>>> A = torch.arange(8, dtype=torch.float).reshape(2, 2, 2)
>>> LA.norm(A, dim=(1,2))
tensor([ 3.7417, 11.2250])
>>> LA.norm(A[0, :, :]), LA.norm(A[1, :, :])
(tensor(3.7417), tensor(11.2250))
.. _singular value:
https://en.wikipedia.org/wiki/Singular_value_decomposition#Singular_values,_singular_vectors,_and_their_relation_to_the_SVD
pinv = linalg_pinv(...)
linalg.pinv(A, *, atol=None, rtol=None, hermitian=False, out=None) -> Tensor
Computes the pseudoinverse (Moore-Penrose inverse) of a matrix.
The pseudoinverse may be `defined algebraically`_
but it is more computationally convenient to understand it `through the SVD`_
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
If :attr:`hermitian`\ `= True`, :attr:`A` is assumed to be Hermitian if complex or
symmetric if real, but this is not checked internally. Instead, just the lower
triangular part of the matrix is used in the computations.
The singular values (or the norm of the eigenvalues when :attr:`hermitian`\ `= True`)
that are below :math:`\max(\text{atol}, \sigma_1 \cdot \text{rtol})` threshold are
treated as zero and discarded in the computation,
where :math:`\sigma_1` is the largest singular value (or eigenvalue).
If :attr:`rtol` is not specified and :attr:`A` is a matrix of dimensions `(m, n)`,
the relative tolerance is set to be :math:`\text{rtol} = \max(m, n) \varepsilon`
and :math:`\varepsilon` is the epsilon value for the dtype of :attr:`A` (see :class:`.finfo`).
If :attr:`rtol` is not specified and :attr:`atol` is specified to be larger than zero then
:attr:`rtol` is set to zero.
If :attr:`atol` or :attr:`rtol` is a :class:`torch.Tensor`, its shape must be broadcastable to that
of the singular values of :attr:`A` as returned by :func:`torch.linalg.svd`.
.. note:: This function uses :func:`torch.linalg.svd` if :attr:`hermitian`\ `= False` and
:func:`torch.linalg.eigh` if :attr:`hermitian`\ `= True`.
For CUDA inputs, this function synchronizes that device with the CPU.
.. note::
Consider using :func:`torch.linalg.lstsq` if possible for multiplying a matrix on the left by
the pseudoinverse, as::
torch.linalg.lstsq(A, B).solution == A.pinv() @ B
It is always preferred to use :func:`~lstsq` when possible, as it is faster and more
numerically stable than computing the pseudoinverse explicitly.
.. note::
This function has NumPy compatible variant `linalg.pinv(A, rcond, hermitian=False)`.
However, use of the positional argument :attr:`rcond` is deprecated in favor of :attr:`rtol`.
.. warning::
This function uses internally :func:`torch.linalg.svd` (or :func:`torch.linalg.eigh`
when :attr:`hermitian`\ `= True`), so its derivative has the same problems as those of these
functions. See the warnings in :func:`torch.linalg.svd` and :func:`torch.linalg.eigh` for
more details.
.. seealso::
:func:`torch.linalg.inv` computes the inverse of a square matrix.
:func:`torch.linalg.lstsq` computes :attr:`A`\ `.pinv() @ \ `:attr:`B` with a
numerically stable algorithm.
Args:
A (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
rcond (float, Tensor, optional): [NumPy Compat]. Alias for :attr:`rtol`. Default: `None`.
Keyword args:
atol (float, Tensor, optional): the absolute tolerance value. When `None` it's considered to be zero.
Default: `None`.
rtol (float, Tensor, optional): the relative tolerance value. See above for the value it takes when `None`.
Default: `None`.
hermitian(bool, optional): indicates whether :attr:`A` is Hermitian if complex
or symmetric if real. Default: `False`.
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Examples::
>>> A = torch.randn(3, 5)
>>> A
tensor([[ 0.5495, 0.0979, -1.4092, -0.1128, 0.4132],
[-1.1143, -0.3662, 0.3042, 1.6374, -0.9294],
[-0.3269, -0.5745, -0.0382, -0.5922, -0.6759]])
>>> torch.linalg.pinv(A)
tensor([[ 0.0600, -0.1933, -0.2090],
[-0.0903, -0.0817, -0.4752],
[-0.7124, -0.1631, -0.2272],
[ 0.1356, 0.3933, -0.5023],
[-0.0308, -0.1725, -0.5216]])
>>> A = torch.randn(2, 6, 3)
>>> Apinv = torch.linalg.pinv(A)
>>> torch.dist(Apinv @ A, torch.eye(3))
tensor(8.5633e-07)
>>> A = torch.randn(3, 3, dtype=torch.complex64)
>>> A = A + A.T.conj() # creates a Hermitian matrix
>>> Apinv = torch.linalg.pinv(A, hermitian=True)
>>> torch.dist(Apinv @ A, torch.eye(3))
tensor(1.0830e-06)
.. _defined algebraically:
https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse#Existence_and_uniqueness
.. _through the SVD:
https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse#Singular_value_decomposition_(SVD)
qr = linalg_qr(...)
qr(A, mode='reduced', *, out=None) -> (Tensor, Tensor)
Computes the QR decomposition of a matrix.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
the **full QR decomposition** of a matrix
:math:`A \in \mathbb{K}^{m \times n}` is defined as
.. math::
A = QR\mathrlap{\qquad Q \in \mathbb{K}^{m \times m}, R \in \mathbb{K}^{m \times n}}
where :math:`Q` is orthogonal in the real case and unitary in the complex case,
and :math:`R` is upper triangular with real diagonal (even in the complex case).
When `m > n` (tall matrix), as `R` is upper triangular, its last `m - n` rows are zero.
In this case, we can drop the last `m - n` columns of `Q` to form the
**reduced QR decomposition**:
.. math::
A = QR\mathrlap{\qquad Q \in \mathbb{K}^{m \times n}, R \in \mathbb{K}^{n \times n}}
The reduced QR decomposition agrees with the full QR decomposition when `n >= m` (wide matrix).
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
The parameter :attr:`mode` chooses between the full and reduced QR decomposition.
If :attr:`A` has shape `(*, m, n)`, denoting `k = min(m, n)`
- :attr:`mode`\ `= 'reduced'` (default): Returns `(Q, R)` of shapes `(*, m, k)`, `(*, k, n)` respectively.
It is always differentiable.
- :attr:`mode`\ `= 'complete'`: Returns `(Q, R)` of shapes `(*, m, m)`, `(*, m, n)` respectively.
It is differentiable for `m <= n`.
- :attr:`mode`\ `= 'r'`: Computes only the reduced `R`. Returns `(Q, R)` with `Q` empty and `R` of shape `(*, k, n)`.
It is never differentiable.
Differences with `numpy.linalg.qr`:
- :attr:`mode`\ `= 'raw'` is not implemented.
- Unlike `numpy.linalg.qr`, this function always returns a tuple of two tensors.
When :attr:`mode`\ `= 'r'`, the `Q` tensor is an empty tensor.
.. warning:: The elements in the diagonal of `R` are not necessarily positive.
As such, the returned QR decomposition is only unique up to the sign of the diagonal of `R`.
Therefore, different platforms, like NumPy, or inputs on different devices,
may produce different valid decompositions.
.. warning:: The QR decomposition is only well-defined if the first `k = min(m, n)` columns
of every matrix in :attr:`A` are linearly independent.
If this condition is not met, no error will be thrown, but the QR produced
may be incorrect and its autodiff may fail or produce incorrect results.
Args:
A (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
mode (str, optional): one of `'reduced'`, `'complete'`, `'r'`.
Controls the shape of the returned tensors. Default: `'reduced'`.
Keyword args:
out (tuple, optional): output tuple of two tensors. Ignored if `None`. Default: `None`.
Returns:
A named tuple `(Q, R)`.
Examples::
>>> A = torch.tensor([[12., -51, 4], [6, 167, -68], [-4, 24, -41]])
>>> Q, R = torch.linalg.qr(A)
>>> Q
tensor([[-0.8571, 0.3943, 0.3314],
[-0.4286, -0.9029, -0.0343],
[ 0.2857, -0.1714, 0.9429]])
>>> R
tensor([[ -14.0000, -21.0000, 14.0000],
[ 0.0000, -175.0000, 70.0000],
[ 0.0000, 0.0000, -35.0000]])
>>> (Q @ R).round()
tensor([[ 12., -51., 4.],
[ 6., 167., -68.],
[ -4., 24., -41.]])
>>> (Q.T @ Q).round()
tensor([[ 1., 0., 0.],
[ 0., 1., -0.],
[ 0., -0., 1.]])
>>> Q2, R2 = torch.linalg.qr(A, mode='r')
>>> Q2
tensor([])
>>> torch.equal(R, R2)
True
>>> A = torch.randn(3, 4, 5)
>>> Q, R = torch.linalg.qr(A, mode='complete')
>>> torch.dist(Q @ R, A)
tensor(1.6099e-06)
>>> torch.dist(Q.mT @ Q, torch.eye(4))
tensor(6.2158e-07)
slogdet = linalg_slogdet(...)
linalg.slogdet(A, *, out=None) -> (Tensor, Tensor)
Computes the sign and natural logarithm of the absolute value of the determinant of a square matrix.
For complex :attr:`A`, it returns the sign and the natural logarithm of the modulus of the
determinant, that is, a logarithmic polar decomposition of the determinant.
The determinant can be recovered as `sign * exp(logabsdet)`.
When a matrix has a determinant of zero, it returns `(0, -inf)`.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
.. seealso::
:func:`torch.linalg.det` computes the determinant of square matrices.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions.
Keyword args:
out (tuple, optional): output tuple of two tensors. Ignored if `None`. Default: `None`.
Returns:
A named tuple `(sign, logabsdet)`.
`sign` will have the same dtype as :attr:`A`.
`logabsdet` will always be real-valued, even when :attr:`A` is complex.
Examples::
>>> A = torch.randn(3, 3)
>>> A
tensor([[ 0.0032, -0.2239, -1.1219],
[-0.6690, 0.1161, 0.4053],
[-1.6218, -0.9273, -0.0082]])
>>> torch.linalg.det(A)
tensor(-0.7576)
>>> torch.logdet(A)
tensor(nan)
>>> torch.linalg.slogdet(A)
torch.return_types.linalg_slogdet(sign=tensor(-1.), logabsdet=tensor(-0.2776))
solve = linalg_solve(...)
linalg.solve(A, B, *, left=True, out=None) -> Tensor
Computes the solution of a square system of linear equations with a unique solution.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
this function computes the solution :math:`X \in \mathbb{K}^{n \times k}` of the **linear system** associated to
:math:`A \in \mathbb{K}^{n \times n}, B \in \mathbb{K}^{n \times k}`, which is defined as
.. math:: AX = B
If :attr:`left`\ `= False`, this function returns the matrix :math:`X \in \mathbb{K}^{n \times k}` that solves the system
.. math::
XA = B\mathrlap{\qquad A \in \mathbb{K}^{k \times k}, B \in \mathbb{K}^{n \times k}.}
This system of linear equations has one solution if and only if :math:`A` is `invertible`_.
This function assumes that :math:`A` is invertible.
Supports inputs of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if the inputs are batches of matrices then
the output has the same batch dimensions.
Letting `*` be zero or more batch dimensions,
- If :attr:`A` has shape `(*, n, n)` and :attr:`B` has shape `(*, n)` (a batch of vectors) or shape
`(*, n, k)` (a batch of matrices or "multiple right-hand sides"), this function returns `X` of shape
`(*, n)` or `(*, n, k)` respectively.
- Otherwise, if :attr:`A` has shape `(*, n, n)` and :attr:`B` has shape `(n,)` or `(n, k)`, :attr:`B`
is broadcasted to have shape `(*, n)` or `(*, n, k)` respectively.
This function then returns the solution of the resulting batch of systems of linear equations.
.. note::
This function computes `X = \ `:attr:`A`\ `.inverse() @ \ `:attr:`B` in a faster and
more numerically stable way than performing the computations separately.
.. note::
It is possible to compute the solution of the system :math:`XA = B` by passing the inputs
:attr:`A` and :attr:`B` transposed and transposing the output returned by this function.
.. note::
:attr:`A` is allowed to be a non-batched `torch.sparse_csr_tensor`, but only with `left=True`.
.. note:: When inputs are on a CUDA device, this function synchronizes that device with the CPU. For a version of this function that does not synchronize, see :func:`torch.linalg.solve_ex`.
.. seealso::
:func:`torch.linalg.solve_triangular` computes the solution of a triangular system of linear
equations with a unique solution.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions.
B (Tensor): right-hand side tensor of shape `(*, n)` or `(*, n, k)` or `(n,)` or `(n, k)`
according to the rules described above
Keyword args:
left (bool, optional): whether to solve the system :math:`AX=B` or :math:`XA = B`. Default: `True`.
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Raises:
RuntimeError: if the :attr:`A` matrix is not invertible or any matrix in a batched :attr:`A`
is not invertible.
Examples::
>>> A = torch.randn(3, 3)
>>> b = torch.randn(3)
>>> x = torch.linalg.solve(A, b)
>>> torch.allclose(A @ x, b)
True
>>> A = torch.randn(2, 3, 3)
>>> B = torch.randn(2, 3, 4)
>>> X = torch.linalg.solve(A, B)
>>> X.shape
torch.Size([2, 3, 4])
>>> torch.allclose(A @ X, B)
True
>>> A = torch.randn(2, 3, 3)
>>> b = torch.randn(3, 1)
>>> x = torch.linalg.solve(A, b) # b is broadcasted to size (2, 3, 1)
>>> x.shape
torch.Size([2, 3, 1])
>>> torch.allclose(A @ x, b)
True
>>> b = torch.randn(3)
>>> x = torch.linalg.solve(A, b) # b is broadcasted to size (2, 3)
>>> x.shape
torch.Size([2, 3])
>>> Ax = A @ x.unsqueeze(-1)
>>> torch.allclose(Ax, b.unsqueeze(-1).expand_as(Ax))
True
.. _invertible:
https://en.wikipedia.org/wiki/Invertible_matrix#The_invertible_matrix_theorem
solve_ex = linalg_solve_ex(...)
linalg.solve_ex(A, B, *, left=True, check_errors=False, out=None) -> (Tensor, Tensor)
A version of :func:`~solve` that does not perform error checks unless :attr:`check_errors`\ `= True`.
It also returns the :attr:`info` tensor returned by `LAPACK's getrf`_.
.. note:: When the inputs are on a CUDA device, this function synchronizes only when :attr:`check_errors`\ `= True`.
.. warning:: This function is "experimental" and it may change in a future PyTorch release.
Args:
A (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions.
Keyword args:
left (bool, optional): whether to solve the system :math:`AX=B` or :math:`XA = B`. Default: `True`.
check_errors (bool, optional): controls whether to check the content of ``infos`` and raise
an error if it is non-zero. Default: `False`.
out (tuple, optional): tuple of two tensors to write the output to. Ignored if `None`. Default: `None`.
Returns:
A named tuple `(result, info)`.
Examples::
>>> A = torch.randn(3, 3)
>>> Ainv, info = torch.linalg.solve_ex(A)
>>> torch.dist(torch.linalg.inv(A), Ainv)
tensor(0.)
>>> info
tensor(0, dtype=torch.int32)
.. _LAPACK's getrf:
https://www.netlib.org/lapack/explore-html-3.6.1/dd/d9a/group__double_g_ecomputational_ga0019443faea08275ca60a734d0593e60.html
solve_triangular = linalg_solve_triangular(...)
linalg.solve_triangular(A, B, *, upper, left=True, unitriangular=False, out=None) -> Tensor
Computes the solution of a triangular system of linear equations with a unique solution.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
this function computes the solution :math:`X \in \mathbb{K}^{n \times k}` of the **linear system**
associated to the triangular matrix :math:`A \in \mathbb{K}^{n \times n}` without zeros on the diagonal
(that is, it is `invertible`_) and the rectangular matrix , :math:`B \in \mathbb{K}^{n \times k}`,
which is defined as
.. math:: AX = B
The argument :attr:`upper` signals whether :math:`A` is upper or lower triangular.
If :attr:`left`\ `= False`, this function returns the matrix :math:`X \in \mathbb{K}^{n \times k}` that
solves the system
.. math::
XA = B\mathrlap{\qquad A \in \mathbb{K}^{k \times k}, B \in \mathbb{K}^{n \times k}.}
If :attr:`upper`\ `= True` (resp. `False`) just the upper (resp. lower) triangular half of :attr:`A`
will be accessed. The elements below the main diagonal will be considered to be zero and will not be accessed.
If :attr:`unitriangular`\ `= True`, the diagonal of :attr:`A` is assumed to be ones and will not be accessed.
The result may contain `NaN` s if the diagonal of :attr:`A` contains zeros or elements that
are very close to zero and :attr:`unitriangular`\ `= False` (default) or if the input matrix
has very small eigenvalues.
Supports inputs of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if the inputs are batches of matrices then
the output has the same batch dimensions.
.. seealso::
:func:`torch.linalg.solve` computes the solution of a general square system of linear
equations with a unique solution.
Args:
A (Tensor): tensor of shape `(*, n, n)` (or `(*, k, k)` if :attr:`left`\ `= False`)
where `*` is zero or more batch dimensions.
B (Tensor): right-hand side tensor of shape `(*, n, k)`.
Keyword args:
upper (bool): whether :attr:`A` is an upper or lower triangular matrix.
left (bool, optional): whether to solve the system :math:`AX=B` or :math:`XA = B`. Default: `True`.
unitriangular (bool, optional): if `True`, the diagonal elements of :attr:`A` are assumed to be
all equal to `1`. Default: `False`.
out (Tensor, optional): output tensor. `B` may be passed as `out` and the result is computed in-place on `B`.
Ignored if `None`. Default: `None`.
Examples::
>>> A = torch.randn(3, 3).triu_()
>>> B = torch.randn(3, 4)
>>> X = torch.linalg.solve_triangular(A, B, upper=True)
>>> torch.allclose(A @ X, B)
True
>>> A = torch.randn(2, 3, 3).tril_()
>>> B = torch.randn(2, 3, 4)
>>> X = torch.linalg.solve_triangular(A, B, upper=False)
>>> torch.allclose(A @ X, B)
True
>>> A = torch.randn(2, 4, 4).tril_()
>>> B = torch.randn(2, 3, 4)
>>> X = torch.linalg.solve_triangular(A, B, upper=False, left=False)
>>> torch.allclose(X @ A, B)
True
.. _invertible:
https://en.wikipedia.org/wiki/Invertible_matrix#The_invertible_matrix_theorem
svd = linalg_svd(...)
linalg.svd(A, full_matrices=True, *, driver=None, out=None) -> (Tensor, Tensor, Tensor)
Computes the singular value decomposition (SVD) of a matrix.
Letting :math:`\mathbb{K}` be :math:`\mathbb{R}` or :math:`\mathbb{C}`,
the **full SVD** of a matrix
:math:`A \in \mathbb{K}^{m \times n}`, if `k = min(m,n)`, is defined as
.. math::
A = U \operatorname{diag}(S) V^{\text{H}}
\mathrlap{\qquad U \in \mathbb{K}^{m \times m}, S \in \mathbb{R}^k, V \in \mathbb{K}^{n \times n}}
where :math:`\operatorname{diag}(S) \in \mathbb{K}^{m \times n}`,
:math:`V^{\text{H}}` is the conjugate transpose when :math:`V` is complex, and the transpose when :math:`V` is real-valued.
The matrices :math:`U`, :math:`V` (and thus :math:`V^{\text{H}}`) are orthogonal in the real case, and unitary in the complex case.
When `m > n` (resp. `m < n`) we can drop the last `m - n` (resp. `n - m`) columns of `U` (resp. `V`) to form the **reduced SVD**:
.. math::
A = U \operatorname{diag}(S) V^{\text{H}}
\mathrlap{\qquad U \in \mathbb{K}^{m \times k}, S \in \mathbb{R}^k, V \in \mathbb{K}^{n \times k}}
where :math:`\operatorname{diag}(S) \in \mathbb{K}^{k \times k}`.
In this case, :math:`U` and :math:`V` also have orthonormal columns.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
The returned decomposition is a named tuple `(U, S, Vh)`
which corresponds to :math:`U`, :math:`S`, :math:`V^{\text{H}}` above.
The singular values are returned in descending order.
The parameter :attr:`full_matrices` chooses between the full (default) and reduced SVD.
The :attr:`driver` kwarg may be used in CUDA with a cuSOLVER backend to choose the algorithm used to compute the SVD.
The choice of a driver is a trade-off between accuracy and speed.
- If :attr:`A` is well-conditioned (its `condition number`_ is not too large), or you do not mind some precision loss.
- For a general matrix: `'gesvdj'` (Jacobi method)
- If :attr:`A` is tall or wide (`m >> n` or `m << n`): `'gesvda'` (Approximate method)
- If :attr:`A` is not well-conditioned or precision is relevant: `'gesvd'` (QR based)
By default (:attr:`driver`\ `= None`), we call `'gesvdj'` and, if it fails, we fallback to `'gesvd'`.
Differences with `numpy.linalg.svd`:
- Unlike `numpy.linalg.svd`, this function always returns a tuple of three tensors
and it doesn't support `compute_uv` argument.
Please use :func:`torch.linalg.svdvals`, which computes only the singular values,
instead of `compute_uv=False`.
.. note:: When :attr:`full_matrices`\ `= True`, the gradients with respect to `U[..., :, min(m, n):]`
and `Vh[..., min(m, n):, :]` will be ignored, as those vectors can be arbitrary bases
of the corresponding subspaces.
.. warning:: The returned tensors `U` and `V` are not unique, nor are they continuous with
respect to :attr:`A`.
Due to this lack of uniqueness, different hardware and software may compute
different singular vectors.
This non-uniqueness is caused by the fact that multiplying any pair of singular
vectors :math:`u_k, v_k` by `-1` in the real case or by
:math:`e^{i \phi}, \phi \in \mathbb{R}` in the complex case produces another two
valid singular vectors of the matrix.
For this reason, the loss function shall not depend on this :math:`e^{i \phi}` quantity,
as it is not well-defined.
This is checked for complex inputs when computing the gradients of this function. As such,
when inputs are complex and are on a CUDA device, the computation of the gradients
of this function synchronizes that device with the CPU.
.. warning:: Gradients computed using `U` or `Vh` will only be finite when
:attr:`A` does not have repeated singular values. If :attr:`A` is rectangular,
additionally, zero must also not be one of its singular values.
Furthermore, if the distance between any two singular values is close to zero,
the gradient will be numerically unstable, as it depends on the singular values
:math:`\sigma_i` through the computation of
:math:`\frac{1}{\min_{i \neq j} \sigma_i^2 - \sigma_j^2}`.
In the rectangular case, the gradient will also be numerically unstable when
:attr:`A` has small singular values, as it also depends on the computation of
:math:`\frac{1}{\sigma_i}`.
.. seealso::
:func:`torch.linalg.svdvals` computes only the singular values.
Unlike :func:`torch.linalg.svd`, the gradients of :func:`~svdvals` are always
numerically stable.
:func:`torch.linalg.eig` for a function that computes another type of spectral
decomposition of a matrix. The eigendecomposition works just on square matrices.
:func:`torch.linalg.eigh` for a (faster) function that computes the eigenvalue decomposition
for Hermitian and symmetric matrices.
:func:`torch.linalg.qr` for another (much faster) decomposition that works on general
matrices.
Args:
A (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
full_matrices (bool, optional): controls whether to compute the full or reduced
SVD, and consequently,
the shape of the returned tensors
`U` and `Vh`. Default: `True`.
Keyword args:
driver (str, optional): name of the cuSOLVER method to be used. This keyword argument only works on CUDA inputs.
Available options are: `None`, `gesvd`, `gesvdj`, and `gesvda`.
Default: `None`.
out (tuple, optional): output tuple of three tensors. Ignored if `None`.
Returns:
A named tuple `(U, S, Vh)` which corresponds to :math:`U`, :math:`S`, :math:`V^{\text{H}}` above.
`S` will always be real-valued, even when :attr:`A` is complex.
It will also be ordered in descending order.
`U` and `Vh` will have the same dtype as :attr:`A`. The left / right singular vectors will be given by
the columns of `U` and the rows of `Vh` respectively.
Examples::
>>> A = torch.randn(5, 3)
>>> U, S, Vh = torch.linalg.svd(A, full_matrices=False)
>>> U.shape, S.shape, Vh.shape
(torch.Size([5, 3]), torch.Size([3]), torch.Size([3, 3]))
>>> torch.dist(A, U @ torch.diag(S) @ Vh)
tensor(1.0486e-06)
>>> U, S, Vh = torch.linalg.svd(A)
>>> U.shape, S.shape, Vh.shape
(torch.Size([5, 5]), torch.Size([3]), torch.Size([3, 3]))
>>> torch.dist(A, U[:, :3] @ torch.diag(S) @ Vh)
tensor(1.0486e-06)
>>> A = torch.randn(7, 5, 3)
>>> U, S, Vh = torch.linalg.svd(A, full_matrices=False)
>>> torch.dist(A, U @ torch.diag_embed(S) @ Vh)
tensor(3.0957e-06)
.. _condition number:
https://pytorch.org/docs/main/linalg.html#torch.linalg.cond
.. _the resulting vectors will span the same subspace:
https://en.wikipedia.org/wiki/Singular_value_decomposition#Singular_values,_singular_vectors,_and_their_relation_to_the_SVD
svdvals = linalg_svdvals(...)
linalg.svdvals(A, *, driver=None, out=None) -> Tensor
Computes the singular values of a matrix.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :attr:`A` is a batch of matrices then
the output has the same batch dimensions.
The singular values are returned in descending order.
.. note:: This function is equivalent to NumPy's `linalg.svd(A, compute_uv=False)`.
.. note:: When inputs are on a CUDA device, this function synchronizes that device with the CPU.
.. seealso::
:func:`torch.linalg.svd` computes the full singular value decomposition.
Args:
A (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
Keyword args:
driver (str, optional): name of the cuSOLVER method to be used. This keyword argument only works on CUDA inputs.
Available options are: `None`, `gesvd`, `gesvdj`, and `gesvda`.
Check :func:`torch.linalg.svd` for details.
Default: `None`.
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Returns:
A real-valued tensor, even when :attr:`A` is complex.
Examples::
>>> A = torch.randn(5, 3)
>>> S = torch.linalg.svdvals(A)
>>> S
tensor([2.5139, 2.1087, 1.1066])
>>> torch.dist(S, torch.linalg.svd(A, full_matrices=False).S)
tensor(2.4576e-07)
tensorinv = linalg_tensorinv(...)
linalg.tensorinv(A, ind=2, *, out=None) -> Tensor
Computes the multiplicative inverse of :func:`torch.tensordot`.
If `m` is the product of the first :attr:`ind` dimensions of :attr:`A` and `n` is the product of
the rest of the dimensions, this function expects `m` and `n` to be equal.
If this is the case, it computes a tensor `X` such that
`tensordot(\ `:attr:`A`\ `, X, \ `:attr:`ind`\ `)` is the identity matrix in dimension `m`.
`X` will have the shape of :attr:`A` but with the first :attr:`ind` dimensions pushed back to the end
.. code:: text
X.shape == A.shape[ind:] + A.shape[:ind]
Supports input of float, double, cfloat and cdouble dtypes.
.. note:: When :attr:`A` is a `2`-dimensional tensor and :attr:`ind`\ `= 1`,
this function computes the (multiplicative) inverse of :attr:`A`
(see :func:`torch.linalg.inv`).
.. note::
Consider using :func:`torch.linalg.tensorsolve` if possible for multiplying a tensor on the left
by the tensor inverse, as::
linalg.tensorsolve(A, B) == torch.tensordot(linalg.tensorinv(A), B) # When B is a tensor with shape A.shape[:B.ndim]
It is always preferred to use :func:`~tensorsolve` when possible, as it is faster and more
numerically stable than computing the pseudoinverse explicitly.
.. seealso::
:func:`torch.linalg.tensorsolve` computes
`torch.tensordot(tensorinv(\ `:attr:`A`\ `), \ `:attr:`B`\ `)`.
Args:
A (Tensor): tensor to invert. Its shape must satisfy
`prod(\ `:attr:`A`\ `.shape[:\ `:attr:`ind`\ `]) ==
prod(\ `:attr:`A`\ `.shape[\ `:attr:`ind`\ `:])`.
ind (int): index at which to compute the inverse of :func:`torch.tensordot`. Default: `2`.
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Raises:
RuntimeError: if the reshaped :attr:`A` is not invertible or the product of the first
:attr:`ind` dimensions is not equal to the product of the rest.
Examples::
>>> A = torch.eye(4 * 6).reshape((4, 6, 8, 3))
>>> Ainv = torch.linalg.tensorinv(A, ind=2)
>>> Ainv.shape
torch.Size([8, 3, 4, 6])
>>> B = torch.randn(4, 6)
>>> torch.allclose(torch.tensordot(Ainv, B), torch.linalg.tensorsolve(A, B))
True
>>> A = torch.randn(4, 4)
>>> Atensorinv = torch.linalg.tensorinv(A, ind=1)
>>> Ainv = torch.linalg.inv(A)
>>> torch.allclose(Atensorinv, Ainv)
True
tensorsolve = linalg_tensorsolve(...)
linalg.tensorsolve(A, B, dims=None, *, out=None) -> Tensor
Computes the solution `X` to the system `torch.tensordot(A, X) = B`.
If `m` is the product of the first :attr:`B`\ `.ndim` dimensions of :attr:`A` and
`n` is the product of the rest of the dimensions, this function expects `m` and `n` to be equal.
The returned tensor `x` satisfies
`tensordot(\ `:attr:`A`\ `, x, dims=x.ndim) == \ `:attr:`B`.
`x` has shape :attr:`A`\ `[B.ndim:]`.
If :attr:`dims` is specified, :attr:`A` will be reshaped as
.. code:: text
A = movedim(A, dims, range(len(dims) - A.ndim + 1, 0))
Supports inputs of float, double, cfloat and cdouble dtypes.
.. seealso::
:func:`torch.linalg.tensorinv` computes the multiplicative inverse of
:func:`torch.tensordot`.
Args:
A (Tensor): tensor to solve for. Its shape must satisfy
`prod(\ `:attr:`A`\ `.shape[:\ `:attr:`B`\ `.ndim]) ==
prod(\ `:attr:`A`\ `.shape[\ `:attr:`B`\ `.ndim:])`.
B (Tensor): tensor of shape :attr:`A`\ `.shape[:\ `:attr:`B`\ `.ndim]`.
dims (Tuple[int], optional): dimensions of :attr:`A` to be moved.
If `None`, no dimensions are moved. Default: `None`.
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Raises:
RuntimeError: if the reshaped :attr:`A`\ `.view(m, m)` with `m` as above is not
invertible or the product of the first :attr:`ind` dimensions is not equal
to the product of the rest of the dimensions.
Examples::
>>> A = torch.eye(2 * 3 * 4).reshape((2 * 3, 4, 2, 3, 4))
>>> B = torch.randn(2 * 3, 4)
>>> X = torch.linalg.tensorsolve(A, B)
>>> X.shape
torch.Size([2, 3, 4])
>>> torch.allclose(torch.tensordot(A, X, dims=X.ndim), B)
True
>>> A = torch.randn(6, 4, 4, 3, 2)
>>> B = torch.randn(4, 3, 2)
>>> X = torch.linalg.tensorsolve(A, B, dims=(0, 2))
>>> X.shape
torch.Size([6, 4])
>>> A = A.permute(1, 3, 4, 0, 2)
>>> A.shape[B.ndim:]
torch.Size([6, 4])
>>> torch.allclose(torch.tensordot(A, X, dims=X.ndim), B, atol=1e-6)
True
vander = linalg_vander(...)
vander(x, N=None) -> Tensor
Generates a Vandermonde matrix.
Returns the Vandermonde matrix :math:`V`
.. math::
V = \begin{pmatrix}
1 & x_1 & x_1^2 & \dots & x_1^{N-1}\\
1 & x_2 & x_2^2 & \dots & x_2^{N-1}\\
1 & x_3 & x_3^2 & \dots & x_3^{N-1}\\
\vdots & \vdots & \vdots & \ddots &\vdots \\
1 & x_n & x_n^2 & \dots & x_n^{N-1}
\end{pmatrix}.
for `N > 1`.
If :attr:`N`\ `= None`, then `N = x.size(-1)` so that the output is a square matrix.
Supports inputs of float, double, cfloat, cdouble, and integral dtypes.
Also supports batches of vectors, and if :attr:`x` is a batch of vectors then
the output has the same batch dimensions.
Differences with `numpy.vander`:
- Unlike `numpy.vander`, this function returns the powers of :attr:`x` in ascending order.
To get them in the reverse order call ``linalg.vander(x, N).flip(-1)``.
Args:
x (Tensor): tensor of shape `(*, n)` where `*` is zero or more batch dimensions
consisting of vectors.
Keyword args:
N (int, optional): Number of columns in the output. Default: `x.size(-1)`
Example::
>>> x = torch.tensor([1, 2, 3, 5])
>>> linalg.vander(x)
tensor([[ 1, 1, 1, 1],
[ 1, 2, 4, 8],
[ 1, 3, 9, 27],
[ 1, 5, 25, 125]])
>>> linalg.vander(x, N=3)
tensor([[ 1, 1, 1],
[ 1, 2, 4],
[ 1, 3, 9],
[ 1, 5, 25]])
vecdot = linalg_vecdot(...)
linalg.vecdot(x, y, *, dim=-1, out=None) -> Tensor
Computes the dot product of two batches of vectors along a dimension.
In symbols, this function computes
.. math::
\sum_{i=1}^n \overline{x_i}y_i.
over the dimension :attr:`dim` where :math:`\overline{x_i}` denotes the conjugate for complex
vectors, and it is the identity for real vectors.
Supports input of half, bfloat16, float, double, cfloat, cdouble and integral dtypes.
It also supports broadcasting.
Args:
x (Tensor): first batch of vectors of shape `(*, n)`.
y (Tensor): second batch of vectors of shape `(*, n)`.
Keyword args:
dim (int): Dimension along which to compute the dot product. Default: `-1`.
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Examples::
>>> v1 = torch.randn(3, 2)
>>> v2 = torch.randn(3, 2)
>>> linalg.vecdot(v1, v2)
tensor([ 0.3223, 0.2815, -0.1944])
>>> torch.vdot(v1[0], v2[0])
tensor(0.3223)
vector_norm = linalg_vector_norm(...)
linalg.vector_norm(x, ord=2, dim=None, keepdim=False, *, dtype=None, out=None) -> Tensor
Computes a vector norm.
If :attr:`x` is complex valued, it computes the norm of :attr:`x`\ `.abs()`
Supports input of float, double, cfloat and cdouble dtypes.
This function does not necessarily treat multidimensional :attr:`x` as a batch of
vectors, instead:
- If :attr:`dim`\ `= None`, :attr:`x` will be flattened before the norm is computed.
- If :attr:`dim` is an `int` or a `tuple`, the norm will be computed over these dimensions
and the other dimensions will be treated as batch dimensions.
This behavior is for consistency with :func:`torch.linalg.norm`.
:attr:`ord` defines the vector norm that is computed. The following norms are supported:
====================== ===============================
:attr:`ord` vector norm
====================== ===============================
`2` (default) `2`-norm (see below)
`inf` `max(abs(x))`
`-inf` `min(abs(x))`
`0` `sum(x != 0)`
other `int` or `float` `sum(abs(x)^{ord})^{(1 / ord)}`
====================== ===============================
where `inf` refers to `float('inf')`, NumPy's `inf` object, or any equivalent object.
:attr:`dtype` may be used to perform the computation in a more precise dtype.
It is semantically equivalent to calling ``linalg.vector_norm(x.to(dtype))``
but it is faster in some cases.
.. seealso::
:func:`torch.linalg.matrix_norm` computes a matrix norm.
Args:
x (Tensor): tensor, flattened by default, but this behavior can be
controlled using :attr:`dim`. (Note: the keyword argument
`input` can also be used as an alias for `x`.)
ord (int, float, inf, -inf, 'fro', 'nuc', optional): order of norm. Default: `2`
dim (int, Tuple[int], optional): dimensions over which to compute
the norm. See above for the behavior when :attr:`dim`\ `= None`.
Default: `None`
keepdim (bool, optional): If set to `True`, the reduced dimensions are retained
in the result as dimensions with size one. Default: `False`
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
dtype (:class:`torch.dtype`, optional): type used to perform the accumulation and the return.
If specified, :attr:`x` is cast to :attr:`dtype` before performing the operation,
and the returned tensor's type will be :attr:`dtype` if real and of its real counterpart if complex.
:attr:`dtype` may be complex if :attr:`x` is complex, otherwise it must be real.
:attr:`x` should be convertible without narrowing to :attr:`dtype`. Default: None
Returns:
A real-valued tensor, even when :attr:`x` is complex.
Examples::
>>> from torch import linalg as LA
>>> a = torch.arange(9, dtype=torch.float) - 4
>>> a
tensor([-4., -3., -2., -1., 0., 1., 2., 3., 4.])
>>> B = a.reshape((3, 3))
>>> B
tensor([[-4., -3., -2.],
[-1., 0., 1.],
[ 2., 3., 4.]])
>>> LA.vector_norm(a, ord=3.5)
tensor(5.4345)
>>> LA.vector_norm(B, ord=3.5)
tensor(5.4345)
DATA
common_notes = {'experimental_warning': 'This function is "experimenta...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\linalg\__init__.py
torch.linspace
Python Library Documentation: built-in function linspace in module torch
linspace(...)
linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
.. math::
(\text{start},
\text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
\ldots,
\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
\text{end})
From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
Args:
start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
steps (int): size of the constructed tensor
Keyword arguments:
out (Tensor, optional): the output tensor.
dtype (torch.dtype, optional): the data type to perform the computation in.
Default: if None, uses the global default dtype (see torch.get_default_dtype())
when both :attr:`start` and :attr:`end` are real,
and corresponding complex dtype when either is complex.
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.linspace(3, 10, steps=5)
tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
>>> torch.linspace(-10, 10, steps=5)
tensor([-10., -5., 0., 5., 10.])
>>> torch.linspace(start=-10, end=10, steps=5)
tensor([-10., -5., 0., 5., 10.])
>>> torch.linspace(start=-10, end=10, steps=1)
tensor([-10.])
torch.load
Python Library Documentation: function load in module torch.serialization
load(f: Union[str, os.PathLike[str], IO[bytes]], map_location: collections.abc.Callable[[torch.types.Storage, str], torch.types.Storage] | torch.device | str | dict[str, str] | None = None, pickle_module: Any = None, *, weights_only: bool | None = None, mmap: bool | None = None, **pickle_load_args: Any) -> Any
load(f, map_location=None, pickle_module=pickle, *, weights_only=True, mmap=None, **pickle_load_args)
Loads an object saved with :func:`torch.save` from a file.
.. warning::
:func:`torch.load()` uses an unpickler under the hood. **Never load data from an untrusted source.**
See :ref:`weights-only-security` for more details.
:func:`torch.load` uses Python's unpickling facilities but treats storages,
which underlie tensors, specially. They are first deserialized on the
CPU and are then moved to the device they were saved from. If this fails
(e.g. because the run time system doesn't have certain devices), an exception
is raised. However, storages can be dynamically remapped to an alternative
set of devices using the :attr:`map_location` argument.
If :attr:`map_location` is a callable, it will be called once for each serialized
storage with two arguments: storage and location. The storage argument
will be the initial deserialization of the storage, residing on the CPU.
Each serialized storage has a location tag associated with it which
identifies the device it was saved from, and this tag is the second
argument passed to :attr:`map_location`. The builtin location tags are ``'cpu'``
for CPU tensors and ``'cuda:device_id'`` (e.g. ``'cuda:2'``) for CUDA tensors.
:attr:`map_location` should return either ``None`` or a storage. If
:attr:`map_location` returns a storage, it will be used as the final deserialized
object, already moved to the right device. Otherwise, :func:`torch.load` will
fall back to the default behavior, as if :attr:`map_location` wasn't specified.
If :attr:`map_location` is a :class:`torch.device` object or a string containing
a device tag, it indicates the location where all tensors should be loaded.
Otherwise, if :attr:`map_location` is a dict, it will be used to remap location tags
appearing in the file (keys), to ones that specify where to put the
storages (values).
User extensions can register their own location tags and tagging and
deserialization methods using :func:`torch.serialization.register_package`.
See :ref:`layout-control` for more advanced tools to manipulate a checkpoint.
Args:
f: a file-like object (has to implement :meth:`read`, :meth:`readline`, :meth:`tell`, and :meth:`seek`),
or a string or os.PathLike object containing a file name
map_location: a function, :class:`torch.device`, string or a dict specifying how to remap storage
locations
pickle_module: module used for unpickling metadata and objects (has to
match the :attr:`pickle_module` used to serialize file)
weights_only: Indicates whether unpickler should be restricted to
loading only tensors, primitive types, dictionaries
and any types added via :func:`torch.serialization.add_safe_globals`.
See :ref:`weights-only` for more details.
mmap: Indicates whether the file should be mapped rather than loading all the storages into memory.
Typically, tensor storages in the file will first be moved from disk to CPU memory, after which they
are moved to the location that they were tagged with when saving, or specified by ``map_location``. This
second step is a no-op if the final location is CPU. When the ``mmap`` flag is set, instead of copying the
tensor storages from disk to CPU memory in the first step, ``f`` is mapped, which means tensor storages
will be lazily loaded when their data is accessed.
pickle_load_args: optional keyword arguments passed over to
:func:`pickle_module.load` and :func:`pickle_module.Unpickler`,
only works if :attr:`weights_only=False`, e.g., :attr:`errors=...`.
.. note::
When you call :func:`torch.load()` on a file which contains GPU tensors, those tensors
will be loaded to GPU by default. You can call ``torch.load(.., map_location='cpu')``
and then :meth:`load_state_dict` to avoid GPU RAM surge when loading a model checkpoint.
.. note::
By default, we decode byte strings as ``utf-8``. This is to avoid a common error
case ``UnicodeDecodeError: 'ascii' codec can't decode byte 0x...``
when loading files saved by Python 2 in Python 3. If this default
is incorrect, you may use an extra :attr:`encoding` keyword argument to specify how
these objects should be loaded, e.g., :attr:`encoding='latin1'` decodes them
to strings using ``latin1`` encoding, and :attr:`encoding='bytes'` keeps them
as byte arrays which can be decoded later with ``byte_array.decode(...)``.
Example:
>>> # xdoctest: +SKIP("undefined filepaths")
>>> torch.load("tensors.pt", weights_only=True)
# Load all tensors onto the CPU
>>> torch.load(
... "tensors.pt",
... map_location=torch.device("cpu"),
... weights_only=True,
... )
# Load all tensors onto the CPU, using a function
>>> torch.load(
... "tensors.pt",
... map_location=lambda storage, loc: storage,
... weights_only=True,
... )
# Load all tensors onto GPU 1
>>> torch.load(
... "tensors.pt",
... map_location=lambda storage, loc: storage.cuda(1), # type: ignore[attr-defined]
... weights_only=True,
... ) # type: ignore[attr-defined]
# Map tensors from GPU 1 to GPU 0
>>> torch.load(
... "tensors.pt",
... map_location={"cuda:1": "cuda:0"},
... weights_only=True,
... )
# Load tensor from io.BytesIO object
# Loading from a buffer setting weights_only=False, warning this can be unsafe
>>> with open("tensor.pt", "rb") as f:
... buffer = io.BytesIO(f.read())
>>> torch.load(buffer, weights_only=False)
# Load a module with 'ascii' encoding for unpickling
# Loading from a module setting weights_only=False, warning this can be unsafe
>>> torch.load("module.pt", encoding="ascii", weights_only=False)
torch.lobpcg
Python Library Documentation: function lobpcg in module torch._lobpcg
lobpcg(A: torch.Tensor, k: int | None = None, B: torch.Tensor | None = None, X: torch.Tensor | None = None, n: int | None = None, iK: torch.Tensor | None = None, niter: int | None = None, tol: float | None = None, largest: bool | None = None, method: str | None = None, tracker: None = None, ortho_iparams: dict[str, int] | None = None, ortho_fparams: dict[str, float] | None = None, ortho_bparams: dict[str, bool] | None = None) -> tuple[torch.Tensor, torch.Tensor]
Find the k largest (or smallest) eigenvalues and the corresponding
eigenvectors of a symmetric positive definite generalized
eigenvalue problem using matrix-free LOBPCG methods.
This function is a front-end to the following LOBPCG algorithms
selectable via `method` argument:
`method="basic"` - the LOBPCG method introduced by Andrew
Knyazev, see [Knyazev2001]. A less robust method, may fail when
Cholesky is applied to singular input.
`method="ortho"` - the LOBPCG method with orthogonal basis
selection [StathopoulosEtal2002]. A robust method.
Supported inputs are dense, sparse, and batches of dense matrices.
.. note:: In general, the basic method spends least time per
iteration. However, the robust methods converge much faster and
are more stable. So, the usage of the basic method is generally
not recommended but there exist cases where the usage of the
basic method may be preferred.
.. warning:: The backward method does not support sparse and complex inputs.
It works only when `B` is not provided (i.e. `B == None`).
We are actively working on extensions, and the details of
the algorithms are going to be published promptly.
.. warning:: While it is assumed that `A` is symmetric, `A.grad` is not.
To make sure that `A.grad` is symmetric, so that `A - t * A.grad` is symmetric
in first-order optimization routines, prior to running `lobpcg`
we do the following symmetrization map: `A -> (A + A.t()) / 2`.
The map is performed only when the `A` requires gradients.
.. warning:: LOBPCG algorithm is not applicable when the number of `A`'s rows
is smaller than 3x the number of requested eigenpairs `n`.
Args:
A (Tensor): the input tensor of size :math:`(*, m, m)`
k (integer, optional): the number of requested
eigenpairs. Default is the number of :math:`X`
columns (when specified) or `1`.
B (Tensor, optional): the input tensor of size :math:`(*, m,
m)`. When not specified, `B` is interpreted as
identity matrix.
X (tensor, optional): the input tensor of size :math:`(*, m, n)`
where `k <= n <= m`. When specified, it is used as
initial approximation of eigenvectors. X must be a
dense tensor.
n (integer, optional): if :math:`X` is not specified then `n`
specifies the size of the generated random
approximation of eigenvectors. Default value for `n`
is `k`. If :math:`X` is specified, any provided value of `n` is
ignored and `n` is automatically set to the number of
columns in :math:`X`.
iK (tensor, optional): the input tensor of size :math:`(*, m,
m)`. When specified, it will be used as preconditioner.
niter (int, optional): maximum number of iterations. When
reached, the iteration process is hard-stopped and
the current approximation of eigenpairs is returned.
For infinite iteration but until convergence criteria
is met, use `-1`.
tol (float, optional): residual tolerance for stopping
criterion. Default is `feps ** 0.5` where `feps` is
smallest non-zero floating-point number of the given
input tensor `A` data type.
largest (bool, optional): when True, solve the eigenproblem for
the largest eigenvalues. Otherwise, solve the
eigenproblem for smallest eigenvalues. Default is
`True`.
method (str, optional): select LOBPCG method. See the
description of the function above. Default is
"ortho".
tracker (callable, optional) : a function for tracing the
iteration process. When specified, it is called at
each iteration step with LOBPCG instance as an
argument. The LOBPCG instance holds the full state of
the iteration process in the following attributes:
`iparams`, `fparams`, `bparams` - dictionaries of
integer, float, and boolean valued input
parameters, respectively
`ivars`, `fvars`, `bvars`, `tvars` - dictionaries
of integer, float, boolean, and Tensor valued
iteration variables, respectively.
`A`, `B`, `iK` - input Tensor arguments.
`E`, `X`, `S`, `R` - iteration Tensor variables.
For instance:
`ivars["istep"]` - the current iteration step
`X` - the current approximation of eigenvectors
`E` - the current approximation of eigenvalues
`R` - the current residual
`ivars["converged_count"]` - the current number of converged eigenpairs
`tvars["rerr"]` - the current state of convergence criteria
Note that when `tracker` stores Tensor objects from
the LOBPCG instance, it must make copies of these.
If `tracker` sets `bvars["force_stop"] = True`, the
iteration process will be hard-stopped.
ortho_iparams, ortho_fparams, ortho_bparams (dict, optional):
various parameters to LOBPCG algorithm when using
`method="ortho"`.
Returns:
E (Tensor): tensor of eigenvalues of size :math:`(*, k)`
X (Tensor): tensor of eigenvectors of size :math:`(*, m, k)`
References:
[Knyazev2001] Andrew V. Knyazev. (2001) Toward the Optimal
Preconditioned Eigensolver: Locally Optimal Block Preconditioned
Conjugate Gradient Method. SIAM J. Sci. Comput., 23(2),
517-541. (25 pages)
https://epubs.siam.org/doi/abs/10.1137/S1064827500366124
[StathopoulosEtal2002] Andreas Stathopoulos and Kesheng
Wu. (2002) A Block Orthogonalization Procedure with Constant
Synchronization Requirements. SIAM J. Sci. Comput., 23(6),
2165-2182. (18 pages)
https://epubs.siam.org/doi/10.1137/S1064827500370883
[DuerschEtal2018] Jed A. Duersch, Meiyue Shao, Chao Yang, Ming
Gu. (2018) A Robust and Efficient Implementation of LOBPCG.
SIAM J. Sci. Comput., 40(5), C655-C676. (22 pages)
https://arxiv.org/abs/1704.07458
torch.log
Python Library Documentation: built-in function log in module torch
log(...)
log(input, *, out=None) -> Tensor
Returns a new tensor with the natural logarithm of the elements
of :attr:`input`.
.. math::
y_{i} = \log_{e} (x_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(5) * 5
>>> a
tensor([4.7767, 4.3234, 1.2156, 0.2411, 4.5739])
>>> torch.log(a)
tensor([ 1.5637, 1.4640, 0.1952, -1.4226, 1.5204])
torch.log10
Python Library Documentation: built-in function log10 in module torch
log10(...)
log10(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the logarithm to the base 10 of the elements
of :attr:`input`.
.. math::
y_{i} = \log_{10} (x_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(5)
>>> a
tensor([ 0.5224, 0.9354, 0.7257, 0.1301, 0.2251])
>>> torch.log10(a)
tensor([-0.2820, -0.0290, -0.1392, -0.8857, -0.6476])
torch.log10_
Python Library Documentation: built-in function log10_ in module torch log10_(...)
torch.log1p
Python Library Documentation: built-in function log1p in module torch
log1p(...)
log1p(input, *, out=None) -> Tensor
Returns a new tensor with the natural logarithm of (1 + :attr:`input`).
.. math::
y_i = \log_{e} (x_i + 1)
.. note:: This function is more accurate than :func:`torch.log` for small
values of :attr:`input`
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(5)
>>> a
tensor([-1.0090, -0.9923, 1.0249, -0.5372, 0.2492])
>>> torch.log1p(a)
tensor([ nan, -4.8653, 0.7055, -0.7705, 0.2225])
torch.log1p_
Python Library Documentation: built-in function log1p_ in module torch log1p_(...)
torch.log2
Python Library Documentation: built-in function log2 in module torch
log2(...)
log2(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the logarithm to the base 2 of the elements
of :attr:`input`.
.. math::
y_{i} = \log_{2} (x_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(5)
>>> a
tensor([ 0.8419, 0.8003, 0.9971, 0.5287, 0.0490])
>>> torch.log2(a)
tensor([-0.2483, -0.3213, -0.0042, -0.9196, -4.3504])
torch.log2_
Python Library Documentation: built-in function log2_ in module torch log2_(...)
torch.log_
Python Library Documentation: built-in function log_ in module torch log_(...)
torch.log_softmax
Python Library Documentation: built-in function log_softmax in module torch log_softmax(...)
torch.logaddexp
Python Library Documentation: built-in function logaddexp in module torch
logaddexp(...)
logaddexp(input, other, *, out=None) -> Tensor
Logarithm of the sum of exponentiations of the inputs.
Calculates pointwise :math:`\log\left(e^x + e^y\right)`. This function is useful
in statistics where the calculated probabilities of events may be so small as to
exceed the range of normal floating point numbers. In such cases the logarithm
of the calculated probability is stored. This function allows adding
probabilities stored in such a fashion.
This op should be disambiguated with :func:`torch.logsumexp` which performs a
reduction on a single tensor.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> torch.logaddexp(torch.tensor([-1.0]), torch.tensor([-1.0, -2, -3]))
tensor([-0.3069, -0.6867, -0.8731])
>>> torch.logaddexp(torch.tensor([-100.0, -200, -300]), torch.tensor([-1.0, -2, -3]))
tensor([-1., -2., -3.])
>>> torch.logaddexp(torch.tensor([1.0, 2000, 30000]), torch.tensor([-1.0, -2, -3]))
tensor([1.1269e+00, 2.0000e+03, 3.0000e+04])
torch.logaddexp2
Python Library Documentation: built-in function logaddexp2 in module torch
logaddexp2(...)
logaddexp2(input, other, *, out=None) -> Tensor
Logarithm of the sum of exponentiations of the inputs in base-2.
Calculates pointwise :math:`\log_2\left(2^x + 2^y\right)`. See
:func:`torch.logaddexp` for more details.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword arguments:
out (Tensor, optional): the output tensor.
torch.logcumsumexp
Python Library Documentation: built-in function logcumsumexp in module torch
logcumsumexp(...)
logcumsumexp(input, dim, *, out=None) -> Tensor
Returns the logarithm of the cumulative summation of the exponentiation of
elements of :attr:`input` in the dimension :attr:`dim`.
For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
.. math::
\text{logcumsumexp}(x)_{ij} = \log \sum\limits_{k=0}^{j} \exp(x_{ik})
Args:
input (Tensor): the input tensor.
dim (int): the dimension to do the operation over
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(10)
>>> torch.logcumsumexp(a, dim=0)
tensor([-0.42296738, -0.04462666, 0.86278635, 0.94622083, 1.05277811,
1.39202815, 1.83525007, 1.84492621, 2.06084887, 2.06844475]))
torch.logdet
Python Library Documentation: built-in function logdet in module torch
logdet(...)
logdet(input) -> Tensor
Calculates log determinant of a square matrix or batches of square matrices.
It returns ``-inf`` if the input has a determinant of zero, and ``NaN`` if it has
a negative determinant.
.. note::
Backward through :meth:`logdet` internally uses SVD results when :attr:`input`
is not invertible. In this case, double backward through :meth:`logdet` will
be unstable in when :attr:`input` doesn't have distinct singular values. See
:func:`torch.linalg.svd` for details.
.. seealso::
:func:`torch.linalg.slogdet` computes the sign (resp. angle) and natural logarithm of the
absolute value of the determinant of real-valued (resp. complex) square matrices.
Arguments:
input (Tensor): the input tensor of size ``(*, n, n)`` where ``*`` is zero or more
batch dimensions.
Example::
>>> A = torch.randn(3, 3)
>>> torch.det(A)
tensor(0.2611)
>>> torch.logdet(A)
tensor(-1.3430)
>>> A
tensor([[[ 0.9254, -0.6213],
[-0.5787, 1.6843]],
[[ 0.3242, -0.9665],
[ 0.4539, -0.0887]],
[[ 1.1336, -0.4025],
[-0.7089, 0.9032]]])
>>> A.det()
tensor([1.1990, 0.4099, 0.7386])
>>> A.det().log()
tensor([ 0.1815, -0.8917, -0.3031])
torch.logical_and
Python Library Documentation: built-in function logical_and in module torch
logical_and(...)
logical_and(input, other, *, out=None) -> Tensor
Computes the element-wise logical AND of the given input tensors. Zeros are treated as ``False`` and nonzeros are
treated as ``True``.
Args:
input (Tensor): the input tensor.
other (Tensor): the tensor to compute AND with
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.logical_and(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
tensor([ True, False, False])
>>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
>>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
>>> torch.logical_and(a, b)
tensor([False, False, True, False])
>>> torch.logical_and(a.double(), b.double())
tensor([False, False, True, False])
>>> torch.logical_and(a.double(), b)
tensor([False, False, True, False])
>>> torch.logical_and(a, b, out=torch.empty(4, dtype=torch.bool))
tensor([False, False, True, False])
torch.logical_not
Python Library Documentation: built-in function logical_not in module torch
logical_not(...)
logical_not(input, *, out=None) -> Tensor
Computes the element-wise logical NOT of the given input tensor. If not specified, the output tensor will have the bool
dtype. If the input tensor is not a bool tensor, zeros are treated as ``False`` and non-zeros are treated as ``True``.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.logical_not(torch.tensor([True, False]))
tensor([False, True])
>>> torch.logical_not(torch.tensor([0, 1, -10], dtype=torch.int8))
tensor([ True, False, False])
>>> torch.logical_not(torch.tensor([0., 1.5, -10.], dtype=torch.double))
tensor([ True, False, False])
>>> torch.logical_not(torch.tensor([0., 1., -10.], dtype=torch.double), out=torch.empty(3, dtype=torch.int16))
tensor([1, 0, 0], dtype=torch.int16)
torch.logical_or
Python Library Documentation: built-in function logical_or in module torch
logical_or(...)
logical_or(input, other, *, out=None) -> Tensor
Computes the element-wise logical OR of the given input tensors. Zeros are treated as ``False`` and nonzeros are
treated as ``True``.
Args:
input (Tensor): the input tensor.
other (Tensor): the tensor to compute OR with
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.logical_or(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
tensor([ True, False, True])
>>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
>>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
>>> torch.logical_or(a, b)
tensor([ True, True, True, False])
>>> torch.logical_or(a.double(), b.double())
tensor([ True, True, True, False])
>>> torch.logical_or(a.double(), b)
tensor([ True, True, True, False])
>>> torch.logical_or(a, b, out=torch.empty(4, dtype=torch.bool))
tensor([ True, True, True, False])
torch.logical_xor
Python Library Documentation: built-in function logical_xor in module torch
logical_xor(...)
logical_xor(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
Computes the element-wise logical XOR of the given input tensors. Zeros are treated as ``False`` and nonzeros are
treated as ``True``.
Args:
input (Tensor): the input tensor.
other (Tensor): the tensor to compute XOR with
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.logical_xor(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
tensor([False, False, True])
>>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
>>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
>>> torch.logical_xor(a, b)
tensor([ True, True, False, False])
>>> torch.logical_xor(a.double(), b.double())
tensor([ True, True, False, False])
>>> torch.logical_xor(a.double(), b)
tensor([ True, True, False, False])
>>> torch.logical_xor(a, b, out=torch.empty(4, dtype=torch.bool))
tensor([ True, True, False, False])
torch.logit
Python Library Documentation: built-in function logit in module torch
logit(...)
logit(input, eps=None, *, out=None) -> Tensor
Alias for :func:`torch.special.logit`.
torch.logit_
Python Library Documentation: built-in function logit_ in module torch logit_(...)
torch.logspace
Python Library Documentation: built-in function logspace in module torch
logspace(...)
logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
:math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
with base :attr:`base`. That is, the values are:
.. math::
(\text{base}^{\text{start}},
\text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
\ldots,
\text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
\text{base}^{\text{end}})
From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
Args:
start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
steps (int): size of the constructed tensor
base (float, optional): base of the logarithm function. Default: ``10.0``.
Keyword arguments:
out (Tensor, optional): the output tensor.
dtype (torch.dtype, optional): the data type to perform the computation in.
Default: if None, uses the global default dtype (see torch.get_default_dtype())
when both :attr:`start` and :attr:`end` are real,
and corresponding complex dtype when either is complex.
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.logspace(start=-10, end=10, steps=5)
tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
>>> torch.logspace(start=0.1, end=1.0, steps=5)
tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
>>> torch.logspace(start=0.1, end=1.0, steps=1)
tensor([1.2589])
>>> torch.logspace(start=2, end=2, steps=1, base=2)
tensor([4.0])
torch.logsumexp
Python Library Documentation: built-in function logsumexp in module torch
logsumexp(...)
logsumexp(input, dim, keepdim=False, *, out=None)
Returns the log of summed exponentials of each row of the :attr:`input`
tensor in the given dimension :attr:`dim`. The computation is numerically
stabilized.
For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
.. math::
\text{logsumexp}(x)_{i} = \log \sum_j \exp(x_{ij})
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints): the dimension or dimensions to reduce.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(3, 3)
>>> torch.logsumexp(a, 1)
tensor([1.4907, 1.0593, 1.5696])
>>> torch.dist(torch.logsumexp(a, 1), torch.log(torch.sum(torch.exp(a), 1)))
tensor(1.6859e-07)
torch.long
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.lstm
Python Library Documentation: built-in function lstm in module torch lstm(...)
torch.lstm_cell
Python Library Documentation: built-in function lstm_cell in module torch lstm_cell(...)
torch.lstsq
Python Library Documentation: function lstsq in module torch._linalg_utils lstsq(input: torch.Tensor, A: torch.Tensor, *, out=None) -> tuple[torch.Tensor, torch.Tensor]
torch.lt
Python Library Documentation: built-in function lt in module torch
lt(...)
lt(input, other, *, out=None) -> Tensor
Computes :math:`\text{input} < \text{other}` element-wise.
The second argument can be a number or a tensor whose shape is
:ref:`broadcastable <broadcasting-semantics>` with the first argument.
Args:
input (Tensor): the tensor to compare
other (Tensor or float): the tensor or value to compare
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
A boolean tensor that is True where :attr:`input` is less than :attr:`other` and False elsewhere
Example::
>>> torch.lt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[False, False], [True, False]])
torch.lu
Python Library Documentation: function lu in module torch.functional
lu(*args, **kwargs)
Computes the LU factorization of a matrix or batches of matrices
:attr:`A`. Returns a tuple containing the LU factorization and
pivots of :attr:`A`. Pivoting is done if :attr:`pivot` is set to
``True``.
.. warning::
:func:`torch.lu` is deprecated in favor of :func:`torch.linalg.lu_factor`
and :func:`torch.linalg.lu_factor_ex`. :func:`torch.lu` will be removed in a
future PyTorch release.
``LU, pivots, info = torch.lu(A, compute_pivots)`` should be replaced with
.. code:: python
LU, pivots = torch.linalg.lu_factor(A, compute_pivots)
``LU, pivots, info = torch.lu(A, compute_pivots, get_infos=True)`` should be replaced with
.. code:: python
LU, pivots, info = torch.linalg.lu_factor_ex(A, compute_pivots)
.. note::
* The returned permutation matrix for every matrix in the batch is
represented by a 1-indexed vector of size ``min(A.shape[-2], A.shape[-1])``.
``pivots[i] == j`` represents that in the ``i``-th step of the algorithm,
the ``i``-th row was permuted with the ``j-1``-th row.
* LU factorization with :attr:`pivot` = ``False`` is not available
for CPU, and attempting to do so will throw an error. However,
LU factorization with :attr:`pivot` = ``False`` is available for
CUDA.
* This function does not check if the factorization was successful
or not if :attr:`get_infos` is ``True`` since the status of the
factorization is present in the third element of the return tuple.
* In the case of batches of square matrices with size less or equal
to 32 on a CUDA device, the LU factorization is repeated for
singular matrices due to the bug in the MAGMA library
(see magma issue 13).
* ``L``, ``U``, and ``P`` can be derived using :func:`torch.lu_unpack`.
.. warning::
The gradients of this function will only be finite when :attr:`A` is full rank.
This is because the LU decomposition is just differentiable at full rank matrices.
Furthermore, if :attr:`A` is close to not being full rank,
the gradient will be numerically unstable as it depends on the computation of :math:`L^{-1}` and :math:`U^{-1}`.
Args:
A (Tensor): the tensor to factor of size :math:`(*, m, n)`
pivot (bool, optional): Whether to compute the LU decomposition with partial pivoting, or the regular LU
decomposition. :attr:`pivot`\ `= False` not supported on CPU. Default: `True`.
get_infos (bool, optional): if set to ``True``, returns an info IntTensor.
Default: ``False``
out (tuple, optional): optional output tuple. If :attr:`get_infos` is ``True``,
then the elements in the tuple are Tensor, IntTensor,
and IntTensor. If :attr:`get_infos` is ``False``, then the
elements in the tuple are Tensor, IntTensor. Default: ``None``
Returns:
(Tensor, IntTensor, IntTensor (optional)): A tuple of tensors containing
- **factorization** (*Tensor*): the factorization of size :math:`(*, m, n)`
- **pivots** (*IntTensor*): the pivots of size :math:`(*, \text{min}(m, n))`.
``pivots`` stores all the intermediate transpositions of rows.
The final permutation ``perm`` could be reconstructed by
applying ``swap(perm[i], perm[pivots[i] - 1])`` for ``i = 0, ..., pivots.size(-1) - 1``,
where ``perm`` is initially the identity permutation of :math:`m` elements
(essentially this is what :func:`torch.lu_unpack` is doing).
- **infos** (*IntTensor*, *optional*): if :attr:`get_infos` is ``True``, this is a tensor of
size :math:`(*)` where non-zero values indicate whether factorization for the matrix or
each minibatch has succeeded or failed
Example::
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_LAPACK)
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> A = torch.randn(2, 3, 3)
>>> A_LU, pivots = torch.lu(A)
>>> A_LU
tensor([[[ 1.3506, 2.5558, -0.0816],
[ 0.1684, 1.1551, 0.1940],
[ 0.1193, 0.6189, -0.5497]],
[[ 0.4526, 1.2526, -0.3285],
[-0.7988, 0.7175, -0.9701],
[ 0.2634, -0.9255, -0.3459]]])
>>> pivots
tensor([[ 3, 3, 3],
[ 3, 3, 3]], dtype=torch.int32)
>>> A_LU, pivots, info = torch.lu(A, get_infos=True)
>>> if info.nonzero().size(0) == 0:
... print('LU factorization succeeded for all samples!')
LU factorization succeeded for all samples!
torch.lu_solve
Python Library Documentation: built-in function lu_solve in module torch
lu_solve(...)
lu_solve(b, LU_data, LU_pivots, *, out=None) -> Tensor
Returns the LU solve of the linear system :math:`Ax = b` using the partially pivoted
LU factorization of A from :func:`~linalg.lu_factor`.
This function supports ``float``, ``double``, ``cfloat`` and ``cdouble`` dtypes for :attr:`input`.
.. warning::
:func:`torch.lu_solve` is deprecated in favor of :func:`torch.linalg.lu_solve`.
:func:`torch.lu_solve` will be removed in a future PyTorch release.
``X = torch.lu_solve(B, LU, pivots)`` should be replaced with
.. code:: python
X = linalg.lu_solve(LU, pivots, B)
Arguments:
b (Tensor): the RHS tensor of size :math:`(*, m, k)`, where :math:`*`
is zero or more batch dimensions.
LU_data (Tensor): the pivoted LU factorization of A from :meth:`~linalg.lu_factor` of size :math:`(*, m, m)`,
where :math:`*` is zero or more batch dimensions.
LU_pivots (IntTensor): the pivots of the LU factorization from :meth:`~linalg.lu_factor` of size :math:`(*, m)`,
where :math:`*` is zero or more batch dimensions.
The batch dimensions of :attr:`LU_pivots` must be equal to the batch dimensions of
:attr:`LU_data`.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> A = torch.randn(2, 3, 3)
>>> b = torch.randn(2, 3, 1)
>>> LU, pivots = torch.linalg.lu_factor(A)
>>> x = torch.lu_solve(b, LU, pivots)
>>> torch.dist(A @ x, b)
tensor(1.00000e-07 *
2.8312)
torch.lu_unpack
Python Library Documentation: built-in function lu_unpack in module torch
lu_unpack(...)
lu_unpack(LU_data, LU_pivots, unpack_data=True, unpack_pivots=True, *, out=None) -> (Tensor, Tensor, Tensor)
Unpacks the LU decomposition returned by :func:`~linalg.lu_factor` into the `P, L, U` matrices.
.. seealso::
:func:`~linalg.lu` returns the matrices from the LU decomposition. Its gradient formula is more efficient
than that of doing :func:`~linalg.lu_factor` followed by :func:`~linalg.lu_unpack`.
Args:
LU_data (Tensor): the packed LU factorization data
LU_pivots (Tensor): the packed LU factorization pivots
unpack_data (bool): flag indicating if the data should be unpacked.
If ``False``, then the returned ``L`` and ``U`` are empty tensors.
Default: ``True``
unpack_pivots (bool): flag indicating if the pivots should be unpacked into a permutation matrix ``P``.
If ``False``, then the returned ``P`` is an empty tensor.
Default: ``True``
Keyword args:
out (tuple, optional): output tuple of three tensors. Ignored if `None`.
Returns:
A namedtuple ``(P, L, U)``
Examples::
>>> A = torch.randn(2, 3, 3)
>>> LU, pivots = torch.linalg.lu_factor(A)
>>> P, L, U = torch.lu_unpack(LU, pivots)
>>> # We can recover A from the factorization
>>> A_ = P @ L @ U
>>> torch.allclose(A, A_)
True
>>> # LU factorization of a rectangular matrix:
>>> A = torch.randn(2, 3, 2)
>>> LU, pivots = torch.linalg.lu_factor(A)
>>> P, L, U = torch.lu_unpack(LU, pivots)
>>> # P, L, U are the same as returned by linalg.lu
>>> P_, L_, U_ = torch.linalg.lu(A)
>>> torch.allclose(P, P_) and torch.allclose(L, L_) and torch.allclose(U, U_)
True
torch.manual_seed
Python Library Documentation: function manual_seed in module torch.random
manual_seed(seed) -> torch._C.Generator
Sets the seed for generating random numbers on all devices. Returns a
`torch.Generator` object.
Args:
seed (int): The desired seed. Value must be within the inclusive range
`[-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]`. Otherwise, a RuntimeError
is raised. Negative inputs are remapped to positive values with the formula
`0xffff_ffff_ffff_ffff + seed`.
torch.margin_ranking_loss
Python Library Documentation: built-in function margin_ranking_loss in module torch margin_ranking_loss(...)
torch.masked
Python Library Documentation: package torch.masked in torch
NAME
torch.masked
PACKAGE CONTENTS
_docs
_ops
maskedtensor (package)
CLASSES
torch.Tensor(torch._C.TensorBase)
torch.masked.maskedtensor.core.MaskedTensor
class MaskedTensor(torch.Tensor)
| MaskedTensor(data, mask, requires_grad=False)
|
| Method resolution order:
| MaskedTensor
| torch.Tensor
| torch._C.TensorBase
| builtins.object
|
| Methods defined here:
|
| __init__(self, data, mask, requires_grad=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __lt__(self, other)
| Return self<value.
|
| __repr__(self)
| Return repr(self).
|
| get_data(self)
|
| get_mask(self)
|
| is_sparse_coo(self)
|
| is_sparse_csr(self)
| Is ``True`` if the Tensor uses sparse CSR storage layout, ``False`` otherwise.
|
| to_tensor(self, value)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_dispatch__(func, types, args, kwargs)
|
| __torch_function__(func, types, args=(), kwargs=None)
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| unary(fn, data, mask)
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, data, mask, requires_grad=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| is_sparse
| Is ``True`` if the Tensor uses sparse COO storage layout, ``False`` otherwise.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.Tensor:
|
| __abs__ = abs(...)
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __neg__ = neg(...)
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| solve(self, other) from torch._tensor.Tensor
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.Tensor:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.Tensor:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.Tensor:
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C.TensorBase:
|
| __add__(...)
|
| __and__(...)
|
| __bool__(...)
|
| __complex__(...)
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __div__(...)
|
| __eq__(...)
| Return self==value.
|
| __float__(...)
|
| __ge__(...)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(...)
| Return self>value.
|
| __iadd__(...)
|
| __iand__(...)
|
| __idiv__(...)
|
| __ifloordiv__(...)
|
| __ilshift__(...)
|
| __imod__(...)
|
| __imul__(...)
|
| __index__(...)
|
| __int__(...)
|
| __invert__(...)
|
| __ior__(...)
|
| __irshift__(...)
|
| __isub__(...)
|
| __ixor__(...)
|
| __le__(...)
| Return self<=value.
|
| __long__(...)
|
| __lshift__(...)
|
| __matmul__(...)
|
| __mod__(...)
|
| __mul__(...)
|
| __ne__(...)
| Return self!=value.
|
| __nonzero__(...)
|
| __or__(...)
| Return self|value.
|
| __radd__(...)
|
| __rand__(...)
|
| __rmul__(...)
|
| __ror__(...)
| Return value|self.
|
| __rshift__(...)
|
| __rxor__(...)
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sub__(...)
|
| __truediv__(...)
|
| __xor__(...)
|
| abs(...)
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...)
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...)
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...)
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...)
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...)
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...)
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...)
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...)
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...)
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...)
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...)
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...)
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...)
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...)
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...)
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...)
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...)
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...)
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...)
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...)
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...)
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...)
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...)
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...)
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...)
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...)
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...)
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...)
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...)
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...)
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...)
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...)
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...)
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...)
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...)
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...)
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...)
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...)
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...)
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...)
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...)
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...)
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...)
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...)
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...)
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...)
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...)
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...)
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...)
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...)
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...)
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...)
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...)
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...)
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...)
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...)
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...)
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...)
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| baddbmm(...)
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...)
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...)
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...)
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...)
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...)
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...)
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...)
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...)
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...)
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...)
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...)
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...)
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...)
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...)
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...)
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...)
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...)
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...)
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...)
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...)
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...)
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...)
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...)
|
| cdouble(...)
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...)
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...)
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...)
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...)
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...)
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...)
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...)
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...)
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...)
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...)
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...)
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...)
|
| clamp_max_(...)
|
| clamp_min(...)
|
| clamp_min_(...)
|
| clip(...)
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...)
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...)
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...)
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...)
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...)
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...)
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...)
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...)
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...)
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...)
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...)
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...)
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...)
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...)
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...)
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...)
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...)
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...)
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...)
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...)
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...)
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...)
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...)
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...)
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...)
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...)
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...)
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...)
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...)
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...)
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...)
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...)
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...)
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...)
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...)
| det() -> Tensor
|
| See :func:`torch.det`
|
| diag(...)
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...)
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...)
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...)
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...)
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...)
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...)
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...)
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...)
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dist(...)
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...)
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...)
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...)
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...)
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...)
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...)
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...)
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| element_size(...)
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...)
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...)
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...)
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...)
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...)
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...)
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...)
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...)
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...)
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...)
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...)
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...)
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...)
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...)
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...)
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...)
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...)
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...)
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...)
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...)
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...)
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...)
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...)
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...)
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...)
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...)
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...)
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...)
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...)
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...)
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...)
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...)
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...)
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...)
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...)
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...)
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...)
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...)
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...)
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...)
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...)
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...)
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...)
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...)
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...)
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...)
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...)
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...)
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...)
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...)
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...)
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...)
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...)
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...)
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...)
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...)
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...)
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...)
|
| heaviside(...)
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...)
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...)
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...)
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...)
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...)
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...)
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...)
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...)
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...)
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...)
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...)
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...)
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index_add(...)
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...)
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...)
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...)
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...)
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...)
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...)
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...)
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...)
|
| index_reduce_(...)
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...)
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...)
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...)
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...)
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...)
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...)
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...)
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...)
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...)
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...)
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...)
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...)
|
| is_floating_point(...)
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...)
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...)
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...)
|
| is_pinned(...)
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...)
|
| is_set_to(...)
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_signed(...)
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...)
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...)
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...)
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...)
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...)
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...)
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...)
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| item(...)
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...)
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...)
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...)
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...)
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...)
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...)
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...)
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...)
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...)
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...)
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...)
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...)
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...)
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...)
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...)
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...)
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...)
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...)
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...)
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...)
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...)
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...)
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...)
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...)
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...)
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...)
|
| logaddexp(...)
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...)
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...)
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...)
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...)
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...)
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...)
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...)
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...)
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...)
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...)
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...)
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...)
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...)
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...)
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...)
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lt(...)
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...)
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu_solve(...)
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...)
|
| map_(...)
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...)
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...)
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...)
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...)
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...)
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...)
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...)
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...)
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...)
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...)
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...)
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...)
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...)
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...)
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...)
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...)
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| moveaxis(...)
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...)
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...)
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...)
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...)
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...)
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...)
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...)
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...)
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...)
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...)
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...)
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...)
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...)
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...)
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...)
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...)
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...)
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...)
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...)
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...)
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...)
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...)
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...)
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...)
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...)
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...)
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...)
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...)
|
| new_empty(...)
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...)
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...)
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...)
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...)
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...)
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...)
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...)
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...)
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...)
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| normal_(...)
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...)
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...)
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...)
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...)
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...)
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...)
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...)
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...)
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...)
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...)
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...)
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...)
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...)
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...)
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...)
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...)
|
| prod(...)
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...)
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...)
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...)
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...)
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...)
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...)
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...)
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...)
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...)
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...)
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...)
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...)
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...)
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...)
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...)
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...)
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...)
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| relu(...)
|
| relu_(...)
|
| remainder(...)
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...)
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...)
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...)
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...)
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...)
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...)
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...)
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...)
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize_(...)
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as_(...)
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...)
|
| resolve_conj(...)
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...)
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...)
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...)
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...)
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...)
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...)
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...)
|
| rsqrt(...)
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...)
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...)
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...)
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...)
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...)
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...)
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...)
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...)
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...)
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...)
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...)
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...)
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| short(...)
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...)
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...)
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...)
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...)
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...)
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...)
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...)
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...)
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...)
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...)
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...)
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...)
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...)
|
| slice_scatter(...)
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...)
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...)
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...)
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| sort(...)
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...)
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...)
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...)
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...)
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split_with_sizes(...)
|
| sqrt(...)
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...)
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...)
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...)
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...)
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...)
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...)
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...)
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| storage_offset(...)
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| stride(...)
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...)
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...)
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...)
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...)
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...)
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...)
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...)
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...)
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...)
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...)
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...)
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| t(...)
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...)
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...)
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...)
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...)
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...)
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...)
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...)
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...)
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...)
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...)
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...)
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...)
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...)
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...)
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...)
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...)
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_csc(...)
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...)
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...)
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...)
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...)
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...)
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...)
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...)
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...)
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...)
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...)
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...)
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...)
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...)
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...)
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...)
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...)
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...)
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...)
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unfold(...)
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...)
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unsafe_chunk(...)
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...)
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...)
|
| unsqueeze(...)
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...)
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...)
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...)
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...)
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...)
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...)
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...)
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...)
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...)
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...)
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...)
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...)
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...)
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C.TensorBase:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| dtype
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_cuda
| Is ``True`` if the Tensor is stored on the GPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| is_xpu
| Is ``True`` if the Tensor is stored on the XPU, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| layout
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
FUNCTIONS
amax(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: tuple[int, ...] | None = None, *, keepdim: bool | None = False, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
amax(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
Returns maximum of all the elements in the :attr:`input`
tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
elements are masked out according to the boolean tensor
:attr:`mask`.
The identity value of maximum operation, which is used to start the
reduction, depends on input dtype. For instance, for float32, uint8,
and int32 dtypes, the identity values are ``-inf``, ``0``, and ``-2147483648``, respectively.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
size 1. Otherwise, :attr:`dim` is squeezed (see
:func:`torch.squeeze`), resulting in the output tensor having 1 (or
``len(dim)``) fewer dimension(s).
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True
then the corresponding element in :attr:`input` tensor will be
included in maximum computation, otherwise the element is
ignored.
When all elements of :attr:`input` along the given dimension
:attr:`dim` are ignored (fully masked-out), the corresponding element
of the output tensor will have undefined value: it may or may not
correspond to the identity value of maximum operation; the
choice may correspond to the value that leads to the most efficient
storage of :attr:`output` tensor.
The mask of the output tensor can be computed as
``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
dtype=torch.bool)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
Default: None that is equivalent to ``tuple(range(input.ndim))``.
Keyword args:
keepdim (bool, optional): whether the output tensor has
:attr:`dim` retained or not. Default: False.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
>>> input
tensor([[-3, -2, -1],
[ 0, 1, 2]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.amax(input, 1, mask=mask)
tensor([ -1, -9223372036854775808])
amin(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: tuple[int, ...] | None = None, *, keepdim: bool | None = False, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
amin(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
Returns minimum of all the elements in the :attr:`input`
tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
elements are masked out according to the boolean tensor
:attr:`mask`.
The identity value of minimum operation, which is used to start the
reduction, depends on input dtype. For instance, for float32, uint8,
and int32 dtypes, the identity values are ``inf``, ``255``, and ``2147483647``, respectively.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
size 1. Otherwise, :attr:`dim` is squeezed (see
:func:`torch.squeeze`), resulting in the output tensor having 1 (or
``len(dim)``) fewer dimension(s).
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True
then the corresponding element in :attr:`input` tensor will be
included in minimum computation, otherwise the element is
ignored.
When all elements of :attr:`input` along the given dimension
:attr:`dim` are ignored (fully masked-out), the corresponding element
of the output tensor will have undefined value: it may or may not
correspond to the identity value of minimum operation; the
choice may correspond to the value that leads to the most efficient
storage of :attr:`output` tensor.
The mask of the output tensor can be computed as
``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
dtype=torch.bool)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
Default: None that is equivalent to ``tuple(range(input.ndim))``.
Keyword args:
keepdim (bool, optional): whether the output tensor has
:attr:`dim` retained or not. Default: False.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
>>> input
tensor([[-3, -2, -1],
[ 0, 1, 2]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.amin(input, 1, mask=mask)
tensor([ -3, 9223372036854775807])
argmax(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: int | None = None, *, keepdim: bool | None = False, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
argmax(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
Returns argmax of all the elements in the :attr:`input`
tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
elements are masked out according to the boolean tensor
:attr:`mask`.
The identity value of argmax operation, which is used to start the
reduction, depends on input dtype. For instance, for float32, uint8,
and int32 dtypes, the identity values are ``-inf``, ``0``, and ``-2147483648``, respectively.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
size 1. Otherwise, :attr:`dim` is squeezed (see
:func:`torch.squeeze`), resulting in the output tensor having 1 (or
``len(dim)``) fewer dimension(s).
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True
then the corresponding element in :attr:`input` tensor will be
included in argmax computation, otherwise the element is
ignored.
When all elements of :attr:`input` along the given dimension
:attr:`dim` are ignored (fully masked-out), the corresponding element
of the output tensor will have undefined value: it may or may not
correspond to the identity value of argmax operation; the
choice may correspond to the value that leads to the most efficient
storage of :attr:`output` tensor.
The mask of the output tensor can be computed as
``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
dtype=torch.bool)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int): the dimension along which argmax is computed.
Keyword args:
keepdim (bool, optional): whether the output tensor has
:attr:`dim` retained or not. Default: False.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
>>> input
tensor([[-3, -2, -1],
[ 0, 1, 2]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.argmax(input, 1, mask=mask)
tensor([2, 0])
argmin(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: int | None = None, *, keepdim: bool | None = False, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
argmin(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
Returns argmin of all the elements in the :attr:`input`
tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
elements are masked out according to the boolean tensor
:attr:`mask`.
The identity value of argmin operation, which is used to start the
reduction, depends on input dtype. For instance, for float32, uint8,
and int32 dtypes, the identity values are ``inf``, ``255``, and ``2147483647``, respectively.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
size 1. Otherwise, :attr:`dim` is squeezed (see
:func:`torch.squeeze`), resulting in the output tensor having 1 (or
``len(dim)``) fewer dimension(s).
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True
then the corresponding element in :attr:`input` tensor will be
included in argmin computation, otherwise the element is
ignored.
When all elements of :attr:`input` along the given dimension
:attr:`dim` are ignored (fully masked-out), the corresponding element
of the output tensor will have undefined value: it may or may not
correspond to the identity value of argmin operation; the
choice may correspond to the value that leads to the most efficient
storage of :attr:`output` tensor.
The mask of the output tensor can be computed as
``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
dtype=torch.bool)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int): the dimension along which argmin is computed.
Keyword args:
keepdim (bool, optional): whether the output tensor has
:attr:`dim` retained or not. Default: False.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
>>> input
tensor([[-3, -2, -1],
[ 0, 1, 2]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.argmin(input, 1, mask=mask)
tensor([0, 0])
as_masked_tensor(data: object, mask: object) -> torch.masked.maskedtensor.core.MaskedTensor
cumprod(input: torch.Tensor, dim: int, *, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
cumprod(input, dim, *, dtype=None, mask=None) -> Tensor
Returns cumulative_prod of all the slices in the :attr:`input` tensor
along :attr:`dim` while the :attr:`input` elements are masked out
according to the boolean tensor :attr:`mask`.
Let ``x`` be a sequence of unmasked elements of one-dimensional slice
of the :attr:`input` tensor. Cumprod of i-th element in ``x`` is
defined as ``prod(x[:i])``.
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True then
the corresponding element in :attr:`input` tensor will be included in
cumulative_prod computation, otherwise the element is ignored.
The values of masked-out elements of the output tensor have undefined
value: it may or may not be set to zero or nan; the choice may correspond to
the value that leads to the most efficient storage of :attr:`output`
tensor.
The mask of the cumulative_prod output tensor can be computed as
``torch.broadcast_to(mask, input.shape)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int): the dimension along which cumulative_prod is computed.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
>>> input
tensor([[-3., -2., -1.],
[ 0., 1., 2.]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.cumprod(input, 1, mask=mask)
tensor([[-3., -3., 3.],
[ 1., 1., 1.]])
cumsum(input: torch.Tensor, dim: int, *, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
cumsum(input, dim, *, dtype=None, mask=None) -> Tensor
Returns cumulative_sum of all the slices in the :attr:`input` tensor
along :attr:`dim` while the :attr:`input` elements are masked out
according to the boolean tensor :attr:`mask`.
Let ``x`` be a sequence of unmasked elements of one-dimensional slice
of the :attr:`input` tensor. Cumsum of i-th element in ``x`` is
defined as ``sum(x[:i])``.
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True then
the corresponding element in :attr:`input` tensor will be included in
cumulative_sum computation, otherwise the element is ignored.
The values of masked-out elements of the output tensor have undefined
value: it may or may not be set to zero or nan; the choice may correspond to
the value that leads to the most efficient storage of :attr:`output`
tensor.
The mask of the cumulative_sum output tensor can be computed as
``torch.broadcast_to(mask, input.shape)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int): the dimension along which cumulative_sum is computed.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
>>> input
tensor([[-3., -2., -1.],
[ 0., 1., 2.]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.cumsum(input, 1, mask=mask)
tensor([[-3., -3., -4.],
[ 0., 0., 0.]])
is_masked_tensor(obj: Any, /) -> typing_extensions.TypeIs[ForwardRef('MaskedTensor')]
Returns True if the input is a MaskedTensor, else False
Args:
a: any input
Examples:
>>> # xdoctest: +SKIP
>>> from torch.masked import MaskedTensor
>>> data = torch.arange(6).reshape(2, 3)
>>> mask = torch.tensor([[True, False, False], [True, True, False]])
>>> mt = MaskedTensor(data, mask)
>>> is_masked_tensor(mt)
True
log_softmax(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: int, *, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
log_softmax(input, dim, *, dtype=None, mask=None) -> Tensor
Returns log_softmax of all the slices in the :attr:`input` tensor
along :attr:`dim` while the :attr:`input` elements are masked out
according to the boolean tensor :attr:`mask`.
Let ``x`` be a sequence of unmasked elements of one-dimensional slice
of the :attr:`input` tensor. LogSoftmax of i-th element in ``x`` is
defined as ``log(exp(x[i])/sum(exp(x)))``.
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True then
the corresponding element in :attr:`input` tensor will be included in
log_softmax computation, otherwise the element is ignored.
The values of masked-out elements of the output tensor have undefined
value: it may or may not be set to zero or nan; the choice may correspond to
the value that leads to the most efficient storage of :attr:`output`
tensor.
The mask of the log_softmax output tensor can be computed as
``torch.broadcast_to(mask, input.shape)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int): the dimension along which log_softmax is computed.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
>>> input
tensor([[-3., -2., -1.],
[ 0., 1., 2.]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.log_softmax(input, 1, mask=mask)
tensor([[-2.1269, -inf, -0.1269],
[ nan, nan, nan]])
logaddexp(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, other: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, *, dtype: int | None = None, input_mask: torch.Tensor | None = None, other_mask: torch.Tensor | None = None) -> torch.Tensor
logaddexp(input, other, *, dtype=None, input_mask=None, other_mask=None) -> Tensor
Returns logaddexp of all the elements in the :attr:`input` and the :attr:`other`
tensor. The :attr:`input` elements are masked out according to the boolean tensor
:attr:`input_mask` and the attr:`other` elements are masked out according to the boolean tensor
:attr:`other_mask`.
The shapes of a mask tensor and the tensor to be masked
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the mask
tensor must not be greater than of the tensor to be masked.
Args:
input (Tensor): the input tensor
other (Tensor): the second input tensor
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the output tensor is
casted to :attr:`dtype` after the operation is
performed. Default: None.
input_mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of :attr:`input` tensor elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
other_mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of :attr:`other` tensor elements.
Default: None that is equivalent to ``torch.ones(other.shape, dtype=torch.bool)``.
Example::
>>> input = torch.tensor([-100.0, -200, -300])
>>> input
tensor([-100., -200., -300.])
>>> other = torch.tensor([-1.0, -2, -3])
>>> other
tensor([-1., -2., -3.])
>>> mask = torch.tensor([True, False, True])
>>> mask
tensor([ True, False, True])
>>> torch.masked._ops.logaddexp(input, other, input_mask=mask, other_mask=mask)
tensor([-1., -inf, -3.])
logsumexp(input: torch.Tensor, dim: tuple[int, ...] | None = None, *, keepdim: bool = False, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
logsumexp(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
Returns logsumexp of all the elements in the :attr:`input`
tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
elements are masked out according to the boolean tensor
:attr:`mask`.
The identity value of logsumexp operation, which is used to start the reduction, is ``-2147483648``.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
size 1. Otherwise, :attr:`dim` is squeezed (see
:func:`torch.squeeze`), resulting in the output tensor having 1 (or
``len(dim)``) fewer dimension(s).
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True
then the corresponding element in :attr:`input` tensor will be
included in logsumexp computation, otherwise the element is
ignored.
When all elements of :attr:`input` along the given dimension
:attr:`dim` are ignored (fully masked-out), the corresponding element
of the output tensor will have undefined value: it may or may not
correspond to the identity value of logsumexp operation; the
choice may correspond to the value that leads to the most efficient
storage of :attr:`output` tensor.
The mask of the output tensor can be computed as
``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
dtype=torch.bool)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
Default: None that is equivalent to ``tuple(range(input.ndim))``.
Keyword args:
keepdim (bool, optional): whether the output tensor has
:attr:`dim` retained or not. Default: False.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
>>> input
tensor([[-3, -2, -1],
[ 0, 1, 2]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.logsumexp(input, 1, mask=mask)
tensor([ 0, -9223372036854775808])
masked_tensor(data: object, mask: object, requires_grad: bool = False) -> torch.masked.maskedtensor.core.MaskedTensor
mean(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: tuple[int, ...] | None = None, *, keepdim: bool | None = False, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
mean(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
Returns mean of all the elements in the :attr:`input`
tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
elements are masked out according to the boolean tensor
:attr:`mask`.
By definition, the identity value of a mean operation is the mean
value of the tensor. If all elements of the input tensor along given
dimension(s) :attr:`dim` are masked-out, the identity value of the
mean is undefined. Due to this ambiguity, the elements of output
tensor with strided layout, that correspond to fully masked-out
elements, have ``nan`` values.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
size 1. Otherwise, :attr:`dim` is squeezed (see
:func:`torch.squeeze`), resulting in the output tensor having 1 (or
``len(dim)``) fewer dimension(s).
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True
then the corresponding element in :attr:`input` tensor will be
included in mean computation, otherwise the element is
ignored.
When all elements of :attr:`input` along the given dimension
:attr:`dim` are ignored (fully masked-out), the corresponding element
of the output tensor will have undefined value: it may or may not
correspond to the identity value of mean operation; the
choice may correspond to the value that leads to the most efficient
storage of :attr:`output` tensor.
The mask of the output tensor can be computed as
``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
dtype=torch.bool)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
Default: None that is equivalent to ``tuple(range(input.ndim))``.
Keyword args:
keepdim (bool, optional): whether the output tensor has
:attr:`dim` retained or not. Default: False.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
>>> input
tensor([[-3, -2, -1],
[ 0, 1, 2]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.mean(input, 1, mask=mask)
tensor([-2., nan])
median(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: int = -1, *, keepdim: bool = False, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
median(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
Returns median of all the elements in the :attr:`input`
tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
elements are masked out according to the boolean tensor
:attr:`mask`.
By definition, the identity value of a median operation is the median
value of the tensor. If all elements of the input tensor along given
dimension(s) :attr:`dim` are masked-out, the identity value of the
median is undefined. Due to this ambiguity, the elements of output
tensor with strided layout, that correspond to fully masked-out
elements, have ``nan`` values.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
size 1. Otherwise, :attr:`dim` is squeezed (see
:func:`torch.squeeze`), resulting in the output tensor having 1 (or
``len(dim)``) fewer dimension(s).
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True
then the corresponding element in :attr:`input` tensor will be
included in median computation, otherwise the element is
ignored.
When all elements of :attr:`input` along the given dimension
:attr:`dim` are ignored (fully masked-out), the corresponding element
of the output tensor will have undefined value: it may or may not
correspond to the identity value of median operation; the
choice may correspond to the value that leads to the most efficient
storage of :attr:`output` tensor.
The mask of the output tensor can be computed as
``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
dtype=torch.bool)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int): the dimension along which median is computed.
Keyword args:
keepdim (bool, optional): whether the output tensor has
:attr:`dim` retained or not. Default: False.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
>>> input
tensor([[-3., -2., -1.],
[ 0., 1., 2.]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.median(input, 1, mask=mask)
tensor([-3., nan])
norm(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, ord: float | None = 2.0, dim: tuple[int, ...] | None = None, *, keepdim: bool | None = False, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
norm(input, ord, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
Returns norm of all the elements in the :attr:`input`
tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
elements are masked out according to the boolean tensor
:attr:`mask`.
The identity value of norm operation, which is used to start the
reduction, is ``0.0``, except for ``ord=-inf`` it is
``inf``.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
size 1. Otherwise, :attr:`dim` is squeezed (see
:func:`torch.squeeze`), resulting in the output tensor having 1 (or
``len(dim)``) fewer dimension(s).
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True
then the corresponding element in :attr:`input` tensor will be
included in norm computation, otherwise the element is
ignored.
When all elements of :attr:`input` along the given dimension
:attr:`dim` are ignored (fully masked-out), the corresponding element
of the output tensor will have undefined value: it may or may not
correspond to the identity value of norm operation; the
choice may correspond to the value that leads to the most efficient
storage of :attr:`output` tensor.
The mask of the output tensor can be computed as
``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
dtype=torch.bool)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
ord (int, float, optional): the order of vector norm. Default: 2.
See :func:`torch.linalg.vector_norm` for a list of supported norms.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
Default: None that is equivalent to ``tuple(range(input.ndim))``.
Keyword args:
keepdim (bool, optional): whether the output tensor has
:attr:`dim` retained or not. Default: False.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
>>> input
tensor([[-3., -2., -1.],
[ 0., 1., 2.]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.norm(input, 2.0, 1, mask=mask)
tensor([3.1623, 0.0000])
normalize(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, ord: float, dim: int, *, eps: float = 1e-12, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
normalize(input, ord, dim, *, eps=1e-12, dtype=None, mask=None) -> Tensor
Returns normalize of all the slices in the :attr:`input` tensor
along :attr:`dim` while the :attr:`input` elements are masked out
according to the boolean tensor :attr:`mask`.
Let ``x`` be a sequence of unmasked elements of one-dimensional slice
of the :attr:`input` tensor. Normalize of i-th element in ``x`` is
defined as ``x[i]/max(norm(x, p), eps)``.
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True then
the corresponding element in :attr:`input` tensor will be included in
normalize computation, otherwise the element is ignored.
The values of masked-out elements of the output tensor have undefined
value: it may or may not be set to zero or nan; the choice may correspond to
the value that leads to the most efficient storage of :attr:`output`
tensor.
The mask of the normalize output tensor can be computed as
``torch.broadcast_to(mask, input.shape)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
ord (int, float): the order of vector norm. Default: 2.
See :func:`torch.linalg.vector_norm` for a list of supported norms.
dim (int): the dimension along which normalize is computed.
Keyword args:
eps (float, optional): small value to avoid division by zero. Default: 1e-12.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
>>> input
tensor([[-3., -2., -1.],
[ 0., 1., 2.]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.normalize(input, 2.0, 1, mask=mask)
tensor([[-0.9487, 0.0000, -0.3162],
[ 0.0000, 0.0000, 0.0000]])
prod(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: tuple[int, ...] | None = None, *, keepdim: bool | None = False, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
prod(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
Returns product of all the elements in the :attr:`input`
tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
elements are masked out according to the boolean tensor
:attr:`mask`.
The identity value of product operation, which is used to start the reduction, is ``1``.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
size 1. Otherwise, :attr:`dim` is squeezed (see
:func:`torch.squeeze`), resulting in the output tensor having 1 (or
``len(dim)``) fewer dimension(s).
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True
then the corresponding element in :attr:`input` tensor will be
included in product computation, otherwise the element is
ignored.
When all elements of :attr:`input` along the given dimension
:attr:`dim` are ignored (fully masked-out), the corresponding element
of the output tensor will have undefined value: it may or may not
correspond to the identity value of product operation; the
choice may correspond to the value that leads to the most efficient
storage of :attr:`output` tensor.
The mask of the output tensor can be computed as
``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
dtype=torch.bool)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
Default: None that is equivalent to ``tuple(range(input.ndim))``.
Keyword args:
keepdim (bool, optional): whether the output tensor has
:attr:`dim` retained or not. Default: False.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
>>> input
tensor([[-3, -2, -1],
[ 0, 1, 2]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.prod(input, 1, mask=mask)
tensor([3, 1])
softmax(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: int, *, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
softmax(input, dim, *, dtype=None, mask=None) -> Tensor
Returns softmax of all the slices in the :attr:`input` tensor
along :attr:`dim` while the :attr:`input` elements are masked out
according to the boolean tensor :attr:`mask`.
Let ``x`` be a sequence of unmasked elements of one-dimensional slice
of the :attr:`input` tensor. Softmax of i-th element in ``x`` is
defined as ``exp(x[i])/sum(exp(x))``.
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True then
the corresponding element in :attr:`input` tensor will be included in
softmax computation, otherwise the element is ignored.
The values of masked-out elements of the output tensor have undefined
value: it may or may not be set to zero or nan; the choice may correspond to
the value that leads to the most efficient storage of :attr:`output`
tensor.
The mask of the softmax output tensor can be computed as
``torch.broadcast_to(mask, input.shape)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int): the dimension along which softmax is computed.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
>>> input
tensor([[-3., -2., -1.],
[ 0., 1., 2.]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.softmax(input, 1, mask=mask)
tensor([[0.1192, 0.0000, 0.8808],
[ nan, nan, nan]])
softmin(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: int, *, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
softmin(input, dim, *, dtype=None, mask=None) -> Tensor
Returns softmin of all the slices in the :attr:`input` tensor
along :attr:`dim` while the :attr:`input` elements are masked out
according to the boolean tensor :attr:`mask`.
Let ``x`` be a sequence of unmasked elements of one-dimensional slice
of the :attr:`input` tensor. Softmin of i-th element in ``x`` is
defined as ``exp(-x[i])/sum(exp(-x))``.
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True then
the corresponding element in :attr:`input` tensor will be included in
softmin computation, otherwise the element is ignored.
The values of masked-out elements of the output tensor have undefined
value: it may or may not be set to zero or nan; the choice may correspond to
the value that leads to the most efficient storage of :attr:`output`
tensor.
The mask of the softmin output tensor can be computed as
``torch.broadcast_to(mask, input.shape)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int): the dimension along which softmin is computed.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3., -2., -1.], [ 0., 1., 2.]])
>>> input
tensor([[-3., -2., -1.],
[ 0., 1., 2.]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.softmin(input, 1, mask=mask)
tensor([[0.8808, 0.0000, 0.1192],
[ nan, nan, nan]])
std(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: tuple[int, ...] | None = None, unbiased: bool | None = None, *, correction: int | None = None, keepdim: bool | None = False, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
std(input, dim, unbiased, *, keepdim=False, dtype=None, mask=None) -> Tensor
Returns standard_deviation of all the elements in the :attr:`input`
tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
elements are masked out according to the boolean tensor
:attr:`mask`.
The identity value of sample standard deviation operation is undefined. The
elements of output tensor with strided layout, that correspond to
fully masked-out elements, have ``nan`` values.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
size 1. Otherwise, :attr:`dim` is squeezed (see
:func:`torch.squeeze`), resulting in the output tensor having 1 (or
``len(dim)``) fewer dimension(s).
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True
then the corresponding element in :attr:`input` tensor will be
included in standard_deviation computation, otherwise the element is
ignored.
When all elements of :attr:`input` along the given dimension
:attr:`dim` are ignored (fully masked-out), the corresponding element
of the output tensor will have undefined value: it may or may not
correspond to the identity value of standard_deviation operation; the
choice may correspond to the value that leads to the most efficient
storage of :attr:`output` tensor.
The mask of the output tensor can be computed as
``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
dtype=torch.bool)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
Default: None that is equivalent to ``tuple(range(input.ndim))``.
unbiased (bool): when True, use Bessel's correction, otherwise, compute
the uncorrected sample variance.
Keyword args:
keepdim (bool, optional): whether the output tensor has
:attr:`dim` retained or not. Default: False.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
>>> input
tensor([[-3, -2, -1],
[ 0, 1, 2]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.std(input, 1, False, mask=mask)
tensor([1., nan])
sum(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: tuple[int, ...] | None = None, *, keepdim: bool | None = False, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
sum(input, dim, *, keepdim=False, dtype=None, mask=None) -> Tensor
Returns sum of all the elements in the :attr:`input`
tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
elements are masked out according to the boolean tensor
:attr:`mask`.
The identity value of sum operation, which is used to start the reduction, is ``0``.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
size 1. Otherwise, :attr:`dim` is squeezed (see
:func:`torch.squeeze`), resulting in the output tensor having 1 (or
``len(dim)``) fewer dimension(s).
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True
then the corresponding element in :attr:`input` tensor will be
included in sum computation, otherwise the element is
ignored.
When all elements of :attr:`input` along the given dimension
:attr:`dim` are ignored (fully masked-out), the corresponding element
of the output tensor will have undefined value: it may or may not
correspond to the identity value of sum operation; the
choice may correspond to the value that leads to the most efficient
storage of :attr:`output` tensor.
The mask of the output tensor can be computed as
``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
dtype=torch.bool)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
Default: None that is equivalent to ``tuple(range(input.ndim))``.
Keyword args:
keepdim (bool, optional): whether the output tensor has
:attr:`dim` retained or not. Default: False.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
>>> input
tensor([[-3, -2, -1],
[ 0, 1, 2]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.sum(input, 1, mask=mask)
tensor([-4, 0])
var(input: torch.Tensor | torch.masked.maskedtensor.core.MaskedTensor, dim: tuple[int, ...] | None = None, unbiased: bool | None = None, *, correction: int | float | None = None, keepdim: bool | None = False, dtype: int | None = None, mask: torch.Tensor | None = None) -> torch.Tensor
var(input, dim, unbiased, *, keepdim=False, dtype=None, mask=None) -> Tensor
Returns variance of all the elements in the :attr:`input`
tensor along the given dimension(s) :attr:`dim` while the :attr:`input`
elements are masked out according to the boolean tensor
:attr:`mask`.
The identity value of sample variance operation is undefined. The
elements of output tensor with strided layout, that correspond to
fully masked-out elements, have ``nan`` values.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of
size 1. Otherwise, :attr:`dim` is squeezed (see
:func:`torch.squeeze`), resulting in the output tensor having 1 (or
``len(dim)``) fewer dimension(s).
The boolean tensor :attr:`mask` defines the "validity" of
:attr:`input` tensor elements: if :attr:`mask` element is True
then the corresponding element in :attr:`input` tensor will be
included in variance computation, otherwise the element is
ignored.
When all elements of :attr:`input` along the given dimension
:attr:`dim` are ignored (fully masked-out), the corresponding element
of the output tensor will have undefined value: it may or may not
correspond to the identity value of variance operation; the
choice may correspond to the value that leads to the most efficient
storage of :attr:`output` tensor.
The mask of the output tensor can be computed as
``torch.any(torch.broadcast_to(mask, input.shape), dim, keepdim=keepdim,
dtype=torch.bool)``.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor
don't need to match, but they must be :ref:`broadcastable
<broadcasting-semantics>` and the dimensionality of the :attr:`mask`
tensor must not be greater than of the :attr:`input` tensor.
Args:
input (Tensor): the input tensor
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
Default: None that is equivalent to ``tuple(range(input.ndim))``.
unbiased (bool): when True, use Bessel's correction, otherwise, compute
the uncorrected sample variance.
Keyword args:
keepdim (bool, optional): whether the output tensor has
:attr:`dim` retained or not. Default: False.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. Default: None.
mask (:class:`torch.Tensor`, optional): the boolean tensor
containing the binary mask of validity of input tensor
elements.
Default: None that is equivalent to ``torch.ones(input.shape, dtype=torch.bool)``.
Example::
>>> input = tensor([[-3, -2, -1], [ 0, 1, 2]])
>>> input
tensor([[-3, -2, -1],
[ 0, 1, 2]])
>>> mask = tensor([[ True, False, True], [False, False, False]])
>>> mask
tensor([[ True, False, True],
[False, False, False]])
>>> torch.masked._ops.var(input, 1, False, mask=mask)
tensor([1., nan])
DATA
__all__ = ['amax', 'amin', 'argmax', 'argmin', 'as_masked_tensor', 'cu...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\masked\__init__.py
torch.masked_fill
Python Library Documentation: built-in function masked_fill in module torch masked_fill(...)
torch.masked_scatter
Python Library Documentation: built-in function masked_scatter in module torch masked_scatter(...)
torch.masked_select
Python Library Documentation: built-in function masked_select in module torch
masked_select(...)
masked_select(input, mask, *, out=None) -> Tensor
Returns a new 1-D tensor which indexes the :attr:`input` tensor according to
the boolean mask :attr:`mask` which is a `BoolTensor`.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor don't need
to match, but they must be :ref:`broadcastable <broadcasting-semantics>`.
.. note:: The returned tensor does **not** use the same storage
as the original tensor
Args:
input (Tensor): the input tensor.
mask (BoolTensor): the tensor containing the binary mask to index with
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.randn(3, 4)
>>> x
tensor([[ 0.3552, -2.3825, -0.8297, 0.3477],
[-1.2035, 1.2252, 0.5002, 0.6248],
[ 0.1307, -2.0608, 0.1244, 2.0139]])
>>> mask = x.ge(0.5)
>>> mask
tensor([[False, False, False, False],
[False, True, True, True],
[False, False, False, True]])
>>> torch.masked_select(x, mask)
tensor([ 1.2252, 0.5002, 0.6248, 2.0139])
torch.math
Python Library Documentation: built-in module math
NAME
math
DESCRIPTION
This module provides access to the mathematical functions
defined by the C standard.
FUNCTIONS
acos(x, /)
Return the arc cosine (measured in radians) of x.
The result is between 0 and pi.
acosh(x, /)
Return the inverse hyperbolic cosine of x.
asin(x, /)
Return the arc sine (measured in radians) of x.
The result is between -pi/2 and pi/2.
asinh(x, /)
Return the inverse hyperbolic sine of x.
atan(x, /)
Return the arc tangent (measured in radians) of x.
The result is between -pi/2 and pi/2.
atan2(y, x, /)
Return the arc tangent (measured in radians) of y/x.
Unlike atan(y/x), the signs of both x and y are considered.
atanh(x, /)
Return the inverse hyperbolic tangent of x.
cbrt(x, /)
Return the cube root of x.
ceil(x, /)
Return the ceiling of x as an Integral.
This is the smallest integer >= x.
comb(n, k, /)
Number of ways to choose k items from n items without repetition and without order.
Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates
to zero when k > n.
Also called the binomial coefficient because it is equivalent
to the coefficient of k-th term in polynomial expansion of the
expression (1 + x)**n.
Raises TypeError if either of the arguments are not integers.
Raises ValueError if either of the arguments are negative.
copysign(x, y, /)
Return a float with the magnitude (absolute value) of x but the sign of y.
On platforms that support signed zeros, copysign(1.0, -0.0)
returns -1.0.
cos(x, /)
Return the cosine of x (measured in radians).
cosh(x, /)
Return the hyperbolic cosine of x.
degrees(x, /)
Convert angle x from radians to degrees.
dist(p, q, /)
Return the Euclidean distance between two points p and q.
The points should be specified as sequences (or iterables) of
coordinates. Both inputs must have the same dimension.
Roughly equivalent to:
sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))
erf(x, /)
Error function at x.
erfc(x, /)
Complementary error function at x.
exp(x, /)
Return e raised to the power of x.
exp2(x, /)
Return 2 raised to the power of x.
expm1(x, /)
Return exp(x)-1.
This function avoids the loss of precision involved in the direct evaluation of exp(x)-1 for small x.
fabs(x, /)
Return the absolute value of the float x.
factorial(n, /)
Find n!.
Raise a ValueError if x is negative or non-integral.
floor(x, /)
Return the floor of x as an Integral.
This is the largest integer <= x.
fmod(x, y, /)
Return fmod(x, y), according to platform C.
x % y may differ.
frexp(x, /)
Return the mantissa and exponent of x, as pair (m, e).
m is a float and e is an int, such that x = m * 2.**e.
If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.
fsum(seq, /)
Return an accurate floating-point sum of values in the iterable seq.
Assumes IEEE-754 floating-point arithmetic.
gamma(x, /)
Gamma function at x.
gcd(*integers)
Greatest Common Divisor.
hypot(...)
hypot(*coordinates) -> value
Multidimensional Euclidean distance from the origin to a point.
Roughly equivalent to:
sqrt(sum(x**2 for x in coordinates))
For a two dimensional point (x, y), gives the hypotenuse
using the Pythagorean theorem: sqrt(x*x + y*y).
For example, the hypotenuse of a 3/4/5 right triangle is:
>>> hypot(3.0, 4.0)
5.0
isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)
Determine whether two floating-point numbers are close in value.
rel_tol
maximum difference for being considered "close", relative to the
magnitude of the input values
abs_tol
maximum difference for being considered "close", regardless of the
magnitude of the input values
Return True if a is close in value to b, and False otherwise.
For the values to be considered close, the difference between them
must be smaller than at least one of the tolerances.
-inf, inf and NaN behave similarly to the IEEE 754 Standard. That
is, NaN is not close to anything, even itself. inf and -inf are
only close to themselves.
isfinite(x, /)
Return True if x is neither an infinity nor a NaN, and False otherwise.
isinf(x, /)
Return True if x is a positive or negative infinity, and False otherwise.
isnan(x, /)
Return True if x is a NaN (not a number), and False otherwise.
isqrt(n, /)
Return the integer part of the square root of the input.
lcm(*integers)
Least Common Multiple.
ldexp(x, i, /)
Return x * (2**i).
This is essentially the inverse of frexp().
lgamma(x, /)
Natural logarithm of absolute value of Gamma function at x.
log(...)
log(x, [base=math.e])
Return the logarithm of x to the given base.
If the base is not specified, returns the natural logarithm (base e) of x.
log10(x, /)
Return the base 10 logarithm of x.
log1p(x, /)
Return the natural logarithm of 1+x (base e).
The result is computed in a way which is accurate for x near zero.
log2(x, /)
Return the base 2 logarithm of x.
modf(x, /)
Return the fractional and integer parts of x.
Both results carry the sign of x and are floats.
nextafter(x, y, /, *, steps=None)
Return the floating-point value the given number of steps after x towards y.
If steps is not specified or is None, it defaults to 1.
Raises a TypeError, if x or y is not a double, or if steps is not an integer.
Raises ValueError if steps is negative.
perm(n, k=None, /)
Number of ways to choose k items from n items without repetition and with order.
Evaluates to n! / (n - k)! when k <= n and evaluates
to zero when k > n.
If k is not specified or is None, then k defaults to n
and the function returns n!.
Raises TypeError if either of the arguments are not integers.
Raises ValueError if either of the arguments are negative.
pow(x, y, /)
Return x**y (x to the power of y).
prod(iterable, /, *, start=1)
Calculate the product of all the elements in the input iterable.
The default start value for the product is 1.
When the iterable is empty, return the start value. This function is
intended specifically for use with numeric values and may reject
non-numeric types.
radians(x, /)
Convert angle x from degrees to radians.
remainder(x, y, /)
Difference between x and the closest integer multiple of y.
Return x - n*y where n*y is the closest integer multiple of y.
In the case where x is exactly halfway between two multiples of
y, the nearest even value of n is used. The result is always exact.
sin(x, /)
Return the sine of x (measured in radians).
sinh(x, /)
Return the hyperbolic sine of x.
sqrt(x, /)
Return the square root of x.
sumprod(p, q, /)
Return the sum of products of values from two iterables p and q.
Roughly equivalent to:
sum(itertools.starmap(operator.mul, zip(p, q, strict=True)))
For float and mixed int/float inputs, the intermediate products
and sums are computed with extended precision.
tan(x, /)
Return the tangent of x (measured in radians).
tanh(x, /)
Return the hyperbolic tangent of x.
trunc(x, /)
Truncates the Real x to the nearest Integral toward 0.
Uses the __trunc__ magic method.
ulp(x, /)
Return the value of the least significant bit of the float x.
DATA
e = 2.718281828459045
inf = inf
nan = nan
pi = 3.141592653589793
tau = 6.283185307179586
FILE
(built-in)
torch.matmul
Python Library Documentation: built-in function matmul in module torch
matmul(...)
matmul(input, other, *, out=None) -> Tensor
Matrix product of two tensors.
The behavior depends on the dimensionality of the tensors as follows:
- If both tensors are 1-dimensional, the dot product (scalar) is returned.
- If both arguments are 2-dimensional, the matrix-matrix product is returned.
- If the first argument is 1-dimensional and the second argument is 2-dimensional,
a 1 is prepended to its dimension for the purpose of the matrix multiply.
After the matrix multiply, the prepended dimension is removed.
- If the first argument is 2-dimensional and the second argument is 1-dimensional,
the matrix-vector product is returned.
- If both arguments are at least 1-dimensional and at least one argument is
N-dimensional (where N > 2), then a batched matrix multiply is returned. If the first
argument is 1-dimensional, a 1 is prepended to its dimension for the purpose of the
batched matrix multiply and removed after. If the second argument is 1-dimensional, a
1 is appended to its dimension for the purpose of the batched matrix multiply and removed after.
The first N-2 dimensions of each argument, the batch dimensions, are
:ref:`broadcast <broadcasting-semantics>` (and thus must be broadcastable).
The last 2, the matrix dimensions, are handled as in the matrix-matrix product.
For example, if :attr:`input` is a
:math:`(j \times 1 \times n \times m)` tensor and :attr:`other` is a :math:`(k \times m \times p)`
tensor, the batch dimensions are :math:`(j \times 1)` and :math:`(k)`,
and the matrix dimensions are :math:`(n \times m)` and :math:`(m \times p)`.
:attr:`out` will be a :math:`(j \times k \times n \times p)` tensor.
This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. In particular the
matrix-matrix (both arguments 2-dimensional) supports sparse arguments with the same restrictions
as :func:`torch.mm`
.. warning::
Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
or may not have autograd support. If you notice missing functionality please
open a feature request.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
.. note::
The 1-dimensional dot product version of this function does not support an :attr:`out` parameter.
Arguments:
input (Tensor): the first tensor to be multiplied
other (Tensor): the second tensor to be multiplied
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> # vector x vector
>>> tensor1 = torch.randn(3)
>>> tensor2 = torch.randn(3)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([])
>>> # matrix x vector
>>> tensor1 = torch.randn(3, 4)
>>> tensor2 = torch.randn(4)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([3])
>>> # batched matrix x broadcasted vector
>>> tensor1 = torch.randn(10, 3, 4)
>>> tensor2 = torch.randn(4)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([10, 3])
>>> # batched matrix x batched matrix
>>> tensor1 = torch.randn(10, 3, 4)
>>> tensor2 = torch.randn(10, 4, 5)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([10, 3, 5])
>>> # batched matrix x broadcasted matrix
>>> tensor1 = torch.randn(10, 3, 4)
>>> tensor2 = torch.randn(4, 5)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([10, 3, 5])
torch.matrix_exp
Python Library Documentation: built-in function matrix_exp in module torch
matrix_exp(...)
matrix_exp(A) -> Tensor
Alias for :func:`torch.linalg.matrix_exp`.
torch.matrix_power
Python Library Documentation: built-in function matrix_power in module torch
matrix_power(...)
matrix_power(input, n, *, out=None) -> Tensor
Alias for :func:`torch.linalg.matrix_power`
torch.matrix_rank
Python Library Documentation: function matrix_rank in module torch._linalg_utils
matrix_rank(input, tol=None, symmetric=False, *, out=None) -> torch.Tensor
# These functions were deprecated and removed
# This nice error message can be removed in version 1.13+
torch.max
Python Library Documentation: built-in function max in module torch
max(...)
max(input, *, out=None) -> Tensor
Returns the maximum value of all elements in the ``input`` tensor.
.. note::
The difference between ``max``/``min`` and ``amax``/``amin`` is:
- ``amax``/``amin`` supports reducing on multiple dimensions,
- ``amax``/``amin`` does not return indices.
Both ``amax``/``amin`` evenly distribute gradients between equal values
when there are multiple input elements with the same minimum or maximum value.
For ``max``/``min``:
- If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
- If reduce over one specified axis, only propagate to the indexed element.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.6763, 0.7445, -2.2369]])
>>> torch.max(a)
tensor(0.7445)
.. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
:noindex:
Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
value of each row of the :attr:`input` tensor in the given dimension
:attr:`dim`. And ``indices`` is the index location of each maximum value found
(argmax).
If ``keepdim`` is ``True``, the output tensors are of the same size
as ``input`` except in the dimension ``dim`` where they are of size 1.
Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
in the output tensors having 1 fewer dimension than ``input``.
.. note:: If there are multiple maximal values in a reduced row then
the indices of the first maximal value are returned.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (tuple, optional): the result tuple of two output tensors (max, max_indices)
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
[ 1.1949, -1.1127, -2.2379, -0.6702],
[ 1.5717, -0.9207, 0.1297, -1.8768],
[-0.6172, 1.0036, -0.6060, -0.2432]])
>>> torch.max(a, 1)
torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
>>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
>>> a.max(dim=1, keepdim=True)
torch.return_types.max(
values=tensor([[2.], [4.]]),
indices=tensor([[1], [1]]))
>>> a.max(dim=1, keepdim=False)
torch.return_types.max(
values=tensor([2., 4.]),
indices=tensor([1, 1]))
.. function:: max(input, other, *, out=None) -> Tensor
:noindex:
See :func:`torch.maximum`.
torch.max_pool1d
Python Library Documentation: built-in function max_pool1d in module torch max_pool1d(...)
torch.max_pool1d_with_indices
Python Library Documentation: built-in function max_pool1d_with_indices in module torch max_pool1d_with_indices(...)
torch.max_pool2d
Python Library Documentation: built-in function max_pool2d in module torch max_pool2d(...)
torch.max_pool3d
Python Library Documentation: built-in function max_pool3d in module torch max_pool3d(...)
torch.maximum
Python Library Documentation: built-in function maximum in module torch
maximum(...)
maximum(input, other, *, out=None) -> Tensor
Computes the element-wise maximum of :attr:`input` and :attr:`other`.
.. note::
If one of the elements being compared is a NaN, then that element is returned.
:func:`maximum` is not supported for tensors with complex dtypes.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor((1, 2, -1))
>>> b = torch.tensor((3, 0, 4))
>>> torch.maximum(a, b)
tensor([3, 2, 4])
torch.mean
Python Library Documentation: built-in function mean in module torch
mean(...)
mean(input, *, dtype=None) -> Tensor
.. note::
If the `input` tensor is empty, ``torch.mean()`` returns ``nan``.
This behavior is consistent with NumPy and follows the definition
that the mean over an empty set is undefined.
Returns the mean value of all elements in the :attr:`input` tensor. Input must be floating point or complex.
Args:
input (Tensor):
the input tensor, either of floating point or complex dtype
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.2294, -0.5481, 1.3288]])
>>> torch.mean(a)
tensor(0.3367)
.. function:: mean(input, dim, keepdim=False, *, dtype=None, out=None) -> Tensor
:noindex:
Returns the mean value of each row of the :attr:`input` tensor in the given
dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
reduce over all of them.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
out (Tensor, optional): the output tensor.
.. seealso::
:func:`torch.nanmean` computes the mean value of `non-NaN` elements.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[-0.3841, 0.6320, 0.4254, -0.7384],
[-0.9644, 1.0131, -0.6549, -1.4279],
[-0.2951, -1.3350, -0.7694, 0.5600],
[ 1.0842, -0.9580, 0.3623, 0.2343]])
>>> torch.mean(a, 1)
tensor([-0.0163, -0.5085, -0.4599, 0.1807])
>>> torch.mean(a, 1, True)
tensor([[-0.0163],
[-0.5085],
[-0.4599],
[ 0.1807]])
torch.median
Python Library Documentation: built-in function median in module torch
median(...)
median(input) -> Tensor
Returns the median of the values in :attr:`input`.
.. note::
The median is not unique for :attr:`input` tensors with an even number
of elements. In this case the lower of the two medians is returned. To
compute the mean of both medians, use :func:`torch.quantile` with ``q=0.5`` instead.
.. warning::
This function produces deterministic (sub)gradients unlike ``median(dim=0)``
Args:
input (Tensor): the input tensor.
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 1.5219, -1.5212, 0.2202]])
>>> torch.median(a)
tensor(0.2202)
.. function:: median(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
:noindex:
Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
in the dimension :attr:`dim`, and ``indices`` contains the index of the median values found in the dimension :attr:`dim`.
By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
If :attr:`keepdim` is ``True``, the output tensors are of the same size
as :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
the outputs tensor having 1 fewer dimension than :attr:`input`.
.. note::
The median is not unique for :attr:`input` tensors with an even number
of elements in the dimension :attr:`dim`. In this case the lower of the
two medians is returned. To compute the mean of both medians in
:attr:`input`, use :func:`torch.quantile` with ``q=0.5`` instead.
.. warning::
``indices`` does not necessarily contain the first occurrence of each
median value found, unless it is unique.
The exact implementation details are device-specific.
Do not expect the same result when run on CPU and GPU in general.
For the same reason do not expect the gradients to be deterministic.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
tensor, which must have dtype long, with their indices in the dimension
:attr:`dim` of :attr:`input`.
Example::
>>> a = torch.randn(4, 5)
>>> a
tensor([[ 0.2505, -0.3982, -0.9948, 0.3518, -1.3131],
[ 0.3180, -0.6993, 1.0436, 0.0438, 0.2270],
[-0.2751, 0.7303, 0.2192, 0.3321, 0.2488],
[ 1.0778, -1.9510, 0.7048, 0.4742, -0.7125]])
>>> torch.median(a, 1)
torch.return_types.median(values=tensor([-0.3982, 0.2270, 0.2488, 0.4742]), indices=tensor([1, 4, 4, 3]))
torch.memory_format
Python Library Documentation: class memory_format in module torch class memory_format(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self).
torch.merge_type_from_type_comment
Python Library Documentation: built-in function merge_type_from_type_comment in module torch
merge_type_from_type_comment(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
merge_type_from_type_comment(arg0: torch._C._jit_tree_views.Decl, arg1: torch._C._jit_tree_views.Decl, arg2: bool) -> torch._C._jit_tree_views.Decl
torch.meshgrid
Python Library Documentation: function meshgrid in module torch.functional
meshgrid(*tensors, indexing: str | None = None) -> tuple[torch.Tensor, ...]
Creates grids of coordinates specified by the 1D inputs in `attr`:tensors.
This is helpful when you want to visualize data over some
range of inputs. See below for a plotting example.
Given :math:`N` 1D tensors :math:`T_0 \ldots T_{N-1}` as
inputs with corresponding sizes :math:`S_0 \ldots S_{N-1}`,
this creates :math:`N` N-dimensional tensors :math:`G_0 \ldots
G_{N-1}`, each with shape :math:`(S_0, ..., S_{N-1})` where
the output :math:`G_i` is constructed by expanding :math:`T_i`
to the result shape.
.. note::
0D inputs are treated equivalently to 1D inputs of a
single element.
.. warning::
`torch.meshgrid(*tensors)` currently has the same behavior
as calling `numpy.meshgrid(*arrays, indexing='ij')`.
In the future `torch.meshgrid` will transition to
`indexing='xy'` as the default.
https://github.com/pytorch/pytorch/issues/50276 tracks
this issue with the goal of migrating to NumPy's behavior.
.. seealso::
:func:`torch.cartesian_prod` has the same effect but it
collects the data in a tensor of vectors.
Args:
tensors (list of Tensor): list of scalars or 1 dimensional tensors. Scalars will be
treated as tensors of size :math:`(1,)` automatically
indexing: (str, optional): the indexing mode, either "xy"
or "ij", defaults to "ij". See warning for future changes.
If "xy" is selected, the first dimension corresponds
to the cardinality of the second input and the second
dimension corresponds to the cardinality of the first
input.
If "ij" is selected, the dimensions are in the same
order as the cardinality of the inputs.
Returns:
seq (sequence of Tensors): If the input has :math:`N`
tensors of size :math:`S_0 \ldots S_{N-1}``, then the
output will also have :math:`N` tensors, where each tensor
is of shape :math:`(S_0, ..., S_{N-1})`.
Example::
>>> x = torch.tensor([1, 2, 3])
>>> y = torch.tensor([4, 5, 6])
Observe the element-wise pairings across the grid, (1, 4),
(1, 5), ..., (3, 6). This is the same thing as the
cartesian product.
>>> grid_x, grid_y = torch.meshgrid(x, y, indexing='ij')
>>> grid_x
tensor([[1, 1, 1],
[2, 2, 2],
[3, 3, 3]])
>>> grid_y
tensor([[4, 5, 6],
[4, 5, 6],
[4, 5, 6]])
This correspondence can be seen when these grids are
stacked properly.
>>> torch.equal(torch.cat(tuple(torch.dstack([grid_x, grid_y]))),
... torch.cartesian_prod(x, y))
True
`torch.meshgrid` is commonly used to produce a grid for
plotting.
>>> # xdoctest: +REQUIRES(module:matplotlib)
>>> # xdoctest: +REQUIRES(env:DOCTEST_SHOW)
>>> import matplotlib.pyplot as plt
>>> xs = torch.linspace(-5, 5, steps=100)
>>> ys = torch.linspace(-5, 5, steps=100)
>>> x, y = torch.meshgrid(xs, ys, indexing='xy')
>>> z = torch.sin(torch.sqrt(x * x + y * y))
>>> ax = plt.axes(projection='3d')
>>> ax.plot_surface(x.numpy(), y.numpy(), z.numpy())
>>> plt.show()
.. image:: ../_static/img/meshgrid.png
:width: 512
torch.min
Python Library Documentation: built-in function min in module torch
min(...)
min(input, *, out=None) -> Tensor
Returns the minimum value of all elements in the :attr:`input` tensor.
.. note::
The difference between ``max``/``min`` and ``amax``/``amin`` is:
- ``amax``/``amin`` supports reducing on multiple dimensions,
- ``amax``/``amin`` does not return indices.
Both ``amax``/``amin`` evenly distribute gradients between equal values
when there are multiple input elements with the same minimum or maximum value.
For ``max``/``min``:
- If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
- If reduce over one specified axis, only propagate to the indexed element.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.6750, 1.0857, 1.7197]])
>>> torch.min(a)
tensor(0.6750)
.. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
:noindex:
Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
value of each row of the :attr:`input` tensor in the given dimension
:attr:`dim`. And ``indices`` is the index location of each minimum value found
(argmin).
If :attr:`keepdim` is ``True``, the output tensors are of the same size as
:attr:`input` except in the dimension :attr:`dim` where they are of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
the output tensors having 1 fewer dimension than :attr:`input`.
.. note:: If there are multiple minimal values in a reduced row then
the indices of the first minimal value are returned.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (tuple, optional): the tuple of two output tensors (min, min_indices)
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
[-1.4644, -0.2635, -0.3651, 0.6134],
[ 0.2457, 0.0384, 1.0128, 0.7015],
[-0.1153, 2.9849, 2.1458, 0.5788]])
>>> torch.min(a, 1)
torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
.. function:: min(input, other, *, out=None) -> Tensor
:noindex:
See :func:`torch.minimum`.
torch.minimum
Python Library Documentation: built-in function minimum in module torch
minimum(...)
minimum(input, other, *, out=None) -> Tensor
Computes the element-wise minimum of :attr:`input` and :attr:`other`.
.. note::
If one of the elements being compared is a NaN, then that element is returned.
:func:`minimum` is not supported for tensors with complex dtypes.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor((1, 2, -1))
>>> b = torch.tensor((3, 0, 4))
>>> torch.minimum(a, b)
tensor([1, 0, -1])
torch.miopen_batch_norm
Python Library Documentation: built-in function miopen_batch_norm in module torch miopen_batch_norm(...)
torch.miopen_convolution
Python Library Documentation: built-in function miopen_convolution in module torch miopen_convolution(...)
torch.miopen_convolution_add_relu
Python Library Documentation: built-in function miopen_convolution_add_relu in module torch miopen_convolution_add_relu(...)
torch.miopen_convolution_relu
Python Library Documentation: built-in function miopen_convolution_relu in module torch miopen_convolution_relu(...)
torch.miopen_convolution_transpose
Python Library Documentation: built-in function miopen_convolution_transpose in module torch miopen_convolution_transpose(...)
torch.miopen_ctc_loss
Python Library Documentation: built-in function miopen_ctc_loss in module torch miopen_ctc_loss(...)
torch.miopen_depthwise_convolution
Python Library Documentation: built-in function miopen_depthwise_convolution in module torch miopen_depthwise_convolution(...)
torch.miopen_rnn
Python Library Documentation: built-in function miopen_rnn in module torch miopen_rnn(...)
torch.mkldnn_adaptive_avg_pool2d
Python Library Documentation: built-in function mkldnn_adaptive_avg_pool2d in module torch mkldnn_adaptive_avg_pool2d(...)
torch.mkldnn_convolution
Python Library Documentation: built-in function mkldnn_convolution in module torch mkldnn_convolution(...)
torch.mkldnn_linear_backward_weights
Python Library Documentation: built-in function mkldnn_linear_backward_weights in module torch mkldnn_linear_backward_weights(...)
torch.mkldnn_max_pool2d
Python Library Documentation: built-in function mkldnn_max_pool2d in module torch mkldnn_max_pool2d(...)
torch.mkldnn_max_pool3d
Python Library Documentation: built-in function mkldnn_max_pool3d in module torch mkldnn_max_pool3d(...)
torch.mkldnn_rnn_layer
Python Library Documentation: built-in function mkldnn_rnn_layer in module torch mkldnn_rnn_layer(...)
torch.mm
Python Library Documentation: built-in function mm in module torch
mm(...)
mm(input, mat2, *, out=None) -> Tensor
Performs a matrix multiplication of the matrices :attr:`input` and :attr:`mat2`.
If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
:math:`(m \times p)` tensor, :attr:`out` will be a :math:`(n \times p)` tensor.
.. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
For broadcasting matrix products, see :func:`torch.matmul`.
Supports strided and sparse 2-D tensors as inputs, autograd with
respect to strided inputs.
This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`.
If :attr:`out` is provided its layout will be used. Otherwise, the result
layout will be deduced from that of :attr:`input`.
.. warning::
Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
or may not have autograd support. If you notice missing functionality please
open a feature request.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
Args:
input (Tensor): the first matrix to be matrix multiplied
mat2 (Tensor): the second matrix to be matrix multiplied
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> mat1 = torch.randn(2, 3)
>>> mat2 = torch.randn(3, 3)
>>> torch.mm(mat1, mat2)
tensor([[ 0.4851, 0.5037, -0.3633],
[-0.0760, -3.6705, 2.4784]])
.. function:: mm(input, mat2, out_dtype, *, out=None) -> Tensor
:noindex:
Args:
input (Tensor): the first matrix to be matrix multiplied
mat2 (Tensor): the second matrix to be matrix multiplied
out_dtype (dtype): the dtype of the output tensor.
Supported only on CUDA and for torch.float32 given
torch.float16/torch.bfloat16 input dtypes.
Keyword args:
out (Tensor, optional): the output tensor.
torch.mode
Python Library Documentation: built-in function mode in module torch
mode(...)
mode(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
Returns a namedtuple ``(values, indices)`` where ``values`` is the mode
value of each row of the :attr:`input` tensor in the given dimension
:attr:`dim`, i.e. a value which appears most often
in that row, and ``indices`` is the index location of each mode value found.
By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
If :attr:`keepdim` is ``True``, the output tensors are of the same size as
:attr:`input` except in the dimension :attr:`dim` where they are of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting
in the output tensors having 1 fewer dimension than :attr:`input`.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (tuple, optional): the result tuple of two output tensors (values, indices)
Example::
>>> b = torch.tensor([[0, 0, 0, 2, 0, 0, 2],
... [0, 3, 0, 0, 2, 0, 1],
... [2, 2, 2, 0, 0, 0, 3],
... [2, 2, 3, 0, 1, 1, 0],
... [1, 1, 0, 0, 2, 0, 2]])
>>> torch.mode(b, 0)
torch.return_types.mode(
values=tensor([0, 2, 0, 0, 0, 0, 2]),
indices=tensor([1, 3, 4, 4, 2, 4, 4]))
torch.monitor
Python Library Documentation: package torch.monitor in torch
NAME
torch.monitor
PACKAGE CONTENTS
CLASSES
builtins.object
TensorboardEventHandler
class TensorboardEventHandler(builtins.object)
| TensorboardEventHandler(writer: 'SummaryWriter') -> None
|
| TensorboardEventHandler is an event handler that will write known events to
| the provided SummaryWriter.
|
| This currently only supports ``torch.monitor.Stat`` events which are logged
| as scalars.
|
| Example:
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_MONITOR)
| >>> # xdoctest: +REQUIRES(module:tensorboard)
| >>> from torch.utils.tensorboard import SummaryWriter
| >>> from torch.monitor import TensorboardEventHandler, register_event_handler
| >>> writer = SummaryWriter("log_dir")
| >>> register_event_handler(TensorboardEventHandler(writer))
|
| Methods defined here:
|
| __call__(self, event: torch._C._monitor.Event) -> None
| Call self as a function.
|
| __init__(self, writer: 'SummaryWriter') -> None
| Constructs the ``TensorboardEventHandler``.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
log_event(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
log_event(event: torch._C._monitor.Event) -> None
log_event logs the specified event to all of the registered event
handlers. It's up to the event handlers to log the event out to the
corresponding event sink.
If there are no event handlers registered this method is a no-op.
register_event_handler(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
register_event_handler(callback: collections.abc.Callable[[torch._C._monitor.Event], None]) -> torch._C._monitor.EventHandlerHandle
register_event_handler registers a callback to be called whenever an
event is logged via ``log_event``. These handlers should avoid blocking
the main thread since that may interfere with training as they run
during the ``log_event`` call.
unregister_event_handler(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
unregister_event_handler(handler: torch._C._monitor.EventHandlerHandle) -> None
unregister_event_handler unregisters the ``EventHandlerHandle`` returned
after calling ``register_event_handler``. After this returns the event
handler will no longer receive events.
DATA
COUNT = <Aggregation.COUNT: 3>
MAX = <Aggregation.MAX: 5>
MEAN = <Aggregation.MEAN: 2>
MIN = <Aggregation.MIN: 6>
STAT_EVENT = 'torch.monitor.Stat'
SUM = <Aggregation.SUM: 4>
TYPE_CHECKING = False
VALUE = <Aggregation.VALUE: 0>
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\monitor\__init__.py
torch.moveaxis
Python Library Documentation: built-in function moveaxis in module torch
moveaxis(...)
moveaxis(input, source, destination) -> Tensor
Alias for :func:`torch.movedim`.
This function is equivalent to NumPy's moveaxis function.
Examples::
>>> t = torch.randn(3,2,1)
>>> t
tensor([[[-0.3362],
[-0.8437]],
[[-0.9627],
[ 0.1727]],
[[ 0.5173],
[-0.1398]]])
>>> torch.moveaxis(t, 1, 0).shape
torch.Size([2, 3, 1])
>>> torch.moveaxis(t, 1, 0)
tensor([[[-0.3362],
[-0.9627],
[ 0.5173]],
[[-0.8437],
[ 0.1727],
[-0.1398]]])
>>> torch.moveaxis(t, (1, 2), (0, 1)).shape
torch.Size([2, 1, 3])
>>> torch.moveaxis(t, (1, 2), (0, 1))
tensor([[[-0.3362, -0.9627, 0.5173]],
[[-0.8437, 0.1727, -0.1398]]])
torch.movedim
Python Library Documentation: built-in function movedim in module torch
movedim(...)
movedim(input, source, destination) -> Tensor
Moves the dimension(s) of :attr:`input` at the position(s) in :attr:`source`
to the position(s) in :attr:`destination`.
Other dimensions of :attr:`input` that are not explicitly moved remain in
their original order and appear at the positions not specified in :attr:`destination`.
Args:
input (Tensor): the input tensor.
source (int or tuple of ints): Original positions of the dims to move. These must be unique.
destination (int or tuple of ints): Destination positions for each of the original dims. These must also be unique.
Examples::
>>> t = torch.randn(3,2,1)
>>> t
tensor([[[-0.3362],
[-0.8437]],
[[-0.9627],
[ 0.1727]],
[[ 0.5173],
[-0.1398]]])
>>> torch.movedim(t, 1, 0).shape
torch.Size([2, 3, 1])
>>> torch.movedim(t, 1, 0)
tensor([[[-0.3362],
[-0.9627],
[ 0.5173]],
[[-0.8437],
[ 0.1727],
[-0.1398]]])
>>> torch.movedim(t, (1, 2), (0, 1)).shape
torch.Size([2, 1, 3])
>>> torch.movedim(t, (1, 2), (0, 1))
tensor([[[-0.3362, -0.9627, 0.5173]],
[[-0.8437, 0.1727, -0.1398]]])
torch.mps
Python Library Documentation: package torch.mps in torch
NAME
torch.mps
DESCRIPTION
This package enables an interface for accessing MPS (Metal Performance Shaders) backend in Python.
Metal is Apple's API for programming metal GPU (graphics processor unit). Using MPS means that increased
performance can be achieved, by running work on the metal GPU(s).
See https://developer.apple.com/documentation/metalperformanceshaders for more details.
PACKAGE CONTENTS
event
profiler
CLASSES
builtins.object
torch.mps.event.Event
class Event(builtins.object)
| Event(enable_timing: bool = False) -> None
|
| Wrapper around an MPS event.
|
| MPS events are synchronization markers that can be used to monitor the
| device's progress, to accurately measure timing, and to synchronize MPS streams.
|
| Args:
| enable_timing (bool, optional): indicates if the event should measure time
| (default: ``False``)
|
| Methods defined here:
|
| __del__(self) -> None
|
| __init__(self, enable_timing: bool = False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| elapsed_time(self, end_event: 'Event') -> float
| Returns the time elapsed in milliseconds after the event was
| recorded and before the end_event was recorded.
|
| query(self) -> bool
| Returns True if all work currently captured by event has completed.
|
| record(self) -> None
| Records the event in the default stream.
|
| synchronize(self) -> None
| Waits until the completion of all work currently captured in this event.
| This prevents the CPU thread from proceeding until the event completes.
|
| wait(self) -> None
| Makes all future work submitted to the default stream wait for this event.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
compile_shader(source: str)
Compiles compute shader from source and allows one to invoke kernels
defined there from the comfort of Python runtime
Example::
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_MPS)
>>> lib = torch.mps.compile_shader(
... "kernel void full(device float* out, constant float& val, uint idx [[thread_position_in_grid]]) { out[idx] = val; }"
... )
>>> x = torch.zeros(16, device="mps")
>>> lib.full(x, 3.14)
current_allocated_memory() -> int
Returns the current GPU memory occupied by tensors in bytes.
.. note::
The returned size does not include cached allocations in
memory pools of MPSAllocator.
device_count() -> int
Returns the number of available MPS devices.
driver_allocated_memory() -> int
Returns total GPU memory allocated by Metal driver for the process in bytes.
.. note::
The returned size includes cached allocations in MPSAllocator pools
as well as allocations from MPS/MPSGraph frameworks.
empty_cache() -> None
Releases all unoccupied cached memory currently held by the caching
allocator so that those can be used in other GPU applications.
get_rng_state(device: int | str | torch.device = 'mps') -> torch.Tensor
Returns the random number generator state as a ByteTensor.
Args:
device (torch.device or int, optional): The device to return the RNG state of.
Default: ``'mps'`` (i.e., ``torch.device('mps')``, the current MPS device).
is_available() -> bool
load_metallib(source)
Loads a precompiled Metal library (.metallib) and returns a shader
library object that allows invoking kernels defined in it.
Args:
source: Either raw metallib bytes (``bytes``/``bytearray``) or a
filesystem path (``str``/``os.PathLike``) to a ``.metallib`` file.
This is useful for loading Metal libraries compiled ahead of time or
generated by external tools (e.g. Triton, MetalASM).
Example::
>>> # xdoctest: +SKIP("requires external .metallib file")
>>> lib = torch.mps.load_metallib("kernels.metallib")
>>> x = torch.ones(16, device="mps")
>>> lib.square(x)
manual_seed(seed: int) -> None
Sets the seed for generating random numbers.
Args:
seed (int): The desired seed.
recommended_max_memory() -> int
Returns recommended max Working set size for GPU memory in bytes.
.. note::
Recommended max working set size for Metal.
returned from device.recommendedMaxWorkingSetSize.
seed() -> None
Sets the seed for generating random numbers to a random number.
set_per_process_memory_fraction(fraction) -> None
Set memory fraction for limiting process's memory allocation on MPS device.
The allowed value equals the fraction multiplied by recommended maximum device memory
(obtained from Metal API device.recommendedMaxWorkingSetSize).
If trying to allocate more than the allowed value in a process, it will raise an out of
memory error in allocator.
Args:
fraction(float): Range: 0~2. Allowed memory equals total_memory * fraction.
.. note::
Passing 0 to fraction means unlimited allocations
(may cause system failure if out of memory).
Passing fraction greater than 1.0 allows limits beyond the value
returned from device.recommendedMaxWorkingSetSize.
set_rng_state(new_state: torch.Tensor, device: int | str | torch.device = 'mps') -> None
Sets the random number generator state.
Args:
new_state (torch.ByteTensor): The desired state
device (torch.device or int, optional): The device to set the RNG state.
Default: ``'mps'`` (i.e., ``torch.device('mps')``, the current MPS device).
synchronize() -> None
Waits for all kernels in all streams on a MPS device to complete.
DATA
__all__ = ['compile_shader', 'load_metallib', 'device_count', 'get_rng...
__annotations__ = {'_default_mps_generator': <class 'torch._C.Generato...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\mps\__init__.py
torch.msort
Python Library Documentation: built-in function msort in module torch
msort(...)
msort(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Sorts the elements of the :attr:`input` tensor along its first dimension
in ascending order by value.
.. note:: `torch.msort(t)` is equivalent to `torch.sort(t, dim=0)[0]`.
See also :func:`torch.sort`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.randn(3, 4)
>>> t
tensor([[-0.1321, 0.4370, -1.2631, -1.1289],
[-2.0527, -1.1250, 0.2275, 0.3077],
[-0.0881, -0.1259, -0.5495, 1.0284]])
>>> torch.msort(t)
tensor([[-2.0527, -1.1250, -1.2631, -1.1289],
[-0.1321, -0.1259, -0.5495, 0.3077],
[-0.0881, 0.4370, 0.2275, 1.0284]])
torch.mtia
Python Library Documentation: package torch.mtia in torch
NAME
torch.mtia - This package enables an interface for accessing MTIA backend in python
PACKAGE CONTENTS
_utils
memory
mtia_graph
CLASSES
builtins.object
device
torch.mtia.mtia_graph.graph
torch._C._MTIAGraph(pybind11_builtins.pybind11_object)
torch.mtia.mtia_graph.MTIAGraph
class MTIAGraph(torch._C._MTIAGraph)
| MTIAGraph(keep_graph: 'bool' = False) -> 'Self'
|
| Wrapper around a MTIA graph.
|
| Method resolution order:
| MTIAGraph
| torch._C._MTIAGraph
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| capture_begin(self, pool: '_POOL_HANDLE') -> 'None'
| Begin capturing a MTIA graph.
|
| capture_end(self) -> 'None'
| End the capture of a MTIA graph.
|
| instantiate(self) -> 'None'
| Instantiate the captured MTIA graph.
|
| pool(self) -> '_POOL_HANDLE'
| Return an opaque token representing the id of this graph's memory pool
|
| replay(self) -> 'None'
| Replay the captured MTIA graph.
|
| reset(self) -> 'None'
| Destroy the captured graph and reset the states.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, keep_graph: 'bool' = False) -> 'Self'
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C._MTIAGraph:
|
| __init__(...)
| __init__(self: torch._C._MTIAGraph, keep_graph: bool = False) -> None
class device(builtins.object)
| device(device: Any)
|
| Context-manager that changes the selected device.
|
| Args:
| device (torch.device or int): device index to select. It's a no-op if
| this argument is a negative integer or ``None``.
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, type: Any, value: Any, traceback: Any)
|
| __init__(self, device: Any)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class graph(builtins.object)
| graph(mtia_graph: 'MTIAGraph', pool: '_POOL_HANDLE | None' = None, stream: 'torch.mtia.Stream | None' = None)
|
| Methods defined here:
|
| __enter__(self) -> 'None'
|
| __exit__(self, *args: 'object') -> 'None'
|
| __init__(self, mtia_graph: 'MTIAGraph', pool: '_POOL_HANDLE | None' = None, stream: 'torch.mtia.Stream | None' = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'default_capture_stream': 'torch.mtia.Stream | None...
|
| default_capture_stream = None
FUNCTIONS
attach_out_of_memory_observer(observer: collections.abc.Callable[[int, int, int, int], None]) -> None
Attach an out-of-memory observer to MTIA memory allocator
current_device() -> int
Return the index of a currently selected device.
current_stream(device: torch.device | str | int | None = None) -> torch.Stream
Return the currently selected :class:`Stream` for a given device.
Args:
device (torch.device or int, optional): selected device. Returns
the currently selected :class:`Stream` for the current device, given
by :func:`~torch.mtia.current_device`, if :attr:`device` is ``None``
(default).
default_stream(device: torch.device | str | int | None = None) -> torch.Stream
Return the default :class:`Stream` for a given device.
Args:
device (torch.device or int, optional): selected device. Returns
the default :class:`Stream` for the current device, given by
:func:`~torch.mtia.current_device`, if :attr:`device` is ``None``
(default).
device_count() -> int
Return the number of MTIA devices available.
empty_cache() -> None
Empty the MTIA device cache.
get_device_capability(device: torch.device | str | int | None = None) -> tuple[int, int]
Return capability of a given device as a tuple of (major version, minor version).
Args:
device (torch.device or int, optional) selected device. Returns
statistics for the current device, given by current_device(),
if device is None (default).
get_device_properties(device: torch.device | str | int | None = None) -> dict[str, typing.Any]
Return a dictionary of MTIA device properties
Args:
device (torch.device or int, optional) selected device. Returns
statistics for the current device, given by current_device(),
if device is None (default).
get_rng_state(device: torch.device | str | int | None = 'mtia') -> torch.Tensor
Returns the random number generator state of the specified MTIA device as a ByteTensor.
Args:
device (torch.device or int, optional): The device to return the RNG state of.
Default: ``'mtia'`` (i.e., ``torch.device('mtia')``, the current mtia device).
.. warning::
This function eagerly initializes MTIA.
get_rng_state_all() -> list[torch.Tensor]
Returns a list of ByteTensor representing the random number states of all devices.
graph_pool_handle() -> '_POOL_HANDLE'
Return an opaque token representing the id of a graph memory pool.
init()
initial_seed() -> int
Returns the current random seed of the current MTIA device.
.. warning::
This function eagerly initializes MTIA.
is_available() -> bool
Return true if MTIA device is available
is_bf16_supported(including_emulation: bool = True)
Return a bool indicating if the current MTIA device supports dtype bfloat16.
is_initialized()
Return whether PyTorch's MTIA state has been initialized.
manual_seed(seed: int) -> None
Sets the seed for generating random numbers for the current MTIA device.
It's safe to call this function if MTIA is not available; in that case, it is silently ignored.
Args:
seed (int): The desired seed.
.. warning::
If you are working with a multi-GPU model, this function is insufficient
to get determinism. To seed all GPUs, use :func:`manual_seed_all`.
manual_seed_all(seed: int) -> None
Sets the seed for generating random numbers on all MTIA devices.
It's safe to call this function if MTIA is not available; in that case, it is silently ignored.
Args:
seed (int): The desired seed.
max_memory_allocated(device: torch.device | str | int | None = None) -> int
Return the maximum memory allocated in bytes for a given device.
Args:
device (torch.device, str, or int, optional) selected device. Returns
statistics for the current device, given by current_device(),
if device is None (default).
memory_allocated(device: torch.device | str | int | None = None) -> int
Return the current MTIA memory occupied by tensors in bytes for a given device.
Args:
device (torch.device or int or str, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.mtia.current_device`,
if :attr:`device` is ``None`` (default).
memory_stats(device: torch.device | str | int | None = None) -> dict[str, typing.Any]
Return a dictionary of MTIA memory allocator statistics for a given device.
Args:
device (torch.device, str, or int, optional) selected device. Returns
statistics for the current device, given by current_device(),
if device is None (default).
record_memory_history(enabled: str | None = 'all', stacks: str = 'python', max_entries: int = 0) -> None
Enable/Disable the memory profiler on MTIA allocator
Args:
enabled (all or state, optional) selected device. Returns
statistics for the current device, given by current_device(),
if device is None (default).
stacks ("python" or "cpp", optional). Select the stack trace to record.
max_entries (int, optional). Maximum number of entries to record.
reset_peak_memory_stats(device: torch.device | str | int | None = None) -> None
Reset the peak memory stats for a given device.
Args:
device (torch.device, str, or int, optional) selected device. Returns
statistics for the current device, given by current_device(),
if device is None (default).
seed() -> int
Sets the seed for generating random numbers to a random number for the current MTIA device.
It's safe to call this function if MTIA is not available; in that case, it is silently ignored.
.. warning::
If you are working with a multi-GPU model, this function will only initialize
the seed on one GPU. To initialize all GPUs, use :func:`seed_all`.
seed_all() -> int
Sets the seed for generating random numbers to a random number on all MTIA devices.
It's safe to call this function if MTIA is not available; in that case, it is silently ignored.
set_device(device: torch.device | str | int | None) -> None
Set the current device.
Args:
device (torch.device or int): selected device. This function is a no-op
if this argument is negative.
set_rng_state(new_state: torch.Tensor, device: torch.device | str | int | None = 'mtia') -> None
Sets the random number generator state of the specified MTIA device.
Args:
new_state (torch.ByteTensor): The desired state
device (torch.device or int, optional): The device to set the RNG state.
Default: ``'mtia'`` (i.e., ``torch.device('mtia')``, the current mtia device).
set_rng_state_all(new_states: list[torch.Tensor]) -> None
Sets the random number generator state of all devices.
Args:
new_states (Iterable of torch.ByteTensor): The desired state for each device.
set_stream(stream: torch.Stream)
Set the current stream. This is a wrapper API to set the stream.
Usage of this function is discouraged in favor of the ``stream``
context manager.
Args:
stream (Stream): selected stream. This function is a no-op
if this argument is ``None``.
snapshot() -> dict[str, typing.Any]
Return a dictionary of MTIA memory allocator history
stream(stream: torch.Stream | None) -> torch.mtia.StreamContext
Wrap around the Context-manager StreamContext that selects a given stream.
Arguments:
stream (Stream): selected stream. This manager is a no-op if it's
``None``.
.. note:: In eager mode stream is of type Stream class while in JIT it doesn't support torch.mtia.stream
synchronize(device: torch.device | str | int | None = None) -> None
Waits for all jobs in all streams on a MTIA device to complete.
DATA
__all__ = ['init', 'is_available', 'is_initialized', 'synchronize', 'd...
__annotations__ = {'_queued_calls': list[tuple[collections.abc.Callabl...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\mtia\__init__.py
torch.mul
Python Library Documentation: built-in function mul in module torch
mul(...)
mul(input, other, *, out=None) -> Tensor
Multiplies :attr:`input` by :attr:`other`.
.. math::
\text{out}_i = \text{input}_i \times \text{other}_i
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
Args:
input (Tensor): the input tensor.
other (Tensor or Number): the tensor or number to multiply input by.
Keyword args:
out (Tensor, optional): the output tensor.
Examples::
>>> a = torch.randn(3)
>>> a
tensor([ 0.2015, -0.4255, 2.6087])
>>> torch.mul(a, 100)
tensor([ 20.1494, -42.5491, 260.8663])
>>> b = torch.randn(4, 1)
>>> b
tensor([[ 1.1207],
[-0.3137],
[ 0.0700],
[ 0.8378]])
>>> c = torch.randn(1, 4)
>>> c
tensor([[ 0.5146, 0.1216, -0.5244, 2.2382]])
>>> torch.mul(b, c)
tensor([[ 0.5767, 0.1363, -0.5877, 2.5083],
[-0.1614, -0.0382, 0.1645, -0.7021],
[ 0.0360, 0.0085, -0.0367, 0.1567],
[ 0.4312, 0.1019, -0.4394, 1.8753]])
torch.multinomial
Python Library Documentation: built-in function multinomial in module torch
multinomial(...)
multinomial(input, num_samples, replacement=False, *, generator=None, out=None) -> LongTensor
Returns a tensor where each row contains :attr:`num_samples` indices sampled
from the multinomial (a stricter definition would be multivariate,
refer to :class:`torch.distributions.multinomial.Multinomial` for more details)
probability distribution located in the corresponding row
of tensor :attr:`input`.
.. note::
The rows of :attr:`input` do not need to sum to one (in which case we use
the values as weights), but must be non-negative, finite and have
a non-zero sum.
Indices are ordered from left to right according to when each was sampled
(first samples are placed in first column).
If :attr:`input` is a vector, :attr:`out` is a vector of size :attr:`num_samples`.
If :attr:`input` is a matrix with `m` rows, :attr:`out` is an matrix of shape
:math:`(m \times \text{num\_samples})`.
If replacement is ``True``, samples are drawn with replacement.
If not, they are drawn without replacement, which means that when a
sample index is drawn for a row, it cannot be drawn again for that row.
.. note::
When drawn without replacement, :attr:`num_samples` must be lower than
number of non-zero elements in :attr:`input` (or the min number of non-zero
elements in each row of :attr:`input` if it is a matrix).
Args:
input (Tensor): the input tensor containing probabilities
num_samples (int): number of samples to draw
replacement (bool, optional): whether to draw with replacement or not
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
Example::
>>> weights = torch.tensor([0, 10, 3, 0], dtype=torch.float) # create a tensor of weights
>>> torch.multinomial(weights, 2)
tensor([1, 2])
>>> torch.multinomial(weights, 5) # ERROR!
RuntimeError: cannot sample n_sample > prob_dist.size(-1) samples without replacement
>>> torch.multinomial(weights, 4, replacement=True)
tensor([ 2, 1, 1, 1])
torch.multiply
Python Library Documentation: built-in function multiply in module torch
multiply(...)
multiply(input, other, *, out=None)
Alias for :func:`torch.mul`.
torch.multiprocessing
Python Library Documentation: package torch.multiprocessing in torch
NAME
torch.multiprocessing - torch.multiprocessing is a wrapper around the native :mod:`multiprocessing` module.
DESCRIPTION
It registers custom reducers, that use shared memory to provide shared
views on the same data in different processes. Once the tensor/storage is moved
to shared_memory (see :func:`~torch.Tensor.share_memory_`), it will be possible
to send it to other processes without making any copies.
The API is 100% compatible with the original module - it's enough to change
``import multiprocessing`` to ``import torch.multiprocessing`` to have all the
tensors sent through the queues or shared via other mechanisms, moved to shared
memory.
Because of the similarity of APIs we do not document most of this package
contents, and we recommend referring to very good docs of the original module.
PACKAGE CONTENTS
_atfork
pool
queue
reductions
spawn
CLASSES
builtins.Exception(builtins.BaseException)
multiprocessing.context.ProcessError
multiprocessing.context.AuthenticationError
multiprocessing.context.BufferTooShort
multiprocessing.context.TimeoutError
multiprocessing.process.BaseProcess(builtins.object)
multiprocessing.context.Process
class AuthenticationError(ProcessError)
| Method resolution order:
| AuthenticationError
| ProcessError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from ProcessError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class BufferTooShort(ProcessError)
| Method resolution order:
| BufferTooShort
| ProcessError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from ProcessError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class Process(multiprocessing.process.BaseProcess)
| Process(group=None, target=None, name=None, args=(), kwargs={}, *, daemon=None)
|
| Method resolution order:
| Process
| multiprocessing.process.BaseProcess
| builtins.object
|
| Methods inherited from multiprocessing.process.BaseProcess:
|
| __init__(self, group=None, target=None, name=None, args=(), kwargs={}, *, daemon=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| close(self)
| Close the Process object.
|
| This method releases resources held by the Process object. It is
| an error to call this method if the child process is still running.
|
| is_alive(self)
| Return whether process is alive
|
| join(self, timeout=None)
| Wait until child process terminates
|
| kill(self)
| Terminate process; sends SIGKILL signal or uses TerminateProcess()
|
| run(self)
| Method to be run in sub-process; can be overridden in sub-class
|
| start(self)
| Start child process
|
| terminate(self)
| Terminate process; sends SIGTERM signal or uses TerminateProcess()
|
| ----------------------------------------------------------------------
| Readonly properties inherited from multiprocessing.process.BaseProcess:
|
| exitcode
| Return exit code of process or `None` if it has yet to stop
|
| ident
| Return identifier (PID) of process or `None` if it has yet to start
|
| pid
| Return identifier (PID) of process or `None` if it has yet to start
|
| sentinel
| Return a file descriptor (Unix) or handle (Windows) suitable for
| waiting for process termination.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from multiprocessing.process.BaseProcess:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| authkey
|
| daemon
| Return whether process is a daemon
|
| name
class ProcessError(builtins.Exception)
| Method resolution order:
| ProcessError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class TimeoutError(ProcessError)
| Method resolution order:
| TimeoutError
| ProcessError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from ProcessError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
FUNCTIONS
Array(typecode_or_type, size_or_initializer, *, lock=True) method of multiprocessing.context.DefaultContext instance
Returns a synchronized shared array
Barrier(parties, action=None, timeout=None) method of multiprocessing.context.DefaultContext instance
Returns a barrier object
BoundedSemaphore(value=1) method of multiprocessing.context.DefaultContext instance
Returns a bounded semaphore object
Condition(lock=None) method of multiprocessing.context.DefaultContext instance
Returns a condition object
Event() method of multiprocessing.context.DefaultContext instance
Returns an event object
JoinableQueue(maxsize=0) method of multiprocessing.context.DefaultContext instance
Returns a queue object
Lock() method of multiprocessing.context.DefaultContext instance
Returns a non-recursive lock object
Manager() method of multiprocessing.context.DefaultContext instance
Returns a manager associated with a running server process
The managers methods such as `Lock()`, `Condition()` and `Queue()`
can be used to create shared objects.
Pipe(duplex=True) method of multiprocessing.context.DefaultContext instance
Returns two connection object connected by a pipe
Pool(processes=None, initializer=None, initargs=(), maxtasksperchild=None) method of multiprocessing.context.DefaultContext instance
Returns a process pool object
Queue(maxsize=0) method of multiprocessing.context.DefaultContext instance
Returns a queue object
RLock() method of multiprocessing.context.DefaultContext instance
Returns a recursive lock object
RawArray(typecode_or_type, size_or_initializer) method of multiprocessing.context.DefaultContext instance
Returns a shared array
RawValue(typecode_or_type, *args) method of multiprocessing.context.DefaultContext instance
Returns a shared object
Semaphore(value=1) method of multiprocessing.context.DefaultContext instance
Returns a semaphore object
SimpleQueue() method of multiprocessing.context.DefaultContext instance
Returns a queue object
Value(typecode_or_type, *args, lock=True) method of multiprocessing.context.DefaultContext instance
Returns a synchronized shared object
active_children()
Return list of process objects corresponding to live child processes
allow_connection_pickling() method of multiprocessing.context.DefaultContext instance
Install support for sending connections and sockets
between processes
cpu_count() method of multiprocessing.context.DefaultContext instance
Returns the number of CPUs in the system
current_process()
Return process object representing the current process
freeze_support() method of multiprocessing.context.DefaultContext instance
Check whether this is a fake forked process in a frozen executable.
If so then run code specified by commandline and exit.
get_all_sharing_strategies()
Return a set of sharing strategies supported on a current system.
get_all_start_methods() method of multiprocessing.context.DefaultContext instance
Returns a list of the supported start methods, default first.
get_context(method=None) method of multiprocessing.context.DefaultContext instance
get_logger() method of multiprocessing.context.DefaultContext instance
Return package logger -- if it does not already exist then
it is created.
get_sharing_strategy()
Return the current strategy for sharing CPU tensors.
get_start_method(allow_none=False) method of multiprocessing.context.DefaultContext instance
log_to_stderr(level=None) method of multiprocessing.context.DefaultContext instance
Turn on logging and add a handler which prints to stderr
parent_process()
Return process object representing the parent process
set_executable(executable) method of multiprocessing.context.DefaultContext instance
Sets the path to a python.exe or pythonw.exe binary used to run
child processes instead of sys.executable when using the 'spawn'
start method. Useful for people embedding Python.
set_forkserver_preload(module_names) method of multiprocessing.context.DefaultContext instance
Set list of module names to try to load in forkserver process.
This is really just a hint.
set_sharing_strategy(new_strategy)
Set the strategy for sharing CPU tensors.
Args:
new_strategy (str): Name of the selected strategy. Should be one of
the values returned by :func:`get_all_sharing_strategies()`.
set_start_method(method, force=False) method of multiprocessing.context.DefaultContext instance
DATA
__all__ = ['set_sharing_strategy', 'get_sharing_strategy', 'get_all_sh...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\multiprocessing\__init__.py
torch.mv
Python Library Documentation: built-in function mv in module torch
mv(...)
mv(input, vec, *, out=None) -> Tensor
Performs a matrix-vector product of the matrix :attr:`input` and the vector
:attr:`vec`.
If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
size :math:`m`, :attr:`out` will be 1-D of size :math:`n`.
.. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
Args:
input (Tensor): matrix to be multiplied
vec (Tensor): vector to be multiplied
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> mat = torch.randn(2, 3)
>>> vec = torch.randn(3)
>>> torch.mv(mat, vec)
tensor([ 1.0404, -0.6361])
torch.mvlgamma
Python Library Documentation: built-in function mvlgamma in module torch
mvlgamma(...)
mvlgamma(input, p, *, out=None) -> Tensor
Alias for :func:`torch.special.multigammaln`.
torch.nan
Python Library Documentation: float object
class float(object)
| float(x=0, /)
|
| Convert a string or number to a floating-point number, if possible.
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(self, /)
| Return the ceiling as an Integral.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(self, /)
| Return the floor as an Integral.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Formats the float according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __int__(self, /)
| int(self)
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __round__(self, ndigits=None, /)
| Return the Integral closest to x, rounding half toward even.
|
| When an argument is passed, work like built-in round(x, ndigits).
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(self, /)
| Return the Integral closest to x between 0 and x.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is exactly equal to the original float.
|
| The ratio is in lowest terms and has a positive denominator. Raise
| OverflowError on infinities and a ValueError on NaNs.
|
| >>> (10.0).as_integer_ratio()
| (10, 1)
| >>> (0.0).as_integer_ratio()
| (0, 1)
| >>> (-.25).as_integer_ratio()
| (-1, 4)
|
| conjugate(self, /)
| Return self, the complex conjugate of any float.
|
| hex(self, /)
| Return a hexadecimal representation of a floating-point number.
|
| >>> (-0.1).hex()
| '-0x1.999999999999ap-4'
| >>> 3.14159.hex()
| '0x1.921f9f01b866ep+1'
|
| is_integer(self, /)
| Return True if the float is an integer.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __getformat__(typestr, /)
| You probably don't want to use this function.
|
| typestr
| Must be 'double' or 'float'.
|
| It exists mainly to be used in Python's test suite.
|
| This function returns whichever of 'unknown', 'IEEE, big-endian' or 'IEEE,
| little-endian' best describes the format of floating-point numbers used by the
| C type named by typestr.
|
| fromhex(string, /)
| Create a floating-point number from a hexadecimal string.
|
| >>> float.fromhex('0x1.ffffp10')
| 2047.984375
| >>> float.fromhex('-0x1p-1074')
| -5e-324
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| imag
| the imaginary part of a complex number
|
| real
| the real part of a complex number
torch.nan_to_num
Python Library Documentation: built-in function nan_to_num in module torch
nan_to_num(...)
nan_to_num(input, nan=0.0, posinf=None, neginf=None, *, out=None) -> Tensor
Replaces :literal:`NaN`, positive infinity, and negative infinity values in :attr:`input`
with the values specified by :attr:`nan`, :attr:`posinf`, and :attr:`neginf`, respectively.
By default, :literal:`NaN`\ s are replaced with zero, positive infinity is replaced with the
greatest finite value representable by :attr:`input`'s dtype, and negative infinity
is replaced with the least finite value representable by :attr:`input`'s dtype.
Args:
input (Tensor): the input tensor.
nan (Number, optional): the value to replace :literal:`NaN`\s with. Default is zero.
posinf (Number, optional): if a Number, the value to replace positive infinity values with.
If None, positive infinity values are replaced with the greatest finite value representable by :attr:`input`'s dtype.
Default is None.
neginf (Number, optional): if a Number, the value to replace negative infinity values with.
If None, negative infinity values are replaced with the lowest finite value representable by :attr:`input`'s dtype.
Default is None.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.tensor([float('nan'), float('inf'), -float('inf'), 3.14])
>>> torch.nan_to_num(x)
tensor([ 0.0000e+00, 3.4028e+38, -3.4028e+38, 3.1400e+00])
>>> torch.nan_to_num(x, nan=2.0)
tensor([ 2.0000e+00, 3.4028e+38, -3.4028e+38, 3.1400e+00])
>>> torch.nan_to_num(x, nan=2.0, posinf=1.0)
tensor([ 2.0000e+00, 1.0000e+00, -3.4028e+38, 3.1400e+00])
torch.nan_to_num_
Python Library Documentation: built-in function nan_to_num_ in module torch nan_to_num_(...)
torch.nanmean
Python Library Documentation: built-in function nanmean in module torch
nanmean(...)
nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None) -> Tensor
Computes the mean of all `non-NaN` elements along the specified dimensions.
Input must be floating point or complex.
This function is identical to :func:`torch.mean` when there are no `NaN` values
in the :attr:`input` tensor. In the presence of `NaN`, :func:`torch.mean` will
propagate the `NaN` to the output whereas :func:`torch.nanmean` will ignore the
`NaN` values (`torch.nanmean(a)` is equivalent to `torch.mean(a[~a.isnan()])`).
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor, either of floating point or complex dtype
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
out (Tensor, optional): the output tensor.
.. seealso::
:func:`torch.mean` computes the mean value, propagating `NaN`.
Example::
>>> x = torch.tensor([[torch.nan, 1, 2], [1, 2, 3]])
>>> x.mean()
tensor(nan)
>>> x.nanmean()
tensor(1.8000)
>>> x.mean(dim=0)
tensor([ nan, 1.5000, 2.5000])
>>> x.nanmean(dim=0)
tensor([1.0000, 1.5000, 2.5000])
# If all elements in the reduced dimensions are NaN then the result is NaN
>>> torch.tensor([torch.nan]).nanmean()
tensor(nan)
torch.nanmedian
Python Library Documentation: built-in function nanmedian in module torch
nanmedian(...)
nanmedian(input) -> Tensor
Returns the median of the values in :attr:`input`, ignoring ``NaN`` values.
This function is identical to :func:`torch.median` when there are no ``NaN`` values in :attr:`input`.
When :attr:`input` has one or more ``NaN`` values, :func:`torch.median` will always return ``NaN``,
while this function will return the median of the non-``NaN`` elements in :attr:`input`.
If all the elements in :attr:`input` are ``NaN`` it will also return ``NaN``.
Args:
input (Tensor): the input tensor.
Example::
>>> a = torch.tensor([1, float('nan'), 3, 2])
>>> a.median()
tensor(nan)
>>> a.nanmedian()
tensor(2.)
.. function:: nanmedian(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
:noindex:
Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
in the dimension :attr:`dim`, ignoring ``NaN`` values, and ``indices`` contains the index of the median values
found in the dimension :attr:`dim`.
This function is identical to :func:`torch.median` when there are no ``NaN`` values in a reduced row. When a reduced row has
one or more ``NaN`` values, :func:`torch.median` will always reduce it to ``NaN``, while this function will reduce it to the
median of the non-``NaN`` elements. If all the elements in a reduced row are ``NaN`` then it will be reduced to ``NaN``, too.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
tensor, which must have dtype long, with their indices in the dimension
:attr:`dim` of :attr:`input`.
Example::
>>> a = torch.tensor([[2, 3, 1], [float('nan'), 1, float('nan')]])
>>> a
tensor([[2., 3., 1.],
[nan, 1., nan]])
>>> a.median(0)
torch.return_types.median(values=tensor([nan, 1., nan]), indices=tensor([1, 1, 1]))
>>> a.nanmedian(0)
torch.return_types.nanmedian(values=tensor([2., 1., 1.]), indices=tensor([0, 1, 0]))
torch.nanquantile
Python Library Documentation: built-in function nanquantile in module torch
nanquantile(...)
nanquantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
This is a variant of :func:`torch.quantile` that "ignores" ``NaN`` values,
computing the quantiles :attr:`q` as if ``NaN`` values in :attr:`input` did
not exist. If all values in a reduced row are ``NaN`` then the quantiles for
that reduction will be ``NaN``. See the documentation for :func:`torch.quantile`.
Args:
input (Tensor): the input tensor.
q (float or Tensor): a scalar or 1D tensor of quantile values in the range [0, 1]
dim (int, optional): the dimension to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword arguments:
interpolation (str): interpolation method to use when the desired quantile lies between two data points.
Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
Default is ``linear``.
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.tensor([float('nan'), 1, 2])
>>> t.quantile(0.5)
tensor(nan)
>>> t.nanquantile(0.5)
tensor(1.5000)
>>> t = torch.tensor([[float('nan'), float('nan')], [1, 2]])
>>> t
tensor([[nan, nan],
[1., 2.]])
>>> t.nanquantile(0.5, dim=0)
tensor([1., 2.])
>>> t.nanquantile(0.5, dim=1)
tensor([ nan, 1.5000])
torch.nansum
Python Library Documentation: built-in function nansum in module torch
nansum(...)
nansum(input, *, dtype=None) -> Tensor
Returns the sum of all elements, treating Not a Numbers (NaNs) as zero.
Args:
input (Tensor): the input tensor.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> a = torch.tensor([1., 2., float('nan'), 4.])
>>> torch.nansum(a)
tensor(7.)
.. function:: nansum(input, dim, keepdim=False, *, dtype=None) -> Tensor
:noindex:
Returns the sum of each row of the :attr:`input` tensor in the given
dimension :attr:`dim`, treating Not a Numbers (NaNs) as zero.
If :attr:`dim` is a list of dimensions, reduce over all of them.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> torch.nansum(torch.tensor([1., float("nan")]))
tensor(1.)
>>> a = torch.tensor([[1, 2], [3., float("nan")]])
>>> torch.nansum(a)
tensor(6.)
>>> torch.nansum(a, dim=0)
tensor([4., 2.])
>>> torch.nansum(a, dim=1)
tensor([3., 3.])
torch.narrow
Python Library Documentation: built-in function narrow in module torch
narrow(...)
narrow(input, dim, start, length) -> Tensor
Returns a new tensor that is a narrowed version of :attr:`input` tensor. The
dimension :attr:`dim` is input from :attr:`start` to ``start + length``. The
returned tensor and :attr:`input` tensor share the same underlying storage.
Args:
input (Tensor): the tensor to narrow
dim (int): the dimension along which to narrow
start (int or Tensor): index of the element to start the narrowed dimension
from. Can be negative, which means indexing from the end of `dim`. If
`Tensor`, it must be an 0-dim integral `Tensor` (bools not allowed)
length (int): length of the narrowed dimension, must be weakly positive
Example::
>>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> torch.narrow(x, 0, 0, 2)
tensor([[ 1, 2, 3],
[ 4, 5, 6]])
>>> torch.narrow(x, 1, 1, 2)
tensor([[ 2, 3],
[ 5, 6],
[ 8, 9]])
>>> torch.narrow(x, -1, torch.tensor(-1), 1)
tensor([[3],
[6],
[9]])
torch.narrow_copy
Python Library Documentation: built-in function narrow_copy in module torch
narrow_copy(...)
narrow_copy(input, dim, start, length, *, out=None) -> Tensor
Same as :meth:`Tensor.narrow` except this returns a copy rather
than shared storage. This is primarily for sparse tensors, which
do not have a shared-storage narrow method.
Args:
input (Tensor): the tensor to narrow
dim (int): the dimension along which to narrow
start (int): index of the element to start the narrowed dimension from. Can
be negative, which means indexing from the end of `dim`
length (int): length of the narrowed dimension, must be weakly positive
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> torch.narrow_copy(x, 0, 0, 2)
tensor([[ 1, 2, 3],
[ 4, 5, 6]])
>>> torch.narrow_copy(x, 1, 1, 2)
tensor([[ 2, 3],
[ 5, 6],
[ 8, 9]])
>>> s = torch.arange(16).reshape(2, 2, 2, 2).to_sparse(2)
>>> torch.narrow_copy(s, 0, 0, 1)
tensor(indices=tensor([[0, 0],
[0, 1]]),
values=tensor([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]]),
size=(1, 2, 2, 2), nnz=2, layout=torch.sparse_coo)
.. seealso::
:func:`torch.narrow` for a non copy variant
torch.native_batch_norm
Python Library Documentation: built-in function native_batch_norm in module torch native_batch_norm(...)
torch.native_channel_shuffle
Python Library Documentation: built-in function native_channel_shuffle in module torch
native_channel_shuffle(...)
native_channel_shuffle(input, groups) -> Tensor
Native kernel level implementation of the `channel_shuffle`.
This function might become private in future releases, use with caution.
Divide the channels in a tensor of shape :math:`(*, C , H, W)`
into g groups and rearrange them as :math:`(*, C \frac g, g, H, W)`,
while keeping the original tensor shape.
See :class:`~torch.nn.ChannelShuffle` for details.
Args:
input (Tensor): the input tensor
groups (int): number of groups to divide channels in and rearrange.
Examples::
>>> input = torch.randn(1, 4, 2, 2)
>>> print(input)
[[[[1, 2],
[3, 4]],
[[5, 6],
[7, 8]],
[[9, 10],
[11, 12]],
[[13, 14],
[15, 16]],
]]
>>> output = torch.nn.functional.native_channel_shuffle(input, 2)
>>> print(output)
[[[[1, 2],
[3, 4]],
[[9, 10],
[11, 12]],
[[5, 6],
[7, 8]],
[[13, 14],
[15, 16]],
]]
torch.native_dropout
Python Library Documentation: built-in function native_dropout in module torch native_dropout(...)
torch.native_group_norm
Python Library Documentation: built-in function native_group_norm in module torch native_group_norm(...)
torch.native_layer_norm
Python Library Documentation: built-in function native_layer_norm in module torch native_layer_norm(...)
torch.native_norm
Python Library Documentation: built-in function native_norm in module torch native_norm(...)
torch.ne
Python Library Documentation: built-in function ne in module torch
ne(...)
ne(input, other, *, out=None) -> Tensor
Computes :math:`\text{input} \neq \text{other}` element-wise.
The second argument can be a number or a tensor whose shape is
:ref:`broadcastable <broadcasting-semantics>` with the first argument.
Args:
input (Tensor): the tensor to compare
other (Tensor or float): the tensor or value to compare
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
A boolean tensor that is True where :attr:`input` is not equal to :attr:`other` and False elsewhere
Example::
>>> torch.ne(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[False, True], [True, False]])
torch.neg
Python Library Documentation: built-in function neg in module torch
neg(...)
neg(input, *, out=None) -> Tensor
Returns a new tensor with the negative of the elements of :attr:`input`.
.. math::
\text{out} = -1 \times \text{input}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(5)
>>> a
tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
>>> torch.neg(a)
tensor([-0.0090, 0.2262, 0.0682, 0.2866, -0.3940])
torch.neg_
Python Library Documentation: built-in function neg_ in module torch neg_(...)
torch.negative
Python Library Documentation: built-in function negative in module torch
negative(...)
negative(input, *, out=None) -> Tensor
Alias for :func:`torch.neg`
torch.negative_
Python Library Documentation: built-in function negative_ in module torch negative_(...)
torch.nested
Python Library Documentation: package torch.nested in torch
NAME
torch.nested - # mypy: allow-untyped-defs
PACKAGE CONTENTS
_internal (package)
FUNCTIONS
as_nested_tensor(ts: torch.Tensor | list[torch.Tensor] | tuple[torch.Tensor, ...], dtype: torch.dtype | None = None, device: torch.device | None = None, layout=None) -> torch.Tensor
Constructs a nested tensor preserving autograd history from a tensor or a list / tuple of
tensors.
If a nested tensor is passed, it will be returned directly unless the device / dtype / layout
differ. Note that converting device / dtype will result in a copy, while converting layout
is not currently supported by this function.
If a non-nested tensor is passed, it is treated as a batch of constituents of consistent size.
A copy will be incurred if the passed device / dtype differ from those of the input OR if
the input is non-contiguous. Otherwise, the input's storage will be used directly.
If a tensor list is provided, tensors in the list are always copied during construction of
the nested tensor.
Args:
ts (Tensor or List[Tensor] or Tuple[Tensor]): a tensor to treat as a nested tensor OR a
list / tuple of tensors with the same ndim
Keyword arguments:
dtype (:class:`torch.dtype`, optional): the desired type of returned nested tensor.
Default: if None, same :class:`torch.dtype` as leftmost tensor in the list.
device (:class:`torch.device`, optional): the desired device of returned nested tensor.
Default: if None, same :class:`torch.device` as leftmost tensor in the list
layout (:class:`torch.layout`, optional): the desired layout of returned nested tensor.
Only strided and jagged layouts are supported. Default: if None, the strided layout.
Example::
>>> a = torch.arange(3, dtype=torch.float, requires_grad=True)
>>> b = torch.arange(5, dtype=torch.float, requires_grad=True)
>>> nt = torch.nested.as_nested_tensor([a, b])
>>> nt.is_leaf
False
>>> fake_grad = torch.nested.nested_tensor([torch.ones_like(a), torch.zeros_like(b)])
>>> nt.backward(fake_grad)
>>> a.grad
tensor([1., 1., 1.])
>>> b.grad
tensor([0., 0., 0., 0., 0.])
>>> c = torch.randn(3, 5, requires_grad=True)
>>> nt2 = torch.nested.as_nested_tensor(c)
masked_select(tensor: torch.Tensor, mask: torch.Tensor) -> torch.Tensor
Constructs a nested tensor given a strided tensor input and a strided mask, the resulting jagged layout nested tensor
will have values retain values where the mask is equal to True. The dimensionality of the mask is preserved and is
represented with the offsets, this is unlike :func:`masked_select` where the output is collapsed to a 1D tensor.
Args:
tensor (:class:`torch.Tensor`): a strided tensor from which the jagged layout nested tensor is constructed from.
mask (:class:`torch.Tensor`): a strided mask tensor which is applied to the tensor input
Example::
>>> tensor = torch.randn(3, 3)
>>> mask = torch.tensor([[False, False, True], [True, False, True], [False, False, True]])
>>> nt = torch.nested.masked_select(tensor, mask)
>>> nt.shape
torch.Size([3, j4])
>>> # Length of each item in the batch:
>>> nt.offsets().diff()
tensor([1, 2, 1])
>>> tensor = torch.randn(6, 5)
>>> mask = torch.tensor([False])
>>> nt = torch.nested.masked_select(tensor, mask)
>>> nt.shape
torch.Size([6, j5])
>>> # Length of each item in the batch:
>>> nt.offsets().diff()
tensor([0, 0, 0, 0, 0, 0])
narrow(tensor: torch.Tensor, dim: int, start: int | torch.Tensor, length: int | torch.Tensor, layout=torch.strided) -> torch.Tensor
Constructs a nested tensor (which might be a view) from :attr:`tensor`, a strided tensor. This follows
similar semantics to torch.Tensor.narrow, where in the :attr:`dim`-th dimension the new nested tensor
shows only the elements in the interval `[start, start+length)`. As nested representations
allow for a different `start` and `length` at each 'row' of that dimension, :attr:`start` and :attr:`length`
can also be tensors of shape `tensor.shape[0]`.
There's some differences depending on the layout you use for the nested tensor. If using strided layout,
torch.narrow will do a copy of the narrowed data into a contiguous NT with strided layout, while
jagged layout narrow() will create a non-contiguous view of your original strided tensor. This particular
representation is really useful for representing kv-caches in Transformer models, as specialized
SDPA kernels can deal with format easily, resulting in performance improvements.
Args:
tensor (:class:`torch.Tensor`): a strided tensor, which will be used as the underlying data
for the nested tensor if using the jagged layout or will be copied for the strided layout.
dim (int): the dimension where narrow will be applied. Only `dim=1` is supported for the
jagged layout, while strided supports all dim
start (Union[int, :class:`torch.Tensor`]): starting element for the narrow operation
length (Union[int, :class:`torch.Tensor`]): number of elements taken during the narrow op
Keyword arguments:
layout (:class:`torch.layout`, optional): the desired layout of returned nested tensor.
Only strided and jagged layouts are supported. Default: if None, the strided layout.
Example::
>>> starts = torch.tensor([0, 1, 2, 3, 4], dtype=torch.int64)
>>> lengths = torch.tensor([3, 2, 2, 1, 5], dtype=torch.int64)
>>> narrow_base = torch.randn(5, 10, 20)
>>> nt_narrowed = torch.nested.narrow(narrow_base, 1, starts, lengths, layout=torch.jagged)
>>> nt_narrowed.is_contiguous()
False
nested_tensor(tensor_list, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) -> torch.Tensor
Constructs a nested tensor with no autograd history (also known as a "leaf tensor", see
:ref:`Autograd mechanics <autograd-mechanics>`) from :attr:`tensor_list` a list of tensors.
Args:
tensor_list (List[array_like]): a list of tensors, or anything that can be passed to torch.tensor,
where each element of the list has the same dimensionality.
Keyword arguments:
dtype (:class:`torch.dtype`, optional): the desired type of returned nested tensor.
Default: if None, same :class:`torch.dtype` as leftmost tensor in the list.
layout (:class:`torch.layout`, optional): the desired layout of returned nested tensor.
Only strided and jagged layouts are supported. Default: if None, the strided layout.
device (:class:`torch.device`, optional): the desired device of returned nested tensor.
Default: if None, same :class:`torch.device` as leftmost tensor in the list
requires_grad (bool, optional): If autograd should record operations on the
returned nested tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned nested tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> a = torch.arange(3, dtype=torch.float, requires_grad=True)
>>> b = torch.arange(5, dtype=torch.float, requires_grad=True)
>>> nt = torch.nested.nested_tensor([a, b], requires_grad=True)
>>> nt.is_leaf
True
nested_tensor_from_jagged(values: torch.Tensor, offsets: torch.Tensor | None = None, lengths: torch.Tensor | None = None, jagged_dim: int | None = None, min_seqlen: int | None = None, max_seqlen: int | None = None) -> torch.Tensor
Constructs a jagged layout nested tensor from the given jagged components. The jagged layout
consists of a required values buffer with the jagged dimension packed into a single dimension.
The offsets / lengths metadata determines how this dimension is split into batch elements
and are expected to be allocated on the same device as the values buffer.
Expected metadata formats:
* offsets: Indices within the packed dimension splitting it into heterogeneously-sized
batch elements. Example: [0, 2, 3, 6] indicates that a packed jagged dim of size 6
should be conceptually split into batch elements of length [2, 1, 3]. Note that both the
beginning and ending offsets are required for kernel convenience (i.e. shape batch_size + 1).
* lengths: Lengths of the individual batch elements; shape == batch_size. Example: [2, 1, 3]
indicates that a packed jagged dim of size 6 should be conceptually split into batch
elements of length [2, 1, 3].
Note that it can be useful to provide both offsets and lengths. This describes a nested tensor
with "holes", where the offsets indicate the start position of each batch item and the length
specifies the total number of elements (see example below).
The returned jagged layout nested tensor will be a view of the input values tensor.
Args:
values (:class:`torch.Tensor`): The underlying buffer in the shape of
(sum_B(*), D_1, ..., D_N). The jagged dimension is packed into a single dimension,
with the offsets / lengths metadata used to distinguish batch elements.
offsets (optional :class:`torch.Tensor`): Offsets into the jagged dimension of shape B + 1.
lengths (optional :class:`torch.Tensor`): Lengths of the batch elements of shape B.
jagged_dim (optional int): Indicates which dimension in values is the packed jagged
dimension. Must be >= 1 as the batch dimension (dim=0) cannot be ragged.
If None, this is set to dim=1 (i.e. the dimension immediately following the batch dimension). Default: None
min_seqlen (optional int): If set, uses the specified value as the cached minimum sequence
length for the returned nested tensor. This can be a useful alternative to computing
this value on-demand, possibly avoiding a GPU -> CPU sync. Default: None
max_seqlen (optional int): If set, uses the specified value as the cached maximum sequence
length for the returned nested tensor. This can be a useful alternative to computing
this value on-demand, possibly avoiding a GPU -> CPU sync. Default: None
Example::
>>> values = torch.randn(12, 5)
>>> offsets = torch.tensor([0, 3, 5, 6, 10, 12])
>>> nt = nested_tensor_from_jagged(values, offsets)
>>> # 3D shape with the middle dimension jagged
>>> nt.shape
torch.Size([5, j2, 5])
>>> # Length of each item in the batch:
>>> offsets.diff()
tensor([3, 2, 1, 4, 2])
>>> values = torch.randn(6, 5)
>>> offsets = torch.tensor([0, 2, 3, 6])
>>> lengths = torch.tensor([1, 1, 2])
>>> # NT with holes
>>> nt = nested_tensor_from_jagged(values, offsets, lengths)
>>> a, b, c = nt.unbind()
>>> # Batch item 1 consists of indices [0, 1)
>>> torch.equal(a, values[0:1, :])
True
>>> # Batch item 2 consists of indices [2, 3)
>>> torch.equal(b, values[2:3, :])
True
>>> # Batch item 3 consists of indices [3, 5)
>>> torch.equal(c, values[3:5, :])
True
to_padded_tensor = nested_to_padded_tensor(...)
to_padded_tensor(input, padding, output_size=None, out=None) -> Tensor
Returns a new (non-nested) Tensor by padding the :attr:`input` nested tensor.
The leading entries will be filled with the nested data,
while the trailing entries will be padded.
.. warning::
:func:`to_padded_tensor` always copies the underlying data,
since the nested and the non-nested tensors differ in memory layout.
Args:
padding (float): The padding value for the trailing entries.
Keyword args:
output_size (Tuple[int]): The size of the output tensor.
If given, it must be large enough to contain all nested data;
else, will infer by taking the max size of each nested sub-tensor along each dimension.
out (Tensor, optional): the output tensor.
Example::
>>> nt = torch.nested.nested_tensor([torch.randn((2, 5)), torch.randn((3, 4))])
nested_tensor([
tensor([[ 1.6862, -1.1282, 1.1031, 0.0464, -1.3276],
[-1.9967, -1.0054, 1.8972, 0.9174, -1.4995]]),
tensor([[-1.8546, -0.7194, -0.2918, -0.1846],
[ 0.2773, 0.8793, -0.5183, -0.6447],
[ 1.8009, 1.8468, -0.9832, -1.5272]])
])
>>> pt_infer = torch.nested.to_padded_tensor(nt, 0.0)
tensor([[[ 1.6862, -1.1282, 1.1031, 0.0464, -1.3276],
[-1.9967, -1.0054, 1.8972, 0.9174, -1.4995],
[ 0.0000, 0.0000, 0.0000, 0.0000, 0.0000]],
[[-1.8546, -0.7194, -0.2918, -0.1846, 0.0000],
[ 0.2773, 0.8793, -0.5183, -0.6447, 0.0000],
[ 1.8009, 1.8468, -0.9832, -1.5272, 0.0000]]])
>>> pt_large = torch.nested.to_padded_tensor(nt, 1.0, (2, 4, 6))
tensor([[[ 1.6862, -1.1282, 1.1031, 0.0464, -1.3276, 1.0000],
[-1.9967, -1.0054, 1.8972, 0.9174, -1.4995, 1.0000],
[ 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000],
[ 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000]],
[[-1.8546, -0.7194, -0.2918, -0.1846, 1.0000, 1.0000],
[ 0.2773, 0.8793, -0.5183, -0.6447, 1.0000, 1.0000],
[ 1.8009, 1.8468, -0.9832, -1.5272, 1.0000, 1.0000],
[ 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000]]])
>>> pt_small = torch.nested.to_padded_tensor(nt, 2.0, (2, 2, 2))
RuntimeError: Value in output_size is less than NestedTensor padded size. Truncation is not supported.
DATA
__all__ = ['to_padded_tensor', 'as_nested_tensor', 'nested_tensor', 'n...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\nested\__init__.py
torch.newaxis
Python Library Documentation: NoneType object class NoneType(object) | Methods defined here: | | __bool__(self, /) | True if self else False | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __repr__(self, /) | Return repr(self). | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature.
torch.nextafter
Python Library Documentation: built-in function nextafter in module torch
nextafter(...)
nextafter(input, other, *, out=None) -> Tensor
Return the next floating-point value after :attr:`input` towards :attr:`other`, elementwise.
The shapes of ``input`` and ``other`` must be
:ref:`broadcastable <broadcasting-semantics>`.
Args:
input (Tensor): the first input tensor
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> eps = torch.finfo(torch.float32).eps
>>> torch.nextafter(torch.tensor([1.0, 2.0]), torch.tensor([2.0, 1.0])) == torch.tensor([eps + 1, 2 - eps])
tensor([True, True])
torch.nn
Python Library Documentation: package torch.nn in torch
NAME
torch.nn - # mypy: allow-untyped-defs
PACKAGE CONTENTS
_reduction
attention (package)
backends (package)
common_types
cpp
functional
grad
init
intrinsic (package)
modules (package)
parallel (package)
parameter
qat (package)
quantizable (package)
quantized (package)
utils (package)
FUNCTIONS
factory_kwargs(kwargs)
Return a canonicalized dict of factory kwargs.
Given kwargs, returns a canonicalized dict of factory kwargs that can be directly passed
to factory functions like torch.empty, or errors if unrecognized kwargs are present.
This function makes it simple to write code like this::
class MyModule(nn.Module):
def __init__(self, **kwargs):
factory_kwargs = torch.nn.factory_kwargs(kwargs)
self.weight = Parameter(torch.empty(10, **factory_kwargs))
Why should you use this function instead of just passing `kwargs` along directly?
1. This function does error validation, so if there are unexpected kwargs we will
immediately report an error, instead of deferring it to the factory call
2. This function supports a special `factory_kwargs` argument, which can be used to
explicitly specify a kwarg to be used for factory functions, in the event one of the
factory kwargs conflicts with an already existing argument in the signature (e.g.
in the signature ``def f(dtype, **kwargs)``, you can specify ``dtype`` for factory
functions, as distinct from the dtype argument, by saying
``f(dtype1, factory_kwargs={"dtype": dtype2})``)
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\nn\__init__.py
torch.no_grad
Python Library Documentation: class no_grad in module torch.autograd.grad_mode class no_grad(torch.utils._contextlib._NoParamDecoratorContextManager) | no_grad() -> None | | Context-manager that disables gradient calculation. | | Disabling gradient calculation is useful for inference, when you are sure | that you will not call :meth:`Tensor.backward()`. It will reduce memory | consumption for computations that would otherwise have `requires_grad=True`. | | In this mode, the result of every computation will have | `requires_grad=False`, even when the inputs have `requires_grad=True`. | There is an exception! All factory functions, or functions that create | a new Tensor and take a requires_grad kwarg, will NOT be affected by | this mode. | | This context manager is thread local; it will not affect computation | in other threads. | | Also functions as a decorator. | | .. note:: | No-grad is one of several mechanisms that can enable or | disable gradients locally see :ref:`locally-disable-grad-doc` for | more information on how they compare. | | .. note:: | This API does not apply to :ref:`forward-mode AD <forward-mode-ad>`. | If you want to disable forward AD for a computation, you can unpack | your dual tensors. | | Example:: | >>> # xdoctest: +SKIP | >>> x = torch.tensor([1.], requires_grad=True) | >>> with torch.no_grad(): | ... y = x * 2 | >>> y.requires_grad | False | >>> @torch.no_grad() | ... def doubler(x): | ... return x * 2 | >>> z = doubler(x) | >>> z.requires_grad | False | >>> @torch.no_grad() | ... def tripler(x): | ... return x * 3 | >>> z = tripler(x) | >>> z.requires_grad | False | >>> # factory function exception | >>> with torch.no_grad(): | ... a = torch.nn.Parameter(torch.rand(10)) | >>> a.requires_grad | True | | Method resolution order: | no_grad | torch.utils._contextlib._NoParamDecoratorContextManager | torch.utils._contextlib._DecoratorContextManager | builtins.object | | Methods defined here: | | __enter__(self) -> None | | __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None | | __init__(self) -> None | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods inherited from torch.utils._contextlib._NoParamDecoratorContextManager: | | __new__(cls, orig_func: Optional[~F] = None) -> Union[Self, ~F] | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from torch.utils._contextlib._DecoratorContextManager: | | __call__(self, orig_func: ~F) -> ~F | Call self as a function. | | clone(self) | | ---------------------------------------------------------------------- | Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
torch.nonzero
Python Library Documentation: built-in function nonzero in module torch
nonzero(...)
nonzero(input, *, out=None, as_tuple=False) -> LongTensor or tuple of LongTensors
.. note::
:func:`torch.nonzero(..., as_tuple=False) <torch.nonzero>` (default) returns a
2-D tensor where each row is the index for a nonzero value.
:func:`torch.nonzero(..., as_tuple=True) <torch.nonzero>` returns a tuple of 1-D
index tensors, allowing for advanced indexing, so ``x[x.nonzero(as_tuple=True)]``
gives all nonzero values of tensor ``x``. Of the returned tuple, each index tensor
contains nonzero indices for a certain dimension.
See below for more details on the two behaviors.
When :attr:`input` is on CUDA, :func:`torch.nonzero() <torch.nonzero>` causes
host-device synchronization.
**When** :attr:`as_tuple` **is** ``False`` **(default)**:
Returns a tensor containing the indices of all non-zero elements of
:attr:`input`. Each row in the result contains the indices of a non-zero
element in :attr:`input`. The result is sorted lexicographically, with
the last index changing the fastest (C-style).
If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
:attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
non-zero elements in the :attr:`input` tensor.
**When** :attr:`as_tuple` **is** ``True``:
Returns a tuple of 1-D tensors, one for each dimension in :attr:`input`,
each containing the indices (in that dimension) of all non-zero elements of
:attr:`input` .
If :attr:`input` has :math:`n` dimensions, then the resulting tuple contains :math:`n`
tensors of size :math:`z`, where :math:`z` is the total number of
non-zero elements in the :attr:`input` tensor.
As a special case, when :attr:`input` has zero dimensions and a nonzero scalar
value, it is treated as a one-dimensional tensor with one element.
Args:
input (Tensor): the input tensor.
Keyword args:
out (LongTensor, optional): the output tensor containing indices
Returns:
LongTensor or tuple of LongTensor: If :attr:`as_tuple` is ``False``, the output
tensor containing indices. If :attr:`as_tuple` is ``True``, one 1-D tensor for
each dimension, containing the indices of each nonzero element along that
dimension.
Example::
>>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]))
tensor([[ 0],
[ 1],
[ 2],
[ 4]])
>>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
... [0.0, 0.4, 0.0, 0.0],
... [0.0, 0.0, 1.2, 0.0],
... [0.0, 0.0, 0.0,-0.4]]))
tensor([[ 0, 0],
[ 1, 1],
[ 2, 2],
[ 3, 3]])
>>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]), as_tuple=True)
(tensor([0, 1, 2, 4]),)
>>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
... [0.0, 0.4, 0.0, 0.0],
... [0.0, 0.0, 1.2, 0.0],
... [0.0, 0.0, 0.0,-0.4]]), as_tuple=True)
(tensor([0, 1, 2, 3]), tensor([0, 1, 2, 3]))
>>> torch.nonzero(torch.tensor(5), as_tuple=True)
(tensor([0]),)
torch.nonzero_static
Python Library Documentation: built-in function nonzero_static in module torch
nonzero_static(...)
nonzero_static(input, *, size, fill_value=-1) -> Tensor
Returns a 2-D tensor where each row is the index for a non-zero value.
The returned Tensor has the same `torch.dtype` as `torch.nonzero()`.
Args:
input (Tensor): the input tensor.
Keyword args:
size (int): the size of non-zero elements expected to be included in the out
tensor. Pad the out tensor with `fill_value` if the `size` is larger
than total number of non-zero elements, truncate out tensor if `size`
is smaller. The size must be a non-negative integer.
fill_value (int, optional): the value to fill the output tensor with when `size` is larger
than the total number of non-zero elements. Default is `-1` to represent
invalid index.
Example::
# Example 1: Padding
>>> input_tensor = torch.tensor([[1, 0], [3, 2]])
>>> static_size = 4
>>> t = torch.nonzero_static(input_tensor, size=static_size)
tensor([[ 0, 0],
[ 1, 0],
[ 1, 1],
[ -1, -1]], dtype=torch.int64)
# Example 2: Truncating
>>> input_tensor = torch.tensor([[1, 0], [3, 2]])
>>> static_size = 2
>>> t = torch.nonzero_static(input_tensor, size=static_size)
tensor([[ 0, 0],
[ 1, 0]], dtype=torch.int64)
# Example 3: 0 size
>>> input_tensor = torch.tensor([10])
>>> static_size = 0
>>> t = torch.nonzero_static(input_tensor, size=static_size)
tensor([], size=(0, 1), dtype=torch.int64)
# Example 4: 0 rank input
>>> input_tensor = torch.tensor(10)
>>> static_size = 2
>>> t = torch.nonzero_static(input_tensor, size=static_size)
tensor([], size=(2, 0), dtype=torch.int64)
torch.norm
Python Library Documentation: function norm in module torch.functional
norm(input, p: float | str | None = 'fro', dim=None, keepdim=False, out=None, dtype=None)
Returns the matrix norm or vector norm of a given tensor.
.. warning::
torch.norm is deprecated and may be removed in a future PyTorch release.
Its documentation and behavior may be incorrect, and it is no longer
actively maintained.
Use :func:`torch.linalg.vector_norm` when computing vector norms and
:func:`torch.linalg.matrix_norm` when computing matrix norms.
For a function with a similar behavior as this one see :func:`torch.linalg.norm`.
Note, however, the signature for these functions is slightly different than the
signature for ``torch.norm``.
Args:
input (Tensor): The input tensor. Its data type must be either a floating
point or complex type. For complex inputs, the norm is calculated using the
absolute value of each element. If the input is complex and neither
:attr:`dtype` nor :attr:`out` is specified, the result's data type will
be the corresponding floating point type (e.g. float if :attr:`input` is
complexfloat).
p (int, float, inf, -inf, 'fro', 'nuc', optional): the order of norm. Default: ``'fro'``
The following norms can be calculated:
====== ============== ==========================
ord matrix norm vector norm
====== ============== ==========================
'fro' Frobenius norm --
'nuc' nuclear norm --
Number -- sum(abs(x)**ord)**(1./ord)
====== ============== ==========================
The vector norm can be calculated across any number of dimensions.
The corresponding dimensions of :attr:`input` are flattened into
one dimension, and the norm is calculated on the flattened
dimension.
Frobenius norm produces the same result as ``p=2`` in all cases
except when :attr:`dim` is a list of three or more dims, in which
case Frobenius norm throws an error.
Nuclear norm can only be calculated across exactly two dimensions.
dim (int, tuple of ints, list of ints, optional):
Specifies which dimension or dimensions of :attr:`input` to
calculate the norm across. If :attr:`dim` is ``None``, the norm will
be calculated across all dimensions of :attr:`input`. If the norm
type indicated by :attr:`p` does not support the specified number of
dimensions, an error will occur.
keepdim (bool, optional): whether the output tensors have :attr:`dim`
retained or not. Ignored if :attr:`dim` = ``None`` and
:attr:`out` = ``None``. Default: ``False``
out (Tensor, optional): the output tensor. Ignored if
:attr:`dim` = ``None`` and :attr:`out` = ``None``.
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. If specified, the input tensor is casted to
:attr:`dtype` while performing the operation. Default: None.
.. note::
Even though ``p='fro'`` supports any number of dimensions, the true
mathematical definition of Frobenius norm only applies to tensors with
exactly two dimensions. :func:`torch.linalg.matrix_norm` with ``ord='fro'``
aligns with the mathematical definition, since it can only be applied across
exactly two dimensions.
Example::
>>> import torch
>>> a = torch.arange(9, dtype= torch.float) - 4
>>> b = a.reshape((3, 3))
>>> torch.norm(a)
tensor(7.7460)
>>> torch.norm(b)
tensor(7.7460)
>>> torch.norm(a, float('inf'))
tensor(4.)
>>> torch.norm(b, float('inf'))
tensor(4.)
>>> c = torch.tensor([[ 1, 2, 3], [-1, 1, 4]] , dtype=torch.float)
>>> torch.norm(c, dim=0)
tensor([1.4142, 2.2361, 5.0000])
>>> torch.norm(c, dim=1)
tensor([3.7417, 4.2426])
>>> torch.norm(c, p=1, dim=1)
tensor([6., 6.])
>>> d = torch.arange(8, dtype=torch.float).reshape(2, 2, 2)
>>> torch.norm(d, dim=(1, 2))
tensor([ 3.7417, 11.2250])
>>> torch.norm(d[0, :, :]), torch.norm(d[1, :, :])
(tensor(3.7417), tensor(11.2250))
torch.norm_except_dim
Python Library Documentation: built-in function norm_except_dim in module torch norm_except_dim(...)
torch.normal
Python Library Documentation: built-in function normal in module torch
normal(...)
normal(mean, std, *, generator=None, out=None) -> Tensor
Returns a tensor of random numbers drawn from separate normal distributions
whose mean and standard deviation are given.
The :attr:`mean` is a tensor with the mean of
each output element's normal distribution
The :attr:`std` is a tensor with the standard deviation of
each output element's normal distribution
The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
total number of elements in each tensor need to be the same.
.. note:: When the shapes do not match, the shape of :attr:`mean`
is used as the shape for the returned output tensor
.. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
its device with the CPU.
Args:
mean (float or Tensor): per-element mean(s). Only floating point types are supported.
std (float or Tensor): per-element standard deviation(s). Only floating point types are supported.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
Example::
>>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
8.0505, 8.1408, 9.0563, 10.0566])
.. function:: normal(mean=0.0, std, *, out=None) -> Tensor
:noindex:
Similar to the function above, but the means are shared among all drawn
elements.
Args:
mean (float, optional): the mean for all distributions
std (Tensor): the tensor of per-element standard deviations
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
.. function:: normal(mean, std=1.0, *, out=None) -> Tensor
:noindex:
Similar to the function above, but the standard deviations are shared among
all drawn elements.
Args:
mean (Tensor): the tensor of per-element means
std (float, optional): the standard deviation for all distributions
Keyword args:
out (Tensor, optional): the output tensor
Example::
>>> torch.normal(mean=torch.arange(1., 6.))
tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
.. function:: normal(mean, std, size, *, out=None) -> Tensor
:noindex:
Similar to the function above, but the means and standard deviations are shared
among all drawn elements. The resulting tensor has size given by :attr:`size`.
Args:
mean (float): the mean for all distributions
std (float): the standard deviation for all distributions
size (int...): a sequence of integers defining the shape of the output tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.normal(2, 3, size=(1, 4))
tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
torch.not_equal
Python Library Documentation: built-in function not_equal in module torch
not_equal(...)
not_equal(input, other, *, out=None) -> Tensor
Alias for :func:`torch.ne`.
torch.nuclear_norm
Python Library Documentation: built-in function nuclear_norm in module torch nuclear_norm(...)
torch.numel
Python Library Documentation: built-in function numel in module torch
numel(...)
numel(input: Tensor) -> int
Returns the total number of elements in the :attr:`input` tensor.
Args:
input (Tensor): the input tensor.
Example::
>>> a = torch.randn(1, 2, 3, 4, 5)
>>> torch.numel(a)
120
>>> a = torch.zeros(4,4)
>>> torch.numel(a)
16
torch.ones
Python Library Documentation: built-in function ones in module torch
ones(...)
ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a tensor filled with the scalar value `1`, with the shape defined
by the variable argument :attr:`size`.
Args:
size (int...): a sequence of integers defining the shape of the output tensor.
Can be a variable number of arguments or a collection like a list or tuple.
Keyword arguments:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.ones(2, 3)
tensor([[ 1., 1., 1.],
[ 1., 1., 1.]])
>>> torch.ones(5)
tensor([ 1., 1., 1., 1., 1.])
torch.ones_like
Python Library Documentation: built-in function ones_like in module torch
ones_like(...)
ones_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns a tensor filled with the scalar value `1`, with the same size as
:attr:`input`. ``torch.ones_like(input)`` is equivalent to
``torch.ones(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
.. warning::
As of 0.4, this function does not support an :attr:`out` keyword. As an alternative,
the old ``torch.ones_like(input, out=output)`` is equivalent to
``torch.ones(input.size(), out=output)``.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
Keyword arguments:
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
Example::
>>> input = torch.empty(2, 3)
>>> torch.ones_like(input)
tensor([[ 1., 1., 1.],
[ 1., 1., 1.]])
torch.ops
Python Library Documentation: package torch.ops in torch
NAME
torch.ops
PACKAGE CONTENTS
SUBMODULES
__all__
__path__
_fields
_native
aten
debug_mode_ops
debugprims
export
higher_order
inductor
mkl
mkldnn
onednn
prim
prims
profiler
quantized
rngprims
DATA
_dir = ['aten', 'profiler', 'inductor', 'quantized', 'prim', 'export',...
VERSION
<module 'torch.ops.__version__' from 'torch.ops'>
DATE
<module 'torch.ops.__date__' from 'torch.ops'>
AUTHOR
<module 'torch.ops.__author__' from 'torch.ops'>
CREDITS
<module 'torch.ops.__credits__' from 'torch.ops'>
FILE
f:\joeycodes\pydocs\_ops.py
torch.optim
Python Library Documentation: package torch.optim in torch
NAME
torch.optim - :mod:`torch.optim` is a package implementing various optimization algorithms.
DESCRIPTION
Most commonly used methods are already supported, and the interface is general
enough, so that more sophisticated ones can also be easily integrated in the
future.
PACKAGE CONTENTS
_adafactor
_functional
_multi_tensor (package)
_muon
_stateless
adadelta
adagrad
adam
adamax
adamw
asgd
lbfgs
lr_scheduler
nadam
optimizer
radam
rmsprop
rprop
sgd
sparse_adam
swa_utils
CLASSES
builtins.object
torch.optim.optimizer.Optimizer
Adafactor
Muon
torch.optim.adadelta.Adadelta
torch.optim.adagrad.Adagrad
torch.optim.adam.Adam
torch.optim.adamw.AdamW
torch.optim.adamax.Adamax
torch.optim.asgd.ASGD
torch.optim.lbfgs.LBFGS
torch.optim.nadam.NAdam
torch.optim.radam.RAdam
torch.optim.rmsprop.RMSprop
torch.optim.rprop.Rprop
torch.optim.sgd.SGD
torch.optim.sparse_adam.SparseAdam
class ASGD(torch.optim.optimizer.Optimizer)
| ASGD(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.01, lambd: float = 0.0001, alpha: float = 0.75, t0: float = 1000000.0, weight_decay: float = 0, foreach: bool | None = None, maximize: bool = False, differentiable: bool = False, capturable: bool = False) -> None
|
| Implements Averaged Stochastic Gradient Descent.
|
| It has been proposed in `Acceleration of stochastic approximation by
| averaging`_.
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, Tensor, optional): learning rate (default: 1e-2)
| lambd (float, optional): decay term (default: 1e-4)
| alpha (float, optional): power for eta update (default: 0.75)
| t0 (float, optional): point at which to start averaging (default: 1e6)
| weight_decay (float, optional): weight decay (L2 penalty) (default: 0)
| foreach (bool, optional): whether foreach implementation of optimizer
| is used. If unspecified by the user (so foreach is None), we will try to use
| foreach over the for-loop implementation on CUDA, since it is usually
| significantly more performant. Note that the foreach implementation uses
| ~ sizeof(params) more peak memory than the for-loop version due to the intermediates
| being a tensorlist vs just one tensor. If memory is prohibitive, batch fewer
| parameters through the optimizer at a time or switch this flag to False (default: None)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
| differentiable (bool, optional): whether autograd should
| occur through the optimizer step in training. Otherwise, the step()
| function runs in a torch.no_grad() context. Setting to True can impair
| performance, so leave it False if you don't intend to run autograd
| through this instance (default: False)
| capturable (bool, optional): whether this instance is safe to
| capture in a graph, whether for CUDA graphs or for torch.compile support.
| Tensors are only capturable when on supported :ref:`accelerators<accelerators>`.
| Passing True can impair ungraphed performance, so if you don't intend to graph
| capture this instance, leave it False (default: False)
|
| .. _Acceleration of stochastic approximation by averaging:
| https://meyn.ece.ufl.edu/wp-content/uploads/sites/77/archive/spm_files/Courses/ECE555-2011/555media/poljud92.pdf
|
| Method resolution order:
| ASGD
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.01, lambd: float = 0.0001, alpha: float = 0.75, t0: float = 1000000.0, weight_decay: float = 0, foreach: bool | None = None, maximize: bool = False, differentiable: bool = False, capturable: bool = False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state)
|
| step(self, closure=None)
| Perform a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class Adadelta(torch.optim.optimizer.Optimizer)
| Adadelta(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 1.0, rho: float = 0.9, eps: float = 1e-06, weight_decay: float = 0, foreach: bool | None = None, *, capturable: bool = False, maximize: bool = False, differentiable: bool = False) -> None
|
| Implements Adadelta algorithm.
|
| .. math::
| \begin{aligned}
| &\rule{110mm}{0.4pt} \\
| &\textbf{input} : \gamma \text{ (lr)}, \: \theta_0 \text{ (params)},
| \: f(\theta) \text{ (objective)}, \: \rho \text{ (decay)},
| \: \lambda \text{ (weight decay)} \\
| &\textbf{initialize} : v_0 \leftarrow 0 \: \text{ (square avg)},
| \: u_0 \leftarrow 0 \: \text{ (accumulate variables)} \\[-1.ex]
| &\rule{110mm}{0.4pt} \\
| &\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
| &\hspace{5mm}g_t \leftarrow \nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm}if \: \lambda \neq 0 \\
| &\hspace{10mm} g_t \leftarrow g_t + \lambda \theta_{t-1} \\
| &\hspace{5mm} v_t \leftarrow v_{t-1} \rho + g^2_t (1 - \rho) \\
| &\hspace{5mm}\Delta x_t \leftarrow \frac{\sqrt{u_{t-1} +
| \epsilon }}{ \sqrt{v_t + \epsilon} }g_t \hspace{21mm} \\
| &\hspace{5mm} u_t \leftarrow u_{t-1} \rho +
| \Delta x^2_t (1 - \rho) \\
| &\hspace{5mm}\theta_t \leftarrow \theta_{t-1} - \gamma \Delta x_t \\
| &\rule{110mm}{0.4pt} \\[-1.ex]
| &\bf{return} \: \theta_t \\[-1.ex]
| &\rule{110mm}{0.4pt} \\[-1.ex]
| \end{aligned}
|
| For further details regarding the algorithm we refer to `ADADELTA: An Adaptive Learning Rate Method`_.
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, Tensor, optional): coefficient that scale delta before it is applied
| to the parameters (default: 1.0)
| rho (float, optional): coefficient used for computing a running average
| of squared gradients (default: 0.9). A higher value of `rho` will
| result in a slower average, which can be helpful for preventing
| oscillations in the learning process.
| eps (float, optional): term added to the denominator to improve
| numerical stability (default: 1e-6).
| weight_decay (float, optional): weight decay (L2 penalty) (default: 0)
| foreach (bool, optional): whether foreach implementation of optimizer
| is used. If unspecified by the user (so foreach is None), we will try to use
| foreach over the for-loop implementation on CUDA, since it is usually
| significantly more performant. Note that the foreach implementation uses
| ~ sizeof(params) more peak memory than the for-loop version due to the intermediates
| being a tensorlist vs just one tensor. If memory is prohibitive, batch fewer
| parameters through the optimizer at a time or switch this flag to False (default: None)
| capturable (bool, optional): whether this instance is safe to
| capture in a graph, whether for CUDA graphs or for torch.compile support.
| Tensors are only capturable when on supported :ref:`accelerators<accelerators>`.
| Passing True can impair ungraphed performance, so if you don't intend to graph
| capture this instance, leave it False (default: False)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
| differentiable (bool, optional): whether autograd should
| occur through the optimizer step in training. Otherwise, the step()
| function runs in a torch.no_grad() context. Setting to True can impair
| performance, so leave it False if you don't intend to run autograd
| through this instance (default: False)
|
| .. _ADADELTA\: An Adaptive Learning Rate Method:
| https://arxiv.org/abs/1212.5701
|
| Method resolution order:
| Adadelta
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 1.0, rho: float = 0.9, eps: float = 1e-06, weight_decay: float = 0, foreach: bool | None = None, *, capturable: bool = False, maximize: bool = False, differentiable: bool = False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state)
|
| step(self, closure=None)
| Perform a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class Adafactor(torch.optim.optimizer.Optimizer)
| Adafactor(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.01, beta2_decay: float = -0.8, eps: tuple[float | None, float] = (None, 0.001), d: float = 1.0, weight_decay: float = 0.0, *, foreach: bool | None = None, maximize: bool = False) -> None
|
| Implements Adafactor algorithm.
|
| .. math::
| \begin{aligned}
| &\rule{110mm}{0.4pt} \\
| &\textbf{input} : \gamma \text{(lr)}, \: \tau
| \text{(}\beta_2\text{ decay)}, \: \theta_0 \text{(params)}, \: f(\theta) \text{(objective)}, \\
| &\hspace{15mm} \: \epsilon_1, \epsilon_2 \text{ (epsilons)}, \: d \text{(clipping threshold)}, \\
| &\hspace{15mm} \: \lambda \text{(weight decay)},
| \: \textit{maximize} \\
| &\textbf{initialize} : \: R_0 \leftarrow 0 \text{ (second moment row factor)}, \\
| &\hspace{23mm} \: C_0 \leftarrow 0 \text{ (second moment col factor)}, \\
| &\hspace{23mm} \: \widehat{V}_0 \leftarrow 0 \text{ (second moment for vectors)} \\[-1.ex]
| &\rule{110mm}{0.4pt} \\
| &\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
|
| &\hspace{5mm}\textbf{if} \: \textit{maximize}: \\
| &\hspace{10mm}G_t \leftarrow -\nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm}\textbf{else} \\
| &\hspace{10mm}G_t \leftarrow \nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm}\widehat{\beta}_{2_t} \leftarrow 1 - t^{\tau} \\
| &\hspace{5mm}\rho_t \leftarrow min(\gamma, \frac{1}{\sqrt{t}}) \\
| &\hspace{5mm}\alpha_t \leftarrow max(\epsilon_2,
| \text{RMS}(\theta_{t-1}))\rho_t \\
| &\hspace{5mm}\theta_t \leftarrow \theta_{t-1} - \gamma \lambda \theta_{t-1} \\
| &\hspace{5mm}\textbf{if} \: \text{dim}(G_t) > 1: \\
| &\hspace{10mm}R_t \leftarrow \widehat{\beta}_{2_t}R_{t-1}+
| (1-\widehat{\beta}_{2_t})(G_t \odot G_t) \cdot 1_m \\
| &\hspace{10mm}C_t \leftarrow \widehat{\beta}_{2_t}C_{t-1}+
| (1-\widehat{\beta}_{2_t}) 1^\top_n \cdot (G_t \odot G_t) \\
| &\hspace{10mm}\widehat{V}_t \leftarrow
| \frac{R_t \cdot C_t}{max(1^\top_n \cdot R_t, \epsilon_1)} \\
| &\hspace{5mm}\textbf{else} \\
| &\hspace{10mm}\widehat{V}_t \leftarrow \widehat{\beta}_{2_t}\widehat{V}_{t-1}+
| (1-\widehat{\beta}_{2_t}) \cdot (G_t \odot G_t) \\
| &\hspace{5mm}U_t \leftarrow
| \frac{G_t}{max(\sqrt{\widehat{V}_t}, \epsilon_1)} \\
| &\hspace{5mm}\widehat{U}_t \leftarrow \frac{U_t}{max(1, \frac{\text{RMS}(U_t)}{d})} \\
| &\hspace{5mm}\theta_t \leftarrow \theta_{t-1} - \alpha_t \widehat{U}_t \\
|
| &\rule{110mm}{0.4pt} \\[-1.ex]
| &\bf{return} \: \theta_t \\[-1.ex]
| &\rule{110mm}{0.4pt} \\[-1.ex]
| \end{aligned}
|
| For further details regarding the algorithm we refer to `Adafactor: Adaptive Learning Rates with Sublinear Memory Cost`_.
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, Tensor, optional): unlike other optimizers, Adafactor does not require a
| learning rate, and Noam Shazeer and Mitchell Stern do not use lr at all.
| Deviating from the paper, this implementation uses lr for applying weight
| decay and as the maximum value for relative step size rho_t. Note that in
| the paper, a constant of 0.01 is used as the maximum value for relative
| step size, and so we set 0.01 as the default value. (default: 1e-2)
| beta2_decay (float, optional): the decay rate of beta2. beta2 standardly refers
| to the coefficient used for computing the running average of the gradient
| squared. (default: -0.8)
| eps (Tuple[float, float], optional): epsilon1 is the term added to the denominator
| of the update calculation to improve numerical stability. This use of epsilon1
| deviates from the algorithm written in the paper! See note below for more details.
| epsilon2 is the term used to avoid having too small a weight update when applying
| parameter scaling. (default: (None, 1e-3))
| d (float, optional): the clipping threshold, used to avoid larger-than-desired
| updates.
| weight_decay (float, optional): weight decay coefficient (default: 1e-2)
| foreach (bool, optional): whether foreach implementation of optimizer is used. Note
| that the foreach implementation uses ~ sizeof(params) more peak memory than the
| for-loop version due to the intermediates being a tensorlist vs just one tensor.
| As Adafactor is commonly used when memory is prohibitive, Adafactor will default
| to the slower single tensor for-loop implementation unless this flag is explicitly
| True. This behavior is contrary to other optimizers, which will attempt defaulting
| to foreach on CUDA for faster runtime. (default: None)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
| .. Note::
| The implementation of Adafactor subtly differs from Noam Shazeer and Mitchell Stern
| and implementations in some other frameworks with its use of learning rate and
| :math:`\epsilon_1`.
|
| Regarding the learning rate hyperparameter: Noam Shazeer and Mitchell Stern do not
| use lr at all, as the stated algorithm uses :math:`\rho_t` and update clipping to
| affect the step size.
|
| This implementation allows `lr` to influence the maximum value for :math:`\rho_t`:
|
| .. math::
| \begin{aligned}
| &\hspace{5mm}\rho_t \leftarrow min(\gamma, \frac{1}{\sqrt{t}})
| \end{aligned}
|
| This differs from Noam Shazeer and Mitchell Stern, who use a constant of 0.01 as
| the maximum value of :math:`\rho_t`
|
| .. math::
| \begin{aligned}
| &\hspace{5mm}\rho_t \leftarrow min(0.01, \frac{1}{\sqrt{t}})
| \end{aligned}
|
| Noam Shazeer and Mitchell Stern do not enforce an opinion on how weight decay should
| be computed, and so we use the learning rate as a coefficient for decoupled weight
| decay, similar to what is suggested in `Decoupled Weight Decay Regularization`_.
|
| Regarding the use of :math:`\epsilon_1`: The implementation attempts to replicate the
| presumed intention of Noam Shazeer and Mitchell Stern to use :math:`\epsilon_1` as
| a stabilizing term when the squared gradient becomes small.
|
| This stabilization can be written as
|
| .. math::
| \begin{aligned}
| &\hspace{5mm}R_t \leftarrow \widehat{\beta}_{2_t}R_{t-1}+
| (1-\widehat{\beta}_{2_t})(G_t \odot G_t + 1_n \cdot 1^\top_m) \cdot 1_m \\
| &\hspace{5mm}C_t \leftarrow \widehat{\beta}_{2_t}C_{t-1}+
| (1-\widehat{\beta}_{2_t}) 1^\top_n \cdot (G_t \odot G_t + 1_n \cdot 1^\top_m) \\
| &\hspace{5mm}\widehat{V}_t \leftarrow
| \frac{R_t \cdot C_t}{max(1^\top_n \cdot R_t, \epsilon_1)} \\
| &\hspace{5mm}U_t \leftarrow \frac{G_t}{max(\sqrt{\widehat{V}_t}, \epsilon_1)} \\
| \end{aligned}
|
| where the row and column factors of gradient squared :math:`R_t` and :math:`C_t`
| are left alone, and we apply :math:`\epsilon_1` at the final calculation of
| the variance estimate :math:`\widehat{V}_t` and for the update :math:`U_t`.
|
| This is in contrast to Noam Shazeer and Mitchell Stern and other frameworks which
| apply :math:`\epsilon_1` to both row and column factors of the squared gradient, but
| not in the calculations after:
|
| .. math::
| \begin{aligned}
| &\hspace{5mm}R_t \leftarrow \widehat{\beta}_{2_t}R_{t-1}+
| (1-\widehat{\beta}_{2_t})(G_t \odot G_t + \epsilon_1 1_n \cdot 1^\top_m) \cdot 1_m \\
| &\hspace{5mm}C_t \leftarrow \widehat{\beta}_{2_t}C_{t-1}+
| (1-\widehat{\beta}_{2_t}) 1^\top_n \cdot (G_t \odot G_t + \epsilon_1 1_n \cdot 1^\top_m) \\
| &\hspace{5mm}\widehat{V}_t \leftarrow \frac{R_t \cdot C_t}{1^\top_n \cdot R_t} \\
| &\hspace{5mm}U_t \leftarrow \frac{G_t}{\sqrt{\widehat{V}_t}} \\
| \end{aligned}
|
| You may note that Noam Shazeer and Mitchell Stern describe using the sum of squared gradients,
| while this implementation uses the mean instead. This choice is mathematically equivalent and
| allows for greater numerical stability for large sums.
|
| .. _Adafactor\: Adaptive Learning Rates with Sublinear Memory Cost:
| https://arxiv.org/pdf/1804.04235
| .. _Decoupled Weight Decay Regularization:
| https://arxiv.org/abs/1711.05101
|
| Method resolution order:
| Adafactor
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.01, beta2_decay: float = -0.8, eps: tuple[float | None, float] = (None, 0.001), d: float = 1.0, weight_decay: float = 0.0, *, foreach: bool | None = None, maximize: bool = False) -> None from torch.optim._adafactor.Adafactor
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state) from torch.optim._adafactor.Adafactor
|
| step(self, closure=None) from torch.optim._adafactor.Adafactor
| Perform a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class Adagrad(torch.optim.optimizer.Optimizer)
| Adagrad(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.01, lr_decay: float = 0, weight_decay: float = 0, initial_accumulator_value: float = 0, eps: float = 1e-10, foreach: bool | None = None, *, maximize: bool = False, differentiable: bool = False, fused: bool | None = None) -> None
|
| Implements Adagrad algorithm.
|
| .. math::
| \begin{aligned}
| &\rule{110mm}{0.4pt} \\
| &\textbf{input} : \gamma \text{ (lr)}, \: \theta_0 \text{ (params)}, \: f(\theta)
| \text{ (objective)}, \: \lambda \text{ (weight decay)}, \\
| &\hspace{12mm} \tau \text{ (initial accumulator value)}, \: \eta\text{ (lr decay)}\\
| &\textbf{initialize} : state\_sum_0 \leftarrow \tau \\[-1.ex]
| &\rule{110mm}{0.4pt} \\
| &\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
| &\hspace{5mm}g_t \leftarrow \nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm} \tilde{\gamma} \leftarrow \gamma / (1 +(t-1) \eta) \\
| &\hspace{5mm} \textbf{if} \: \lambda \neq 0 \\
| &\hspace{10mm} g_t \leftarrow g_t + \lambda \theta_{t-1} \\
| &\hspace{5mm}state\_sum_t \leftarrow state\_sum_{t-1} + g^2_t \\
| &\hspace{5mm}\theta_t \leftarrow
| \theta_{t-1}- \tilde{\gamma} \frac{g_t}{\sqrt{state\_sum_t}+\epsilon} \\
| &\rule{110mm}{0.4pt} \\[-1.ex]
| &\bf{return} \: \theta_t \\[-1.ex]
| &\rule{110mm}{0.4pt} \\[-1.ex]
| \end{aligned}
|
| For further details regarding the algorithm we refer to `Adaptive Subgradient Methods for Online Learning
| and Stochastic Optimization`_.
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, Tensor, optional): learning rate (default: 1e-2)
| lr_decay (float, optional): learning rate decay (default: 0)
| weight_decay (float, optional): weight decay (L2 penalty) (default: 0)
| initial_accumulator_value (float, optional): initial value of the
| sum of squares of gradients (default: 0)
| eps (float, optional): term added to the denominator to improve
| numerical stability (default: 1e-10)
| foreach (bool, optional): whether foreach implementation of optimizer
| is used. If unspecified by the user (so foreach is None), we will try to use
| foreach over the for-loop implementation on CUDA, since it is usually
| significantly more performant. Note that the foreach implementation uses
| ~ sizeof(params) more peak memory than the for-loop version due to the intermediates
| being a tensorlist vs just one tensor. If memory is prohibitive, batch fewer
| parameters through the optimizer at a time or switch this flag to False (default: None)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
| differentiable (bool, optional): whether autograd should
| occur through the optimizer step in training. Otherwise, the step()
| function runs in a torch.no_grad() context. Setting to True can impair
| performance, so leave it False if you don't intend to run autograd
| through this instance (default: False)
| fused (bool, optional): whether the fused implementation (CPU and CUDA only) is used.
| Currently, `torch.float64`, `torch.float32`, `torch.float16`, and `torch.bfloat16`
| are supported. (default: None). Please note that the fused implementation does not
| support sparse or complex gradients.
| .. _Adaptive Subgradient Methods for Online Learning and Stochastic
| Optimization: http://jmlr.org/papers/v12/duchi11a.html
|
| Method resolution order:
| Adagrad
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.01, lr_decay: float = 0, weight_decay: float = 0, initial_accumulator_value: float = 0, eps: float = 1e-10, foreach: bool | None = None, *, maximize: bool = False, differentiable: bool = False, fused: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state)
|
| share_memory(self) -> None
| Calls tensor.share_memory_() on the state sum tensors.
|
| step(self, closure=None)
| Perform a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class Adam(torch.optim.optimizer.Optimizer)
| Adam(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.001, betas: tuple[float | torch.Tensor, float | torch.Tensor] = (0.9, 0.999), eps: float = 1e-08, weight_decay: float = 0, amsgrad: bool = False, *, foreach: bool | None = None, maximize: bool = False, capturable: bool = False, differentiable: bool = False, fused: bool | None = None, decoupled_weight_decay: bool = False) -> None
|
| Implements Adam algorithm.
|
| .. math::
| \begin{aligned}
| &\rule{110mm}{0.4pt} \\
| &\textbf{input} : \gamma \text{ (lr)}, \beta_1, \beta_2
| \text{ (betas)},\theta_0 \text{ (params)},f(\theta) \text{ (objective)} \\
| &\hspace{13mm} \lambda \text{ (weight decay)}, \: \textit{amsgrad},
| \:\textit{maximize}, \: \epsilon \text{ (epsilon)} \\
| &\textbf{initialize} : m_0 \leftarrow 0 \text{ ( first moment)},
| v_0\leftarrow 0 \text{ (second moment)},\: v_0^{max}\leftarrow 0 \\[-1.ex]
| &\rule{110mm}{0.4pt} \\
| &\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
|
| &\hspace{5mm}\textbf{if} \: \textit{maximize}: \\
| &\hspace{10mm}g_t \leftarrow -\nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm}\textbf{else} \\
| &\hspace{10mm}g_t \leftarrow \nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm}\textbf{if} \: \lambda \neq 0 \\
| &\hspace{10mm} g_t \leftarrow g_t + \lambda \theta_{t-1} \\
| &\hspace{5mm}m_t \leftarrow \beta_1 m_{t-1} + (1 - \beta_1) g_t \\
| &\hspace{5mm}v_t \leftarrow \beta_2 v_{t-1} + (1-\beta_2) g^2_t \\
| &\hspace{5mm}\widehat{m_t} \leftarrow m_t/\big(1-\beta_1^t \big) \\
| &\hspace{5mm}\textbf{if} \: amsgrad \\
| &\hspace{10mm} v_t^{max} \leftarrow \mathrm{max}(v_{t-1}^{max},v_t) \\
| &\hspace{10mm}\widehat{v_t} \leftarrow v_t^{max}/\big(1-\beta_2^t \big) \\
| &\hspace{5mm}\textbf{else} \\
| &\hspace{10mm}\widehat{v_t} \leftarrow v_t/\big(1-\beta_2^t \big) \\
| &\hspace{5mm}\theta_t \leftarrow \theta_{t-1} - \gamma \widehat{m_t}/
| \big(\sqrt{\widehat{v_t}} + \epsilon \big) \\
| &\rule{110mm}{0.4pt} \\[-1.ex]
| &\bf{return} \: \theta_t \\[-1.ex]
| &\rule{110mm}{0.4pt} \\[-1.ex]
| \end{aligned}
|
| For further details regarding the algorithm we refer to `Adam: A Method for Stochastic Optimization`_.
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, Tensor, optional): learning rate (default: 1e-3). A tensor LR
| is not yet supported for all our implementations. Please use a float
| LR if you are not also specifying fused=True or capturable=True.
| betas (tuple[float | Tensor, float | Tensor], optional):
| coefficients used for computing running averages of gradient and
| its square. If a tensor is provided, must be 1-element. (default: (0.9, 0.999))
| eps (float, optional): term added to the denominator to improve
| numerical stability (default: 1e-8)
| weight_decay (float, optional): weight decay (L2 penalty) (default: 0)
| decoupled_weight_decay (bool, optional): if True, this optimizer is
| equivalent to AdamW and the algorithm will not accumulate weight
| decay in the momentum nor variance. (default: False)
| amsgrad (bool, optional): whether to use the AMSGrad variant of this
| algorithm from the paper `On the Convergence of Adam and Beyond`_
| (default: False)
| foreach (bool, optional): whether foreach implementation of optimizer
| is used. If unspecified by the user (so foreach is None), we will try to use
| foreach over the for-loop implementation on CUDA, since it is usually
| significantly more performant. Note that the foreach implementation uses
| ~ sizeof(params) more peak memory than the for-loop version due to the intermediates
| being a tensorlist vs just one tensor. If memory is prohibitive, batch fewer
| parameters through the optimizer at a time or switch this flag to False (default: None)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
| capturable (bool, optional): whether this instance is safe to
| capture in a graph, whether for CUDA graphs or for torch.compile support.
| Tensors are only capturable when on supported :ref:`accelerators<accelerators>`.
| Passing True can impair ungraphed performance, so if you don't intend to graph
| capture this instance, leave it False (default: False)
| differentiable (bool, optional): whether autograd should
| occur through the optimizer step in training. Otherwise, the step()
| function runs in a torch.no_grad() context. Setting to True can impair
| performance, so leave it False if you don't intend to run autograd
| through this instance (default: False)
| fused (bool, optional): whether the fused implementation is used.
| Currently, `torch.float64`, `torch.float32`, `torch.float16`, and `torch.bfloat16`
| are supported. (default: None)
|
| .. note:: The foreach and fused implementations are typically faster than the for-loop,
| single-tensor implementation, with fused being theoretically fastest with both
| vertical and horizontal fusion. As such, if the user has not specified either
| flag (i.e., when foreach = fused = None), we will attempt defaulting to the foreach
| implementation when the tensors are all on CUDA. Why not fused? Since the fused
| implementation is relatively new, we want to give it sufficient bake-in time.
| To specify fused, pass True for fused. To force running the for-loop
| implementation, pass False for either foreach or fused.
| .. Note::
| A prototype implementation of Adam and AdamW for MPS supports `torch.float32` and `torch.float16`.
| .. _Adam\: A Method for Stochastic Optimization:
| https://arxiv.org/abs/1412.6980
| .. _On the Convergence of Adam and Beyond:
| https://openreview.net/forum?id=ryQu7f-RZ
|
| Method resolution order:
| Adam
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.001, betas: tuple[float | torch.Tensor, float | torch.Tensor] = (0.9, 0.999), eps: float = 1e-08, weight_decay: float = 0, amsgrad: bool = False, *, foreach: bool | None = None, maximize: bool = False, capturable: bool = False, differentiable: bool = False, fused: bool | None = None, decoupled_weight_decay: bool = False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state)
|
| step(self, closure=None)
| Perform a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class AdamW(torch.optim.adam.Adam)
| AdamW(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.001, betas: tuple[float | torch.Tensor, float | torch.Tensor] = (0.9, 0.999), eps: float = 1e-08, weight_decay: float = 0.01, amsgrad: bool = False, *, maximize: bool = False, foreach: bool | None = None, capturable: bool = False, differentiable: bool = False, fused: bool | None = None) -> None
|
| Implements AdamW algorithm, where weight decay does not accumulate in the momentum nor variance.
|
| .. math::
| \begin{aligned}
| &\rule{110mm}{0.4pt} \\
| &\textbf{input} : \gamma \text{(lr)}, \: \beta_1, \beta_2
| \text{(betas)}, \: \theta_0 \text{(params)}, \: f(\theta) \text{(objective)},
| \: \epsilon \text{ (epsilon)} \\
| &\hspace{13mm} \lambda \text{(weight decay)}, \: \textit{amsgrad},
| \: \textit{maximize} \\
| &\textbf{initialize} : m_0 \leftarrow 0 \text{ (first moment)}, v_0 \leftarrow 0
| \text{ ( second moment)}, \: v_0^{max}\leftarrow 0 \\[-1.ex]
| &\rule{110mm}{0.4pt} \\
| &\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
|
| &\hspace{5mm}\textbf{if} \: \textit{maximize}: \\
| &\hspace{10mm}g_t \leftarrow -\nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm}\textbf{else} \\
| &\hspace{10mm}g_t \leftarrow \nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm} \theta_t \leftarrow \theta_{t-1} - \gamma \lambda \theta_{t-1} \\
| &\hspace{5mm}m_t \leftarrow \beta_1 m_{t-1} + (1 - \beta_1) g_t \\
| &\hspace{5mm}v_t \leftarrow \beta_2 v_{t-1} + (1-\beta_2) g^2_t \\
| &\hspace{5mm}\widehat{m_t} \leftarrow m_t/\big(1-\beta_1^t \big) \\
| &\hspace{5mm}\textbf{if} \: amsgrad \\
| &\hspace{10mm} v_t^{max} \leftarrow \mathrm{max}(v_{t-1}^{max},v_t) \\
| &\hspace{10mm}\widehat{v_t} \leftarrow v_t^{max}/\big(1-\beta_2^t \big) \\
| &\hspace{5mm}\textbf{else} \\
| &\hspace{10mm}\widehat{v_t} \leftarrow v_t/\big(1-\beta_2^t \big) \\
| &\hspace{5mm}\theta_t \leftarrow \theta_t - \gamma \widehat{m_t}/
| \big(\sqrt{\widehat{v_t}} + \epsilon \big) \\
| &\rule{110mm}{0.4pt} \\[-1.ex]
| &\bf{return} \: \theta_t \\[-1.ex]
| &\rule{110mm}{0.4pt} \\[-1.ex]
| \end{aligned}
|
| For further details regarding the algorithm we refer to `Decoupled Weight Decay Regularization`_.
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, Tensor, optional): learning rate (default: 1e-3). A tensor LR
| is not yet supported for all our implementations. Please use a float
| LR if you are not also specifying fused=True or capturable=True.
| betas (tuple[float | Tensor, float | Tensor], optional):
| coefficients used for computing running averages of gradient and
| its square. If a tensor is provided, must be 1-element. (default: (0.9, 0.999))
| eps (float, optional): term added to the denominator to improve
| numerical stability (default: 1e-8)
| weight_decay (float, optional): weight decay coefficient (default: 1e-2)
| amsgrad (bool, optional): whether to use the AMSGrad variant of this
| algorithm from the paper `On the Convergence of Adam and Beyond`_
| (default: False)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
| foreach (bool, optional): whether foreach implementation of optimizer
| is used. If unspecified by the user (so foreach is None), we will try to use
| foreach over the for-loop implementation on CUDA, since it is usually
| significantly more performant. Note that the foreach implementation uses
| ~ sizeof(params) more peak memory than the for-loop version due to the intermediates
| being a tensorlist vs just one tensor. If memory is prohibitive, batch fewer
| parameters through the optimizer at a time or switch this flag to False (default: None)
| capturable (bool, optional): whether this instance is safe to
| capture in a graph, whether for CUDA graphs or for torch.compile support.
| Tensors are only capturable when on supported :ref:`accelerators<accelerators>`.
| Passing True can impair ungraphed performance, so if you don't intend to graph
| capture this instance, leave it False (default: False)
| differentiable (bool, optional): whether autograd should
| occur through the optimizer step in training. Otherwise, the step()
| function runs in a torch.no_grad() context. Setting to True can impair
| performance, so leave it False if you don't intend to run autograd
| through this instance (default: False)
| fused (bool, optional): whether the fused implementation is used.
| Currently, `torch.float64`, `torch.float32`, `torch.float16`, and `torch.bfloat16`
| are supported. (default: None)
|
| .. note:: The foreach and fused implementations are typically faster than the for-loop,
| single-tensor implementation, with fused being theoretically fastest with both
| vertical and horizontal fusion. As such, if the user has not specified either
| flag (i.e., when foreach = fused = None), we will attempt defaulting to the foreach
| implementation when the tensors are all on CUDA. Why not fused? Since the fused
| implementation is relatively new, we want to give it sufficient bake-in time.
| To specify fused, pass True for fused. To force running the for-loop
| implementation, pass False for either foreach or fused.
| .. Note::
| A prototype implementation of Adam and AdamW for MPS supports `torch.float32` and `torch.float16`.
| .. _Decoupled Weight Decay Regularization:
| https://arxiv.org/abs/1711.05101
| .. _On the Convergence of Adam and Beyond:
| https://openreview.net/forum?id=ryQu7f-RZ
|
| Method resolution order:
| AdamW
| torch.optim.adam.Adam
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.001, betas: tuple[float | torch.Tensor, float | torch.Tensor] = (0.9, 0.999), eps: float = 1e-08, weight_decay: float = 0.01, amsgrad: bool = False, *, maximize: bool = False, foreach: bool | None = None, capturable: bool = False, differentiable: bool = False, fused: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state)
| # Preserve decoupled_weight_decay from AdamW for backwards compatibility. The following
| # guarantees that decoupled_weight_decay will always be True for loading any state into
| # AdamW
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.adam.Adam:
|
| step(self, closure=None)
| Perform a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class Adamax(torch.optim.optimizer.Optimizer)
| Adamax(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.002, betas: tuple[float, float] = (0.9, 0.999), eps: float = 1e-08, weight_decay: float = 0, foreach: bool | None = None, *, maximize: bool = False, differentiable: bool = False, capturable: bool = False) -> None
|
| Implements Adamax algorithm (a variant of Adam based on infinity norm).
|
| .. math::
| \begin{aligned}
| &\rule{110mm}{0.4pt} \\
| &\textbf{input} : \gamma \text{ (lr)}, \beta_1, \beta_2
| \text{ (betas)},\theta_0 \text{ (params)},f(\theta) \text{ (objective)},
| \: \lambda \text{ (weight decay)}, \\
| &\hspace{13mm} \epsilon \text{ (epsilon)} \\
| &\textbf{initialize} : m_0 \leftarrow 0 \text{ ( first moment)},
| u_0 \leftarrow 0 \text{ ( infinity norm)} \\[-1.ex]
| &\rule{110mm}{0.4pt} \\
| &\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
| &\hspace{5mm}g_t \leftarrow \nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm}if \: \lambda \neq 0 \\
| &\hspace{10mm} g_t \leftarrow g_t + \lambda \theta_{t-1} \\
| &\hspace{5mm}m_t \leftarrow \beta_1 m_{t-1} + (1 - \beta_1) g_t \\
| &\hspace{5mm}u_t \leftarrow \mathrm{max}(\beta_2 u_{t-1}, |g_{t}|+\epsilon) \\
| &\hspace{5mm}\theta_t \leftarrow \theta_{t-1} - \frac{\gamma m_t}{(1-\beta^t_1) u_t} \\
| &\rule{110mm}{0.4pt} \\[-1.ex]
| &\bf{return} \: \theta_t \\[-1.ex]
| &\rule{110mm}{0.4pt} \\[-1.ex]
| \end{aligned}
|
| For further details regarding the algorithm we refer to `Adam: A Method for Stochastic Optimization`_.
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, Tensor, optional): learning rate (default: 2e-3)
| betas (Tuple[float, float], optional): coefficients used for computing
| running averages of gradient and its square
| eps (float, optional): term added to the denominator to improve
| numerical stability (default: 1e-8)
| weight_decay (float, optional): weight decay (L2 penalty) (default: 0)
| foreach (bool, optional): whether foreach implementation of optimizer
| is used. If unspecified by the user (so foreach is None), we will try to use
| foreach over the for-loop implementation on CUDA, since it is usually
| significantly more performant. Note that the foreach implementation uses
| ~ sizeof(params) more peak memory than the for-loop version due to the intermediates
| being a tensorlist vs just one tensor. If memory is prohibitive, batch fewer
| parameters through the optimizer at a time or switch this flag to False (default: None)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
| differentiable (bool, optional): whether autograd should
| occur through the optimizer step in training. Otherwise, the step()
| function runs in a torch.no_grad() context. Setting to True can impair
| performance, so leave it False if you don't intend to run autograd
| through this instance (default: False)
| capturable (bool, optional): whether this instance is safe to
| capture in a graph, whether for CUDA graphs or for torch.compile support.
| Tensors are only capturable when on supported :ref:`accelerators<accelerators>`.
| Passing True can impair ungraphed performance, so if you don't intend to graph
| capture this instance, leave it False (default: False)
|
| .. _Adam\: A Method for Stochastic Optimization:
| https://arxiv.org/abs/1412.6980
|
| Method resolution order:
| Adamax
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.002, betas: tuple[float, float] = (0.9, 0.999), eps: float = 1e-08, weight_decay: float = 0, foreach: bool | None = None, *, maximize: bool = False, differentiable: bool = False, capturable: bool = False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state)
|
| step(self, closure=None)
| Performs a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class LBFGS(torch.optim.optimizer.Optimizer)
| LBFGS(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 1, max_iter: int = 20, max_eval: int | None = None, tolerance_grad: float = 1e-07, tolerance_change: float = 1e-09, history_size: int = 100, line_search_fn: str | None = None) -> None
|
| Implements L-BFGS algorithm.
|
| Heavily inspired by `minFunc
| <https://www.cs.ubc.ca/~schmidtm/Software/minFunc.html>`_.
|
| .. warning::
| This optimizer doesn't support per-parameter options and parameter
| groups (there can be only one).
|
| .. warning::
| Right now all parameters have to be on a single device. This will be
| improved in the future.
|
| .. note::
| This is a very memory intensive optimizer (it requires additional
| ``param_bytes * (history_size + 1)`` bytes). If it doesn't fit in memory
| try reducing the history size, or use a different algorithm.
|
| Args:
| params (iterable): iterable of parameters to optimize. Parameters must be real.
| lr (float, optional): learning rate (default: 1)
| max_iter (int, optional): maximal number of iterations per optimization step
| (default: 20)
| max_eval (int, optional): maximal number of function evaluations per optimization
| step (default: max_iter * 1.25).
| tolerance_grad (float, optional): termination tolerance on first order optimality
| (default: 1e-7).
| tolerance_change (float, optional): termination tolerance on function
| value/parameter changes (default: 1e-9).
| history_size (int, optional): update history size (default: 100).
| line_search_fn (str, optional): either 'strong_wolfe' or None (default: None).
|
| Method resolution order:
| LBFGS
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 1, max_iter: int = 20, max_eval: int | None = None, tolerance_grad: float = 1e-07, tolerance_change: float = 1e-09, history_size: int = 100, line_search_fn: str | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| step(self, closure)
| Perform a single optimization step.
|
| Args:
| closure (Callable): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setstate__(self, state: dict[str, typing.Any]) -> None
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class Muon(torch.optim.optimizer.Optimizer)
| Muon(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float = 0.001, weight_decay: float = 0.1, momentum: float = 0.95, nesterov: bool = True, ns_coefficients: tuple[float, float, float] = (3.4445, -4.775, 2.0315), eps: float = 1e-07, ns_steps: int = 5, adjust_lr_fn: str | None = None) -> None
|
| Implements Muon algorithm.
|
| .. math::
| \begin{aligned}
| &\rule{110mm}{0.4pt} \\
| &\textbf{input} : \gamma \text{ (lr)},\ \lambda \text{ (weight decay)},\
| \mu \text{ (momentum)},\ \textit{nesterov}\in\{True,False\},\\
| &\hspace{13mm}(a,b,c)\ \text{ (NS coefficients)},\
| \varepsilon \text{ (epsilon)},\ k \text{ (NS steps)},\
| \theta_0 \text{ (params)},\ f(\theta) \text{ (objective)} \\
| &\textbf{initialize} : B_0 \leftarrow 0 \text{ (momentum buffer)} \\[-1.ex]
| &\rule{110mm}{0.4pt} \\
| &\textbf{for}\ t=1\ \textbf{to}\ \ldots\ \textbf{do} \\[0.25ex]
| &\hspace{5mm} g_t \leftarrow \nabla_{\theta} f_t(\theta_{t-1}) \\[0.25ex]
| &\hspace{5mm} B_t \leftarrow \mu B_{t-1} + g_t \\[0.25ex]
| &\hspace{5mm} \widetilde{B}_t \leftarrow
| \begin{cases}
| g_t + \mu B_t, & \text{if nesterov}=True \\
| B_t, & \text{if nesterov}=False
| \end{cases} \\[1.0ex]
| &\hspace{5mm} O_t \leftarrow \mathrm{NS}^{(a,b,c)}_{k}\!\big(\widetilde{B}_t;\ \varepsilon\big) \\[0.5ex]
| &\hspace{5mm} \theta_t \leftarrow \theta_{t-1} - \gamma\,\lambda\,\theta_{t-1}
| \quad\text{(decoupled weight decay)} \\[0.25ex]
|
| &\hspace{5mm} \gamma \leftarrow \mathrm{AdjustLR}\!\big(\gamma;\ \mathrm{shape}\!\big(\theta_t \big) \big) \\[0.25ex]
| &\hspace{5mm} \theta_t \leftarrow \theta_t - \gamma\, O_t \\
| &\rule{110mm}{0.4pt} \\[-1.ex]
| &\mathbf{return}\ \theta_t \\[-1.ex]
| &\rule{110mm}{0.4pt}s
| \end{aligned}
|
| Here, :math:`\mathrm{NS}^{(a,b,c)}_{k}(\cdot;\varepsilon)` denotes :math:`k` iterations of the
| Newton–Schulz orthogonalization operator parameterized by coefficients :math:`(a,b,c)`
| with numerical stabilization :math:`\varepsilon`.
|
| The purpose for :math:`\mathrm{AdjustLR}\!\big(\gamma;\ \mathrm{shape}\!\big(\theta_t \big) \big)`
| is to make the orthogonalized update have a consistent :math:`RMS` across rectangular matrices.
|
| Keller's original implementation scales the update by :math:`\sqrt{\max\!\left(1, \frac{A}{B}\right)}`,
| where :math:`A` and :math:`B` are dimension of the matrix being optimized.
|
| Moonshot's implementation also focuses on matching :math:`RMS` of AdamW. The adjustment is computed as:
| :math:`\gamma \leftarrow {0.2}\gamma\,\sqrt{\max\!\left({A}, {B}\right)}`
| The method is adopted from `Muon is Scalable for LLM Training`_. Research
| results show that with this adjustment Muon can directly reuse the learning rate
| and weight decay tuned for AdamW.
|
| We provide two options for the learning rate adjustment: "original", which follows Keller's
| implementation, and "match_rms_adamw", which refers to Moonshot's implementation. This gives users the
| flexibility to choose between the two. If `adjust_lr_fn` is not specified, the default is "original".
|
| For further details regarding the algorithm we refer to `Muon: An optimizer for hidden layers in neural networks`_
| and `Muon is Scalable for LLM Training`_.
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named. Note that Muon is an optimizer for 2D parameters of neural network hidden layers. Other
| parameters, such as bias, and embedding, should be optimized by a standard method such as AdamW.
| lr (float, Tensor, optional): learning rate (default: 1e-3).
| weight_decay (float, optional): weight decay (L2 penalty). (default: 0.1)
| momentum (float, optional): momentum factor (default: 0.95)
| nesterov (bool, optional): enables Nesterov momentum. Only applicable
| when momentum is non-zero
| ns_coefficients (tuple of three floats, optional): coefficients \(a,b,c\) for the
| Newton–Schulz orthogonalization polynomial (default: (3.4445, -4.775, 2.0315))
| eps (float, optional): term added to the denominator for numerical stability. (default: 1e-07)
| ns_steps (int, optional): number of Newton–Schulz iteration steps. (default: 5)
| adjust_lr_fn (str, optional): function to adjust learning rate. One of "original" and "match_rms_adamw".
| If not specified, we will default to use "original". (default: None)
|
| Example:
| >>> # xdoctest: +SKIP
| >>> # Muon only supports 2D params; use a standard optimizer
| >>> # such as AdamW for biases, embeddings, and other non-2D
| >>> # parameters.
| >>> muon_params = [
| ... p for p in model.parameters() if p.ndim == 2
| ... ]
| >>> other_params = [
| ... p for p in model.parameters() if p.ndim != 2
| ... ]
| >>> optim_muon = torch.optim.Muon(
| ... muon_params, lr=0.02, momentum=0.95
| ... )
| >>> optim_adamw = torch.optim.AdamW(
| ... other_params, lr=3e-4, weight_decay=0.01
| ... )
| >>> optim_muon.zero_grad()
| >>> optim_adamw.zero_grad()
| >>> loss_fn(model(input), target).backward()
| >>> optim_muon.step()
| >>> optim_adamw.step()
|
| .. _Muon\: An optimizer for hidden layers in neural networks:
| https://kellerjordan.github.io/posts/muon/
| .. _Muon is Scalable for LLM Training:
| https://arxiv.org/pdf/2502.16982
|
| Method resolution order:
| Muon
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float = 0.001, weight_decay: float = 0.1, momentum: float = 0.95, nesterov: bool = True, ns_coefficients: tuple[float, float, float] = (3.4445, -4.775, 2.0315), eps: float = 1e-07, ns_steps: int = 5, adjust_lr_fn: str | None = None) -> None from torch.optim._muon.Muon
| Initialize self. See help(type(self)) for accurate signature.
|
| step(self, closure=None) from torch.optim._muon.Muon
| Performs a single optimization step.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setstate__(self, state: dict[str, typing.Any]) -> None
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class NAdam(torch.optim.optimizer.Optimizer)
| NAdam(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.002, betas: tuple[float, float] = (0.9, 0.999), eps: float = 1e-08, weight_decay: float = 0, momentum_decay: float = 0.004, decoupled_weight_decay: bool = False, *, foreach: bool | None = None, maximize: bool = False, capturable: bool = False, differentiable: bool = False) -> None
|
| Implements NAdam algorithm.
|
| .. math::
| \begin{aligned}
| &\rule{110mm}{0.4pt} \\
| &\textbf{input} : \gamma_t \text{ (lr)}, \: \beta_1,\beta_2 \text{ (betas)},
| \: \theta_0 \text{ (params)}, \: f(\theta) \text{ (objective)} \\
| &\hspace{13mm} \: \lambda \text{ (weight decay)}, \:\psi \text{ (momentum decay)} \\
| &\hspace{13mm} \: \textit{decoupled\_weight\_decay}, \:\textit{maximize} \\
| &\textbf{initialize} : m_0 \leftarrow 0 \text{ ( first moment)},
| v_0 \leftarrow 0 \text{ ( second moment)} \\[-1.ex]
| &\rule{110mm}{0.4pt} \\
| &\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
| &\hspace{5mm}\textbf{if} \: \textit{maximize}: \\
| &\hspace{10mm}g_t \leftarrow -\nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm}\textbf{else} \\
| &\hspace{10mm}g_t \leftarrow \nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm} \theta_t \leftarrow \theta_{t-1} \\
| &\hspace{5mm} \textbf{if} \: \lambda \neq 0 \\
| &\hspace{10mm}\textbf{if} \: \textit{decoupled\_weight\_decay} \\
| &\hspace{15mm} \theta_t \leftarrow \theta_{t-1} - \gamma \lambda \theta_{t-1} \\
| &\hspace{10mm}\textbf{else} \\
| &\hspace{15mm} g_t \leftarrow g_t + \lambda \theta_{t-1} \\
| &\hspace{5mm} \mu_t \leftarrow \beta_1 \big(1 - \frac{1}{2} 0.96^{t \psi} \big) \\
| &\hspace{5mm} \mu_{t+1} \leftarrow \beta_1 \big(1 - \frac{1}{2} 0.96^{(t+1)\psi}\big)\\
| &\hspace{5mm}m_t \leftarrow \beta_1 m_{t-1} + (1 - \beta_1) g_t \\
| &\hspace{5mm}v_t \leftarrow \beta_2 v_{t-1} + (1-\beta_2) g^2_t \\
| &\hspace{5mm}\widehat{m_t} \leftarrow \mu_{t+1} m_t/(1-\prod_{i=1}^{t+1}\mu_i)\\[-1.ex]
| & \hspace{11mm} + (1-\mu_t) g_t /(1-\prod_{i=1}^{t} \mu_{i}) \\
| &\hspace{5mm}\widehat{v_t} \leftarrow v_t/\big(1-\beta_2^t \big) \\
| &\hspace{5mm}\theta_t \leftarrow \theta_t - \gamma \widehat{m_t}/
| \big(\sqrt{\widehat{v_t}} + \epsilon \big) \\
| &\rule{110mm}{0.4pt} \\[-1.ex]
| &\bf{return} \: \theta_t \\[-1.ex]
| &\rule{110mm}{0.4pt} \\[-1.ex]
| \end{aligned}
|
| For further details regarding the algorithm we refer to `Incorporating Nesterov Momentum into Adam`_.
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, Tensor, optional): learning rate (default: 2e-3)
| betas (Tuple[float, float], optional): coefficients used for computing
| running averages of gradient and its square (default: (0.9, 0.999))
| eps (float, optional): term added to the denominator to improve
| numerical stability (default: 1e-8)
| weight_decay (float, optional): weight decay (L2 penalty) (default: 0)
| momentum_decay (float, optional): momentum momentum_decay (default: 4e-3)
| decoupled_weight_decay (bool, optional): whether to decouple the weight
| decay as in AdamW to obtain NAdamW. If True, the algorithm does not
| accumulate weight decay in the momentum nor variance. (default: False)
| foreach (bool, optional): whether foreach implementation of optimizer
| is used. If unspecified by the user (so foreach is None), we will try to use
| foreach over the for-loop implementation on CUDA, since it is usually
| significantly more performant. Note that the foreach implementation uses
| ~ sizeof(params) more peak memory than the for-loop version due to the intermediates
| being a tensorlist vs just one tensor. If memory is prohibitive, batch fewer
| parameters through the optimizer at a time or switch this flag to False (default: None)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
| capturable (bool, optional): whether this instance is safe to
| capture in a graph, whether for CUDA graphs or for torch.compile support.
| Tensors are only capturable when on supported :ref:`accelerators<accelerators>`.
| Passing True can impair ungraphed performance, so if you don't intend to graph
| capture this instance, leave it False (default: False)
| differentiable (bool, optional): whether autograd should
| occur through the optimizer step in training. Otherwise, the step()
| function runs in a torch.no_grad() context. Setting to True can impair
| performance, so leave it False if you don't intend to run autograd
| through this instance (default: False)
|
| .. _Incorporating Nesterov Momentum into Adam:
| https://openreview.net/forum?id=OM0jvwB8jIp57ZJjtNEZ
| .. _Decoupled Weight Decay Regularization:
| https://arxiv.org/abs/1711.05101
|
| Method resolution order:
| NAdam
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.002, betas: tuple[float, float] = (0.9, 0.999), eps: float = 1e-08, weight_decay: float = 0, momentum_decay: float = 0.004, decoupled_weight_decay: bool = False, *, foreach: bool | None = None, maximize: bool = False, capturable: bool = False, differentiable: bool = False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state)
|
| step(self, closure=None)
| Perform a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class Optimizer(builtins.object)
| Optimizer(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], defaults: dict[str, typing.Any]) -> None
|
| Base class for all optimizers.
|
| .. warning::
| Parameters need to be specified as collections that have a deterministic
| ordering that is consistent between runs. Examples of objects that don't
| satisfy those properties are sets and iterators over values of dictionaries.
|
| Args:
| params (iterable): an iterable of :class:`torch.Tensor` s or
| :class:`dict` s. Specifies what Tensors should be optimized.
| defaults: (dict): a dict containing default values of optimization
| options (used when a parameter group doesn't specify them).
|
| Methods defined here:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], defaults: dict[str, typing.Any]) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setstate__(self, state: dict[str, typing.Any]) -> None
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| step(self, closure: collections.abc.Callable[[], float] | None = None) -> float | None
| Perform a single optimization step to update parameter.
|
| Args:
| closure (Callable): A closure that reevaluates the model and
| returns the loss. Optional for most optimizers.
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
|
| __annotations__ = {'OptimizerPostHook': typing.TypeAlias, 'OptimizerPr...
class RAdam(torch.optim.optimizer.Optimizer)
| RAdam(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.001, betas: tuple[float, float] = (0.9, 0.999), eps: float = 1e-08, weight_decay: float = 0, decoupled_weight_decay: bool = False, *, foreach: bool | None = None, maximize: bool = False, capturable: bool = False, differentiable: bool = False) -> None
|
| Implements RAdam algorithm.
|
| .. math::
| \begin{aligned}
| &\rule{110mm}{0.4pt} \\
| &\textbf{input} : \gamma \text{ (lr)}, \: \beta_1, \beta_2
| \text{ (betas)}, \: \theta_0 \text{ (params)}, \:f(\theta) \text{ (objective)}, \:
| \lambda \text{ (weightdecay)}, \:\textit{maximize} \\
| &\hspace{13mm} \epsilon \text{ (epsilon)}, \textit{decoupled\_weight\_decay} \\
| &\textbf{initialize} : m_0 \leftarrow 0 \text{ ( first moment)},
| v_0 \leftarrow 0 \text{ ( second moment)}, \\
| &\hspace{18mm} \rho_{\infty} \leftarrow 2/(1-\beta_2) -1 \\[-1.ex]
| &\rule{110mm}{0.4pt} \\
| &\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
| &\hspace{6mm}\textbf{if} \: \textit{maximize}: \\
| &\hspace{12mm}g_t \leftarrow -\nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{6mm}\textbf{else} \\
| &\hspace{12mm}g_t \leftarrow \nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{6mm} \theta_t \leftarrow \theta_{t-1} \\
| &\hspace{6mm} \textbf{if} \: \lambda \neq 0 \\
| &\hspace{12mm}\textbf{if} \: \textit{decoupled\_weight\_decay} \\
| &\hspace{18mm} \theta_t \leftarrow \theta_{t} - \gamma \lambda \theta_{t} \\
| &\hspace{12mm}\textbf{else} \\
| &\hspace{18mm} g_t \leftarrow g_t + \lambda \theta_{t} \\
| &\hspace{6mm}m_t \leftarrow \beta_1 m_{t-1} + (1 - \beta_1) g_t \\
| &\hspace{6mm}v_t \leftarrow \beta_2 v_{t-1} + (1-\beta_2) g^2_t \\
| &\hspace{6mm}\widehat{m_t} \leftarrow m_t/\big(1-\beta_1^t \big) \\
| &\hspace{6mm}\rho_t \leftarrow \rho_{\infty} -
| 2 t \beta^t_2 /\big(1-\beta_2^t \big) \\[0.1.ex]
| &\hspace{6mm}\textbf{if} \: \rho_t > 5 \\
| &\hspace{12mm} l_t \leftarrow \frac{\sqrt{ (1-\beta^t_2) }}{ \sqrt{v_t} +\epsilon } \\
| &\hspace{12mm} r_t \leftarrow
| \sqrt{\frac{(\rho_t-4)(\rho_t-2)\rho_{\infty}}{(\rho_{\infty}-4)(\rho_{\infty}-2) \rho_t}} \\
| &\hspace{12mm}\theta_t \leftarrow \theta_t - \gamma \widehat{m_t} r_t l_t \\
| &\hspace{6mm}\textbf{else} \\
| &\hspace{12mm}\theta_t \leftarrow \theta_t - \gamma \widehat{m_t} \\
| &\rule{110mm}{0.4pt} \\[-1.ex]
| &\bf{return} \: \theta_t \\[-1.ex]
| &\rule{110mm}{0.4pt} \\[-1.ex]
| \end{aligned}
|
| For further details regarding the algorithm we refer to `On the variance of the adaptive learning rate and beyond`_.
|
| This implementation provides an option to use either the original weight_decay implementation as in Adam
| (where the weight_decay is applied to the gradient) or the one from AdamW (where weight_decay is applied
| to the weight) through the decoupled_weight_decay option. When decoupled_weight_decay is set to False
| (default), it uses the original Adam style weight decay, otherwise, it uses the AdamW style which
| corresponds more closely to the `author's implementation`_ in the RAdam paper. Further information
| about decoupled weight decay can be found in `Decoupled Weight Decay Regularization`_.
|
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, Tensor, optional): learning rate (default: 1e-3)
| betas (Tuple[float, float], optional): coefficients used for computing
| running averages of gradient and its square (default: (0.9, 0.999))
| eps (float, optional): term added to the denominator to improve
| numerical stability (default: 1e-8)
| weight_decay (float, optional): weight decay (L2 penalty) (default: 0)
| decoupled_weight_decay (bool, optional): whether to decouple the weight
| decay as in AdamW to obtain RAdamW. If True, the algorithm does not
| accumulate weight decay in the momentum nor variance. (default: False)
| foreach (bool, optional): whether foreach implementation of optimizer
| is used. If unspecified by the user (so foreach is None), we will try to use
| foreach over the for-loop implementation on CUDA, since it is usually
| significantly more performant. Note that the foreach implementation uses
| ~ sizeof(params) more peak memory than the for-loop version due to the intermediates
| being a tensorlist vs just one tensor. If memory is prohibitive, batch fewer
| parameters through the optimizer at a time or switch this flag to False (default: None)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
| capturable (bool, optional): whether this instance is safe to
| capture in a graph, whether for CUDA graphs or for torch.compile support.
| Tensors are only capturable when on supported :ref:`accelerators<accelerators>`.
| Passing True can impair ungraphed performance, so if you don't intend to graph
| capture this instance, leave it False (default: False)
| differentiable (bool, optional): whether autograd should
| occur through the optimizer step in training. Otherwise, the step()
| function runs in a torch.no_grad() context. Setting to True can impair
| performance, so leave it False if you don't intend to run autograd
| through this instance (default: False)
|
| .. _On the variance of the adaptive learning rate and beyond:
| https://arxiv.org/abs/1908.03265
| .. _author's implementation:
| https://github.com/LiyuanLucasLiu/RAdam
| .. _Decoupled Weight Decay Regularization:
| https://arxiv.org/abs/1711.05101
|
| Method resolution order:
| RAdam
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.001, betas: tuple[float, float] = (0.9, 0.999), eps: float = 1e-08, weight_decay: float = 0, decoupled_weight_decay: bool = False, *, foreach: bool | None = None, maximize: bool = False, capturable: bool = False, differentiable: bool = False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state)
|
| step(self, closure=None)
| Perform a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class RMSprop(torch.optim.optimizer.Optimizer)
| RMSprop(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.01, alpha: float = 0.99, eps: float = 1e-08, weight_decay: float = 0, momentum: float = 0, centered: bool = False, capturable: bool = False, foreach: bool | None = None, maximize: bool = False, differentiable: bool = False) -> None
|
| Implements RMSprop algorithm.
|
| .. math::
| \begin{aligned}
| &\rule{110mm}{0.4pt} \\
| &\textbf{input} : \alpha \text{ (alpha)}, \: \gamma \text{ (lr)},
| \: \theta_0 \text{ (params)}, \: f(\theta) \text{ (objective)} \\
| &\hspace{13mm} \lambda \text{ (weight decay)},\: \mu \text{ (momentum)},
| \: centered, \: \epsilon \text{ (epsilon)} \\
| &\textbf{initialize} : v_0 \leftarrow 0 \text{ (square average)}, \:
| \textbf{b}_0 \leftarrow 0 \text{ (buffer)}, \: g^{ave}_0 \leftarrow 0 \\[-1.ex]
| &\rule{110mm}{0.4pt} \\
| &\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
| &\hspace{5mm}g_t \leftarrow \nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm}if \: \lambda \neq 0 \\
| &\hspace{10mm} g_t \leftarrow g_t + \lambda \theta_{t-1} \\
| &\hspace{5mm}v_t \leftarrow \alpha v_{t-1} + (1 - \alpha) g^2_t
| \hspace{8mm} \\
| &\hspace{5mm} \tilde{v_t} \leftarrow v_t \\
| &\hspace{5mm}if \: centered \\
| &\hspace{10mm} g^{ave}_t \leftarrow g^{ave}_{t-1} \alpha + (1-\alpha) g_t \\
| &\hspace{10mm} \tilde{v_t} \leftarrow \tilde{v_t} - \big(g^{ave}_{t} \big)^2 \\
| &\hspace{5mm}if \: \mu > 0 \\
| &\hspace{10mm} \textbf{b}_t\leftarrow \mu \textbf{b}_{t-1} +
| g_t/ \big(\sqrt{\tilde{v_t}} + \epsilon \big) \\
| &\hspace{10mm} \theta_t \leftarrow \theta_{t-1} - \gamma \textbf{b}_t \\
| &\hspace{5mm} else \\
| &\hspace{10mm}\theta_t \leftarrow \theta_{t-1} -
| \gamma g_t/ \big(\sqrt{\tilde{v_t}} + \epsilon \big) \hspace{3mm} \\
| &\rule{110mm}{0.4pt} \\[-1.ex]
| &\bf{return} \: \theta_t \\[-1.ex]
| &\rule{110mm}{0.4pt} \\[-1.ex]
| \end{aligned}
|
| For further details regarding the algorithm we refer to
| `lecture notes <https://www.cs.toronto.edu/~tijmen/csc321/slides/lecture_slides_lec6.pdf>`_ by G. Hinton.
| and centered version `Generating Sequences
| With Recurrent Neural Networks <https://arxiv.org/pdf/1308.0850v5.pdf>`_.
| The implementation here takes the square root of the gradient average before
| adding epsilon (note that TensorFlow interchanges these two operations). The effective
| learning rate is thus :math:`\gamma/(\sqrt{v} + \epsilon)` where :math:`\gamma`
| is the scheduled learning rate and :math:`v` is the weighted moving average
| of the squared gradient.
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, Tensor, optional): learning rate (default: 1e-2)
| alpha (float, optional): smoothing constant (default: 0.99)
| eps (float, optional): term added to the denominator to improve
| numerical stability (default: 1e-8)
| weight_decay (float, optional): weight decay (L2 penalty) (default: 0)
| momentum (float, optional): momentum factor (default: 0)
| centered (bool, optional) : if ``True``, compute the centered RMSProp,
| the gradient is normalized by an estimation of its variance
| capturable (bool, optional): whether this instance is safe to
| capture in a graph, whether for CUDA graphs or for torch.compile support.
| Tensors are only capturable when on supported :ref:`accelerators<accelerators>`.
| Passing True can impair ungraphed performance, so if you don't intend to graph
| capture this instance, leave it False (default: False)
| foreach (bool, optional): whether foreach implementation of optimizer
| is used. If unspecified by the user (so foreach is None), we will try to use
| foreach over the for-loop implementation on CUDA, since it is usually
| significantly more performant. Note that the foreach implementation uses
| ~ sizeof(params) more peak memory than the for-loop version due to the intermediates
| being a tensorlist vs just one tensor. If memory is prohibitive, batch fewer
| parameters through the optimizer at a time or switch this flag to False (default: None)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
| differentiable (bool, optional): whether autograd should
| occur through the optimizer step in training. Otherwise, the step()
| function runs in a torch.no_grad() context. Setting to True can impair
| performance, so leave it False if you don't intend to run autograd
| through this instance (default: False)
|
| Method resolution order:
| RMSprop
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.01, alpha: float = 0.99, eps: float = 1e-08, weight_decay: float = 0, momentum: float = 0, centered: bool = False, capturable: bool = False, foreach: bool | None = None, maximize: bool = False, differentiable: bool = False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state)
|
| step(self, closure=None)
| Perform a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class Rprop(torch.optim.optimizer.Optimizer)
| Rprop(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.01, etas: tuple[float, float] = (0.5, 1.2), step_sizes: tuple[float, float] = (1e-06, 50), *, capturable: bool = False, foreach: bool | None = None, maximize: bool = False, differentiable: bool = False) -> None
|
| Implements the resilient backpropagation algorithm.
|
| .. math::
| \begin{aligned}
| &\rule{110mm}{0.4pt} \\
| &\textbf{input} : \theta_0 \in \mathbf{R}^d \text{ (params)},f(\theta)
| \text{ (objective)}, \\
| &\hspace{13mm} \eta_{+/-} \text{ (etaplus, etaminus)}, \Gamma_{max/min}
| \text{ (step sizes)} \\
| &\textbf{initialize} : g^0_{prev} \leftarrow 0,
| \: \eta_0 \leftarrow \text{lr (learning rate)} \\
| &\rule{110mm}{0.4pt} \\
| &\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
| &\hspace{5mm}g_t \leftarrow \nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm} \textbf{for} \text{ } i = 0, 1, \ldots, d-1 \: \mathbf{do} \\
| &\hspace{10mm} \textbf{if} \: g^i_{prev} g^i_t > 0 \\
| &\hspace{15mm} \eta^i_t \leftarrow \mathrm{min}(\eta^i_{t-1} \eta_{+},
| \Gamma_{max}) \\
| &\hspace{10mm} \textbf{else if} \: g^i_{prev} g^i_t < 0 \\
| &\hspace{15mm} \eta^i_t \leftarrow \mathrm{max}(\eta^i_{t-1} \eta_{-},
| \Gamma_{min}) \\
| &\hspace{15mm} g^i_t \leftarrow 0 \\
| &\hspace{10mm} \textbf{else} \: \\
| &\hspace{15mm} \eta^i_t \leftarrow \eta^i_{t-1} \\
| &\hspace{5mm}\theta_t \leftarrow \theta_{t-1}- \eta_t \mathrm{sign}(g_t) \\
| &\hspace{5mm}g_{prev} \leftarrow g_t \\
| &\rule{110mm}{0.4pt} \\[-1.ex]
| &\bf{return} \: \theta_t \\[-1.ex]
| &\rule{110mm}{0.4pt} \\[-1.ex]
| \end{aligned}
|
| For further details regarding the algorithm we refer to the paper
| `A Direct Adaptive Method for Faster Backpropagation Learning: The RPROP Algorithm
| <http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.21.1417>`_.
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, optional): learning rate (default: 1e-2)
| etas (Tuple[float, float], optional): pair of (etaminus, etaplus), that
| are multiplicative increase and decrease factors
| (default: (0.5, 1.2))
| step_sizes (Tuple[float, float], optional): a pair of minimal and
| maximal allowed step sizes (default: (1e-6, 50))
| capturable (bool, optional): whether this instance is safe to
| capture in a graph, whether for CUDA graphs or for torch.compile support.
| Tensors are only capturable when on supported :ref:`accelerators<accelerators>`.
| Passing True can impair ungraphed performance, so if you don't intend to graph
| capture this instance, leave it False (default: False)
| foreach (bool, optional): whether foreach implementation of optimizer
| is used. If unspecified by the user (so foreach is None), we will try to use
| foreach over the for-loop implementation on CUDA, since it is usually
| significantly more performant. Note that the foreach implementation uses
| ~ sizeof(params) more peak memory than the for-loop version due to the intermediates
| being a tensorlist vs just one tensor. If memory is prohibitive, batch fewer
| parameters through the optimizer at a time or switch this flag to False (default: None)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
| differentiable (bool, optional): whether autograd should
| occur through the optimizer step in training. Otherwise, the step()
| function runs in a torch.no_grad() context. Setting to True can impair
| performance, so leave it False if you don't intend to run autograd
| through this instance (default: False)
|
| Method resolution order:
| Rprop
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.01, etas: tuple[float, float] = (0.5, 1.2), step_sizes: tuple[float, float] = (1e-06, 50), *, capturable: bool = False, foreach: bool | None = None, maximize: bool = False, differentiable: bool = False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state)
|
| step(self, closure=None)
| Perform a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class SGD(torch.optim.optimizer.Optimizer)
| SGD(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.001, momentum: float = 0, dampening: float = 0, weight_decay: float | torch.Tensor = 0, nesterov: bool = False, *, maximize: bool = False, foreach: bool | None = None, differentiable: bool = False, fused: bool | None = None) -> None
|
| Implements stochastic gradient descent (optionally with momentum).
|
| .. math::
| \begin{aligned}
| &\rule{110mm}{0.4pt} \\
| &\textbf{input} : \gamma \text{ (lr)}, \: \theta_0 \text{ (params)}, \: f(\theta)
| \text{ (objective)}, \: \lambda \text{ (weight decay)}, \\
| &\hspace{13mm} \:\mu \text{ (momentum)}, \:\tau \text{ (dampening)},
| \:\textit{ nesterov,}\:\textit{ maximize} \\[-1.ex]
| &\rule{110mm}{0.4pt} \\
| &\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
| &\hspace{5mm}\textbf{if} \: \textit{maximize}: \\
| &\hspace{10mm}g_t \leftarrow -\nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm}\textbf{else} \\
| &\hspace{10mm}g_t \leftarrow \nabla_{\theta} f_t (\theta_{t-1}) \\
| &\hspace{5mm}\textbf{if} \: \lambda \neq 0 \\
| &\hspace{10mm} g_t \leftarrow g_t + \lambda \theta_{t-1} \\
| &\hspace{5mm}\textbf{if} \: \mu \neq 0 \\
| &\hspace{10mm}\textbf{if} \: t > 1 \\
| &\hspace{15mm} \textbf{b}_t \leftarrow \mu \textbf{b}_{t-1} + (1-\tau) g_t \\
| &\hspace{10mm}\textbf{else} \\
| &\hspace{15mm} \textbf{b}_t \leftarrow g_t \\
| &\hspace{10mm}\textbf{if} \: \textit{nesterov} \\
| &\hspace{15mm} g_t \leftarrow g_{t} + \mu \textbf{b}_t \\
| &\hspace{10mm}\textbf{else} \\[-1.ex]
| &\hspace{15mm} g_t \leftarrow \textbf{b}_t \\
| &\hspace{5mm}\theta_t \leftarrow \theta_{t-1} - \gamma g_t \\[-1.ex]
| &\rule{110mm}{0.4pt} \\[-1.ex]
| &\bf{return} \: \theta_t \\[-1.ex]
| &\rule{110mm}{0.4pt} \\[-1.ex]
| \end{aligned}
|
| Nesterov momentum is based on the formula from
| `On the importance of initialization and momentum in deep learning`__.
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, Tensor, optional): learning rate (default: 1e-3)
| momentum (float, optional): momentum factor (default: 0)
| dampening (float, optional): dampening for momentum (default: 0)
| weight_decay (float, optional): weight decay (L2 penalty) (default: 0)
| nesterov (bool, optional): enables Nesterov momentum. Only applicable
| when momentum is non-zero. (default: False)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
| foreach (bool, optional): whether foreach implementation of optimizer
| is used. If unspecified by the user (so foreach is None), we will try to use
| foreach over the for-loop implementation on CUDA, since it is usually
| significantly more performant. Note that the foreach implementation uses
| ~ sizeof(params) more peak memory than the for-loop version due to the intermediates
| being a tensorlist vs just one tensor. If memory is prohibitive, batch fewer
| parameters through the optimizer at a time or switch this flag to False (default: None)
| differentiable (bool, optional): whether autograd should
| occur through the optimizer step in training. Otherwise, the step()
| function runs in a torch.no_grad() context. Setting to True can impair
| performance, so leave it False if you don't intend to run autograd
| through this instance (default: False)
| fused (bool, optional): whether the fused implementation is used.
| Currently, `torch.float64`, `torch.float32`, `torch.float16`, and `torch.bfloat16`
| are supported. (default: None)
|
| .. note:: The foreach and fused implementations are typically faster than the for-loop,
| single-tensor implementation, with fused being theoretically fastest with both
| vertical and horizontal fusion. As such, if the user has not specified either
| flag (i.e., when foreach = fused = None), we will attempt defaulting to the foreach
| implementation when the tensors are all on CUDA. Why not fused? Since the fused
| implementation is relatively new, we want to give it sufficient bake-in time.
| To specify fused, pass True for fused. To force running the for-loop
| implementation, pass False for either foreach or fused.
|
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = torch.optim.SGD(model.parameters(), lr=0.1, momentum=0.9)
| >>> optimizer.zero_grad()
| >>> loss_fn(model(input), target).backward()
| >>> optimizer.step()
|
| __ http://www.cs.toronto.edu/%7Ehinton/absps/momentum.pdf
|
| .. note::
| The implementation of SGD with Momentum/Nesterov subtly differs from
| Sutskever et al. and implementations in some other frameworks.
|
| Considering the specific case of Momentum, the update can be written as
|
| .. math::
| \begin{aligned}
| v_{t+1} & = \mu * v_{t} + g_{t+1}, \\
| p_{t+1} & = p_{t} - \text{lr} * v_{t+1},
| \end{aligned}
|
| where :math:`p`, :math:`g`, :math:`v` and :math:`\mu` denote the
| parameters, gradient, velocity, and momentum respectively.
|
| This is in contrast to Sutskever et al. and
| other frameworks which employ an update of the form
|
| .. math::
| \begin{aligned}
| v_{t+1} & = \mu * v_{t} + \text{lr} * g_{t+1}, \\
| p_{t+1} & = p_{t} - v_{t+1}.
| \end{aligned}
|
| The Nesterov version is analogously modified.
|
| Moreover, the initial value of the momentum buffer is set to the
| gradient value at the first step. This is in contrast to some other
| frameworks that initialize it to all zeros. One notable side effect
| of this decision is that the first momentum value will not be scaled
| by dampening. Dampening will be applied starting at the second step.
|
| Method resolution order:
| SGD
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.001, momentum: float = 0, dampening: float = 0, weight_decay: float | torch.Tensor = 0, nesterov: bool = False, *, maximize: bool = False, foreach: bool | None = None, differentiable: bool = False, fused: bool | None = None) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state)
|
| step(self, closure=None)
| Perform a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
class SparseAdam(torch.optim.optimizer.Optimizer)
| SparseAdam(params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.001, betas: tuple[float, float] = (0.9, 0.999), eps: float = 1e-08, maximize: bool = False) -> None
|
| SparseAdam implements a masked version of the Adam algorithm
| suitable for sparse gradients. Currently, due to implementation constraints (explained
| below), SparseAdam is only intended for a narrow subset of use cases, specifically
| parameters of a dense layout with gradients of a sparse layout. This occurs in a
| special case where the module backwards produces grads already in a sparse layout.
| One example NN module that behaves as such is ``nn.Embedding(sparse=True)``.
|
| SparseAdam approximates the Adam algorithm by masking out the parameter and moment
| updates corresponding to the zero values in the gradients. Whereas the Adam algorithm
| will update the first moment, the second moment, and the parameters based on all values
| of the gradients, SparseAdam only updates the moments and parameters corresponding
| to the non-zero values of the gradients.
|
| A simplified way of thinking about the `intended` implementation is as such:
|
| 1. Create a mask of the non-zero values in the sparse gradients. For example,
| if your gradient looks like [0, 5, 0, 0, 9], the mask would be [0, 1, 0, 0, 1].
| 2. Apply this mask over the running moments and do computation on only the
| non-zero values.
| 3. Apply this mask over the parameters and only apply an update on non-zero values.
|
| In actuality, we use sparse layout Tensors to optimize this approximation, which means the
| more gradients that are masked by not being materialized, the more performant the optimization.
| Since we rely on using sparse layout tensors, we infer that any materialized value in the
| sparse layout is non-zero and we do NOT actually verify that all values are not zero!
| It is important to not conflate a semantically sparse tensor (a tensor where many
| of its values are zeros) with a sparse layout tensor (a tensor where ``.is_sparse``
| returns ``True``). The SparseAdam approximation is intended for `semantically` sparse
| tensors and the sparse layout is only an implementation detail. A clearer implementation
| would be to use MaskedTensors, but those are experimental.
|
|
| .. note::
|
| If you suspect your gradients are semantically sparse (but do not have sparse
| layout), this variant may not be the best for you. Ideally, you want to avoid
| materializing anything that is suspected to be sparse in the first place, since
| needing to convert all your grads from dense layout to sparse layout may outweigh
| the performance gain. Here, using Adam may be the best alternative, unless you
| can easily rig up your module to output sparse grads similar to
| ``nn.Embedding(sparse=True)``. If you insist on converting your grads, you can do
| so by manually overriding your parameters' ``.grad`` fields with their sparse
| equivalents before calling ``.step()``.
|
|
| Args:
| params (iterable): iterable of parameters or named_parameters to optimize
| or iterable of dicts defining parameter groups. When using named_parameters,
| all parameters in all groups should be named
| lr (float, Tensor, optional): learning rate (default: 1e-3)
| betas (Tuple[float, float], optional): coefficients used for computing
| running averages of gradient and its square (default: (0.9, 0.999))
| eps (float, optional): term added to the denominator to improve
| numerical stability (default: 1e-8)
| maximize (bool, optional): maximize the objective with respect to the
| params, instead of minimizing (default: False)
|
| .. _Adam\: A Method for Stochastic Optimization:
| https://arxiv.org/abs/1412.6980
|
| Method resolution order:
| SparseAdam
| torch.optim.optimizer.Optimizer
| builtins.object
|
| Methods defined here:
|
| __init__(self, params: collections.abc.Iterable[torch.Tensor] | collections.abc.Iterable[dict[str, typing.Any]] | collections.abc.Iterable[tuple[str, torch.Tensor]], lr: float | torch.Tensor = 0.001, betas: tuple[float, float] = (0.9, 0.999), eps: float = 1e-08, maximize: bool = False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| step(self, closure=None)
| Perform a single optimization step.
|
| Args:
| closure (Callable, optional): A closure that reevaluates the model
| and returns the loss.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.optim.optimizer.Optimizer:
|
| __getstate__(self) -> dict[str, typing.Any]
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setstate__(self, state: dict[str, typing.Any]) -> None
|
| add_param_group(self, param_group: dict[str, typing.Any]) -> None
| Add a param group to the :class:`Optimizer` s `param_groups`.
|
| This can be useful when fine tuning a pre-trained network as frozen layers can be made
| trainable and added to the :class:`Optimizer` as training progresses.
|
| Args:
| param_group (dict): Specifies what Tensors should be optimized along with group
| specific optimization options.
|
| load_state_dict(self, state_dict: dict[str, typing.Any]) -> None
| Load the optimizer state.
|
| Args:
| state_dict (dict): optimizer state. Should be an object returned
| from a call to :meth:`state_dict`.
|
| .. warning::
| Make sure this method is called after initializing :class:`torch.optim.lr_scheduler.LRScheduler`,
| as calling it beforehand will overwrite the loaded learning rates.
|
| .. note::
| The names of the parameters (if they exist under the "param_names" key of each param group
| in :meth:`state_dict`) will not affect the loading process.
| To use the parameters' names for custom cases (such as when the parameters in the loaded state dict
| differ from those initialized in the optimizer),
| a custom ``register_load_state_dict_pre_hook`` should be implemented to adapt the loaded dict
| accordingly.
| If ``param_names`` exist in loaded state dict ``param_groups`` they will be saved and override
| the current names, if present, in the optimizer state. If they do not exist in loaded state dict,
| the optimizer ``param_names`` will remain unchanged.
|
| Example:
| >>> # xdoctest: +SKIP
| >>> optimizer = ... # initialized optimizer matching the saved state
| >>> scheduler1 = torch.optim.lr_scheduler.LinearLR(
| ... optimizer,
| ... start_factor=0.1,
| ... end_factor=1,
| ... total_iters=20,
| ... )
| >>> scheduler2 = torch.optim.lr_scheduler.CosineAnnealingLR(
| ... optimizer,
| ... T_max=80,
| ... eta_min=3e-5,
| ... )
| >>> lr = torch.optim.lr_scheduler.SequentialLR(
| ... optimizer,
| ... schedulers=[scheduler1, scheduler2],
| ... milestones=[20],
| ... )
| >>> lr.load_state_dict(torch.load("./save_seq.pt"))
| >>> # now load the optimizer checkpoint after loading the LRScheduler
| >>> optimizer.load_state_dict(torch.load("./save_optim.pt"))
|
| register_load_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict post-hook which will be called after
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| The hook will be called with argument ``self`` after calling
| ``load_state_dict`` on ``self``. The registered hook can be used to
| perform post-processing after ``load_state_dict`` has loaded the
| ``state_dict``.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a load_state_dict pre-hook which will be called before
| :meth:`~torch.optim.Optimizer.load_state_dict` is called. It should have the
| following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The ``optimizer`` argument is the optimizer instance being used and the
| ``state_dict`` argument is a shallow copy of the ``state_dict`` the user
| passed in to ``load_state_dict``. The hook may modify the state_dict inplace
| or optionally return a new one. If a state_dict is returned, it will be used
| to be loaded into the optimizer.
|
| The hook will be called with argument ``self`` and ``state_dict`` before
| calling ``load_state_dict`` on ``self``. The registered hook can be used to
| perform pre-processing before the ``load_state_dict`` call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``load_state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_post_hook(self, hook: collections.abc.Callable[['Optimizer', dict[str, typing.Any]], dict[str, typing.Any] | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict post-hook which will be called after :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer, state_dict) -> state_dict or None
|
| The hook will be called with arguments ``self`` and ``state_dict`` after generating
| a ``state_dict`` on ``self``. The hook may modify the state_dict inplace or optionally
| return a new one. The registered hook can be used to perform post-processing
| on the ``state_dict`` before it is returned.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided post ``hook`` will be fired before
| all the already registered post-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| post-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_state_dict_pre_hook(self, hook: collections.abc.Callable[['Optimizer'], None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a state dict pre-hook which will be called before :meth:`~torch.optim.Optimizer.state_dict` is called.
|
| It should have the following signature::
|
| hook(optimizer) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
| The hook will be called with argument ``self`` before calling ``state_dict`` on ``self``.
| The registered hook can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If True, the provided pre ``hook`` will be fired before
| all the already registered pre-hooks on ``state_dict``. Otherwise,
| the provided ``hook`` will be fired after all the already registered
| pre-hooks. (default: False)
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_post_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step post hook which will be called after optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None
|
| The ``optimizer`` argument is the optimizer instance being used.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_step_pre_hook(self, hook: collections.abc.Callable[[typing.Self, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[tuple[typing.Any, ...], dict[str, typing.Any]] | None]) -> torch.utils.hooks.RemovableHandle
| Register an optimizer step pre hook which will be called before optimizer step.
|
| It should have the following signature::
|
| hook(optimizer, args, kwargs) -> None or modified args and kwargs
|
| The ``optimizer`` argument is the optimizer instance being used. If
| args and kwargs are modified by the pre-hook, then the transformed
| values are returned as a tuple containing the new_args and new_kwargs.
|
| Args:
| hook (Callable): The user defined hook to be registered.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| state_dict(self) -> dict[str, typing.Any]
| Return the state of the optimizer as a :class:`dict`.
|
| It contains two entries:
|
| * ``state``: a Dict holding current optimization state. Its content
| differs between optimizer classes, but some common characteristics
| hold. For example, state is saved per parameter, and the parameter
| itself is NOT saved. ``state`` is a Dictionary mapping parameter ids
| to a Dict with state corresponding to each parameter.
| * ``param_groups``: a List containing all parameter groups where each
| parameter group is a Dict. Each parameter group contains metadata
| specific to the optimizer, such as learning rate and weight decay,
| as well as a List of parameter IDs of the parameters in the group.
| If a param group was initialized with ``named_parameters()`` the names
| content will also be saved in the state dict.
|
| NOTE: The parameter IDs may look like indices but they are just IDs
| associating state with param_group. When loading from a state_dict,
| the optimizer will zip the param_group ``params`` (int IDs) and the
| optimizer ``param_groups`` (actual ``nn.Parameter`` s) in order to
| match state WITHOUT additional verification.
|
| A returned state dict might look something like:
|
| .. code-block:: text
|
| {
| 'state': {
| 0: {'momentum_buffer': tensor(...), ...},
| 1: {'momentum_buffer': tensor(...), ...},
| 2: {'momentum_buffer': tensor(...), ...},
| 3: {'momentum_buffer': tensor(...), ...}
| },
| 'param_groups': [
| {
| 'lr': 0.01,
| 'weight_decay': 0,
| ...
| 'params': [0]
| 'param_names' ['param0'] (optional)
| },
| {
| 'lr': 0.001,
| 'weight_decay': 0.5,
| ...
| 'params': [1, 2, 3]
| 'param_names': ['param1', 'layer.weight', 'layer.bias'] (optional)
| }
| ]
| }
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset the gradients of all optimized :class:`torch.Tensor` s.
|
| Args:
| set_to_none (bool, optional): Instead of setting to zero, set the grads to None. Default: ``True``
|
| This will in general have lower memory footprint, and can modestly improve performance.
| However, it changes certain behaviors. For example:
|
| 1. When the user tries to access a gradient and perform manual ops on it,
| a None attribute or a Tensor full of 0s will behave differently.
| 2. If the user requests ``zero_grad(set_to_none=True)`` followed by a backward pass, ``.grad``\ s
| are guaranteed to be None for params that did not receive a gradient.
| 3. ``torch.optim`` optimizers have a different behavior if the gradient is 0 or None
| (in one case it does the step with a gradient of 0 and in the other it skips
| the step altogether).
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.optim.optimizer.Optimizer:
|
| profile_hook_step(func: collections.abc.Callable[~_P, ~R]) -> collections.abc.Callable[~_P, ~R]
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.optim.optimizer.Optimizer:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.optim.optimizer.Optimizer:
|
| OptimizerPostHook = collections.abc.Callable[[typing.Self, tuple[typin...
|
| OptimizerPreHook = collections.abc.Callable[[typing.Self, tuple[typ......
FUNCTIONS
swap_in_optimizer_params_and_state(optimizer: 'torch.optim.Optimizer', swapin_parameters: dict[str, torch.Tensor], swapin_optim_state: dict[str, typing.Any])
Temporarily replace an optimizer's parameters and state with the
supplied params and optim states, then restore them on exit.
For the duration of the context, all optimizer APIs (including
user hooks) see the swap-in values; the live optimizer is restored on
exit.
The difference between this API and ``optimizer.load_state_dict`` is
that ``optimizer.load_state_dict`` only updates the optimizer's state
and leaves the parameters in ``param_groups`` untouched. This API also
swaps in the parameters, so that ``optimizer.step()`` acts on the
swap-in parameter tensors you supply.
Args:
optimizer: the live optimizer; its state must already be
initialized.
swapin_parameters: tensors to use as parameters during the context,
provided in the same order as the existing input parameters to
the optimizer (most commonly in ``model.named_parameters()``
order).
swapin_optim_state: an ``optimizer.state_dict()``-shaped dict
(``{"state": ..., "param_groups": ...}``) holding the state to
install. ``"state"`` is keyed by packed integer parameter ids
and ``"param_groups"`` mirrors ``optimizer.param_groups``,
with each ``"params"`` entry as a list of those packed ids
and the remaining keys carrying per-group hyperparameters
(``lr``, ``betas``, ``foreach``, ``capturable``, ...).
Only in-place tensor edits propagate back to the user supplied
``swapin_optim_state``; all other side-effects (e.g.,
assigning a new tensor to the optim state)
are ignored.
Example:
One use of this API is to run ``optimizer.step()`` against
``FakeTensor`` versions of the parameters and state for nonstrict
tracing — capturing an FX graph of the step without touching the
live optimizer::
from torch.fx.experimental.proxy_tensor import make_fx
from torch._subclasses import FakeTensorMode
from torch.utils import _pytree as pytree
fake_mode = FakeTensorMode(allow_non_fake_inputs=True)
with fake_mode:
fake_params = {
n: fake_mode.from_tensor(p) for n, p in model.named_parameters()
}
fake_osd = pytree.tree_map_only(
torch.Tensor, fake_mode.from_tensor, optimizer.state_dict()
)
def step_fn(params, osd):
with swap_in_optimizer_params_and_state(optimizer, params, osd):
optimizer.step()
return params, osd
gm = make_fx(step_fn)(fake_params, fake_osd)
DATA
__all__ = ['Adafactor', 'Adadelta', 'Adagrad', 'Adam', 'Adamax', 'Adam...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\optim\__init__.py
torch.orgqr
Python Library Documentation: built-in function orgqr in module torch
orgqr(...)
orgqr(input, tau) -> Tensor
Alias for :func:`torch.linalg.householder_product`.
torch.ormqr
Python Library Documentation: built-in function ormqr in module torch
ormqr(...)
ormqr(input, tau, other, left=True, transpose=False, *, out=None) -> Tensor
Computes the matrix-matrix multiplication of a product of Householder matrices with a general matrix.
Multiplies a :math:`m \times n` matrix `C` (given by :attr:`other`) with a matrix `Q`,
where `Q` is represented using Householder reflectors `(input, tau)`.
See `Representation of Orthogonal or Unitary Matrices`_ for further details.
If :attr:`left` is `True` then `op(Q)` times `C` is computed, otherwise the result is `C` times `op(Q)`.
When :attr:`left` is `True`, the implicit matrix `Q` has size :math:`m \times m`.
It has size :math:`n \times n` otherwise.
If :attr:`transpose` is `True` then `op` is the conjugate transpose operation, otherwise it's a no-op.
Supports inputs of float, double, cfloat and cdouble dtypes.
Also supports batched inputs, and, if the input is batched, the output is batched with the same dimensions.
.. seealso::
:func:`torch.geqrf` can be used to form the Householder representation `(input, tau)` of matrix `Q`
from the QR decomposition.
.. note::
This function supports backward but it is only fast when ``(input, tau)`` do not require gradients
and/or ``tau.size(-1)`` is very small.
``
Args:
input (Tensor): tensor of shape `(*, mn, k)` where `*` is zero or more batch dimensions
and `mn` equals to `m` or `n` depending on the :attr:`left`.
tau (Tensor): tensor of shape `(*, min(mn, k))` where `*` is zero or more batch dimensions.
other (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
left (bool): controls the order of multiplication.
transpose (bool): controls whether the matrix `Q` is conjugate transposed or not.
Keyword args:
out (Tensor, optional): the output Tensor. Ignored if `None`. Default: `None`.
.. _Representation of Orthogonal or Unitary Matrices:
https://www.netlib.org/lapack/lug/node128.html
torch.os
Python Library Documentation: module os
NAME
os - OS routines for NT or Posix depending on what system we're on.
MODULE REFERENCE
https://docs.python.org/3.12/library/os.html
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
DESCRIPTION
This exports:
- all functions from posix or nt, e.g. unlink, stat, etc.
- os.path is either posixpath or ntpath
- os.name is either 'posix' or 'nt'
- os.curdir is a string representing the current directory (always '.')
- os.pardir is a string representing the parent directory (always '..')
- os.sep is the (or a most common) pathname separator ('/' or '\\')
- os.extsep is the extension separator (always '.')
- os.altsep is the alternate pathname separator (None or '/')
- os.pathsep is the component separator used in $PATH etc
- os.linesep is the line separator in text files ('\r' or '\n' or '\r\n')
- os.defpath is the default search path for executables
- os.devnull is the file path of the null device ('/dev/null', etc.)
Programs that import and use 'os' stand a better chance of being
portable between different platforms. Of course, they must then
only use functions that are defined by all platforms (e.g., unlink
and opendir), and leave all pathname manipulation to os.path
(e.g., split and join).
CLASSES
builtins.Exception(builtins.BaseException)
builtins.OSError
builtins.object
nt.DirEntry
builtins.tuple(builtins.object)
nt.times_result
nt.uname_result
stat_result
statvfs_result
terminal_size
class DirEntry(builtins.object)
| Methods defined here:
|
| __fspath__(self, /)
| Returns the path for the entry.
|
| __repr__(self, /)
| Return repr(self).
|
| inode(self, /)
| Return inode of the entry; cached per entry.
|
| is_dir(self, /, *, follow_symlinks=True)
| Return True if the entry is a directory; cached per entry.
|
| is_file(self, /, *, follow_symlinks=True)
| Return True if the entry is a file; cached per entry.
|
| is_junction(self, /)
| Return True if the entry is a junction; cached per entry.
|
| is_symlink(self, /)
| Return True if the entry is a symbolic link; cached per entry.
|
| stat(self, /, *, follow_symlinks=True)
| Return stat_result object for the entry; cached per entry.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __class_getitem__(...)
| See PEP 585
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| name
| the entry's base filename, relative to scandir() "path" argument
|
| path
| the entry's full path name; equivalent to os.path.join(scandir_path, entry.name)
error = class OSError(Exception)
| Base class for I/O related errors.
|
| Method resolution order:
| OSError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| BlockingIOError
| ChildProcessError
| ConnectionError
| FileExistsError
| ... and 7 other subclasses
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce__(...)
| Helper for pickle.
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| characters_written
|
| errno
| POSIX exception code
|
| filename
| exception filename
|
| filename2
| second exception filename
|
| strerror
| exception strerror
|
| winerror
| Win32 exception code
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class stat_result(builtins.tuple)
| stat_result(iterable=(), /)
|
| stat_result: Result from stat, fstat, or lstat.
|
| This object may be accessed either as a tuple of
| (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)
| or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.
|
| Posix/windows: If your platform supports st_blksize, st_blocks, st_rdev,
| or st_flags, they are available as attributes only.
|
| See os.stat for more information.
|
| Method resolution order:
| stat_result
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| st_atime
| time of last access
|
| st_atime_ns
| time of last access in nanoseconds
|
| st_birthtime
| time of creation
|
| st_birthtime_ns
| time of creation in nanoseconds
|
| st_ctime
| time of last change
|
| st_ctime_ns
| time of last change in nanoseconds
|
| st_dev
| device
|
| st_file_attributes
| Windows file attribute bits
|
| st_gid
| group ID of owner
|
| st_ino
| inode
|
| st_mode
| protection bits
|
| st_mtime
| time of last modification
|
| st_mtime_ns
| time of last modification in nanoseconds
|
| st_nlink
| number of hard links
|
| st_reparse_tag
| Windows reparse tag
|
| st_size
| total size, in bytes
|
| st_uid
| user ID of owner
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('st_mode', 'st_ino', 'st_dev', 'st_nlink', 'st_uid',...
|
| n_fields = 20
|
| n_sequence_fields = 10
|
| n_unnamed_fields = 3
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class statvfs_result(builtins.tuple)
| statvfs_result(iterable=(), /)
|
| statvfs_result: Result from statvfs or fstatvfs.
|
| This object may be accessed either as a tuple of
| (bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flag, namemax),
| or via the attributes f_bsize, f_frsize, f_blocks, f_bfree, and so on.
|
| See os.statvfs for more information.
|
| Method resolution order:
| statvfs_result
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| f_bavail
|
| f_bfree
|
| f_blocks
|
| f_bsize
|
| f_favail
|
| f_ffree
|
| f_files
|
| f_flag
|
| f_frsize
|
| f_fsid
|
| f_namemax
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('f_bsize', 'f_frsize', 'f_blocks', 'f_bfree', 'f_bav...
|
| n_fields = 11
|
| n_sequence_fields = 10
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class terminal_size(builtins.tuple)
| terminal_size(iterable=(), /)
|
| A tuple of (columns, lines) for holding terminal window size
|
| Method resolution order:
| terminal_size
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| columns
| width of the terminal window in characters
|
| lines
| height of the terminal window in characters
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('columns', 'lines')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class times_result(builtins.tuple)
| times_result(iterable=(), /)
|
| times_result: Result from os.times().
|
| This object may be accessed either as a tuple of
| (user, system, children_user, children_system, elapsed),
| or via the attributes user, system, children_user, children_system,
| and elapsed.
|
| See os.times for more information.
|
| Method resolution order:
| times_result
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| children_system
| system time of children
|
| children_user
| user time of children
|
| elapsed
| elapsed time since an arbitrary point in the past
|
| system
| system time
|
| user
| user time
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('user', 'system', 'children_user', 'children_system'...
|
| n_fields = 5
|
| n_sequence_fields = 5
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class uname_result(builtins.tuple)
| uname_result(iterable=(), /)
|
| uname_result: Result from os.uname().
|
| This object may be accessed either as a tuple of
| (sysname, nodename, release, version, machine),
| or via the attributes sysname, nodename, release, version, and machine.
|
| See os.uname for more information.
|
| Method resolution order:
| uname_result
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| machine
| hardware identifier
|
| nodename
| name of machine on network (implementation-defined)
|
| release
| operating system release
|
| sysname
| operating system name
|
| version
| operating system version
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('sysname', 'nodename', 'release', 'version', 'machin...
|
| n_fields = 5
|
| n_sequence_fields = 5
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
FUNCTIONS
_exit(status)
Exit to the system with specified status, without normal exit processing.
abort()
Abort the interpreter immediately.
This function 'dumps core' or otherwise fails in the hardest way possible
on the hosting operating system. This function never returns.
access(path, mode, *, dir_fd=None, effective_ids=False, follow_symlinks=True)
Use the real uid/gid to test for access to a path.
path
Path to be tested; can be string, bytes, or a path-like object.
mode
Operating-system mode bitfield. Can be F_OK to test existence,
or the inclusive-OR of R_OK, W_OK, and X_OK.
dir_fd
If not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that
directory.
effective_ids
If True, access will use the effective uid/gid instead of
the real uid/gid.
follow_symlinks
If False, and the last element of the path is a symbolic link,
access will examine the symbolic link itself instead of the file
the link points to.
dir_fd, effective_ids, and follow_symlinks may not be implemented
on your platform. If they are unavailable, using them will raise a
NotImplementedError.
Note that most operations will use the effective uid/gid, therefore this
routine can be used in a suid/sgid environment to test if the invoking user
has the specified access to the path.
chdir(path)
Change the current working directory to the specified path.
path may always be specified as a string.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
chmod(path, mode, *, dir_fd=None, follow_symlinks=True)
Change the access permissions of a file.
path
Path to be modified. May always be specified as a str, bytes, or a path-like object.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
mode
Operating-system mode bitfield.
Be careful when using number literals for *mode*. The conventional UNIX notation for
numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in
Python.
dir_fd
If not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that
directory.
follow_symlinks
If False, and the last element of the path is a symbolic link,
chmod will modify the symbolic link itself instead of the file
the link points to.
It is an error to use dir_fd or follow_symlinks when specifying path as
an open file descriptor.
dir_fd and follow_symlinks may not be implemented on your platform.
If they are unavailable, using them will raise a NotImplementedError.
close(fd)
Close a file descriptor.
closerange(fd_low, fd_high, /)
Closes all file descriptors in [fd_low, fd_high), ignoring errors.
cpu_count()
Return the number of CPUs in the system; return None if indeterminable.
This number is not equivalent to the number of CPUs the current process can
use. The number of usable CPUs can be obtained with
``len(os.sched_getaffinity(0))``
device_encoding(fd)
Return a string describing the encoding of a terminal's file descriptor.
The file descriptor must be attached to a terminal.
If the device is not a terminal, return None.
dup(fd, /)
Return a duplicate of a file descriptor.
dup2(fd, fd2, inheritable=True)
Duplicate file descriptor.
execl(file, *args)
execl(file, *args)
Execute the executable file with argument list args, replacing the
current process.
execle(file, *args)
execle(file, *args, env)
Execute the executable file with argument list args and
environment env, replacing the current process.
execlp(file, *args)
execlp(file, *args)
Execute the executable file (which is searched for along $PATH)
with argument list args, replacing the current process.
execlpe(file, *args)
execlpe(file, *args, env)
Execute the executable file (which is searched for along $PATH)
with argument list args and environment env, replacing the current
process.
execv(path, argv, /)
Execute an executable path with arguments, replacing current process.
path
Path of executable file.
argv
Tuple or list of strings.
execve(path, argv, env)
Execute an executable path with arguments, replacing current process.
path
Path of executable file.
argv
Tuple or list of strings.
env
Dictionary of strings mapping to strings.
execvp(file, args)
execvp(file, args)
Execute the executable file (which is searched for along $PATH)
with argument list args, replacing the current process.
args may be a list or tuple of strings.
execvpe(file, args, env)
execvpe(file, args, env)
Execute the executable file (which is searched for along $PATH)
with argument list args and environment env, replacing the
current process.
args may be a list or tuple of strings.
fdopen(fd, mode='r', buffering=-1, encoding=None, *args, **kwargs)
fsdecode(filename)
Decode filename (an os.PathLike, bytes, or str) from the filesystem
encoding with 'surrogateescape' error handler, return str unchanged. On
Windows, use 'strict' error handler if the file system encoding is
'mbcs' (which is the default encoding).
fsencode(filename)
Encode filename (an os.PathLike, bytes, or str) to the filesystem
encoding with 'surrogateescape' error handler, return bytes unchanged.
On Windows, use 'strict' error handler if the file system encoding is
'mbcs' (which is the default encoding).
fspath(path)
Return the file system path representation of the object.
If the object is str or bytes, then allow it to pass through as-is. If the
object defines __fspath__(), then return the result of that method. All other
types raise a TypeError.
fstat(fd)
Perform a stat system call on the given file descriptor.
Like stat(), but for an open file descriptor.
Equivalent to os.stat(fd).
fsync(fd)
Force write of fd to disk.
ftruncate(fd, length, /)
Truncate a file, specified by file descriptor, to a specific length.
get_blocking(fd, /)
Get the blocking mode of the file descriptor.
Return False if the O_NONBLOCK flag is set, True if the flag is cleared.
get_exec_path(env=None)
Returns the sequence of directories that will be searched for the
named executable (similar to a shell) when launching a process.
*env* must be an environment variable dict or None. If *env* is None,
os.environ will be used.
get_handle_inheritable(handle, /)
Get the close-on-exe flag of the specified file descriptor.
get_inheritable(fd, /)
Get the close-on-exe flag of the specified file descriptor.
get_terminal_size(...)
Return the size of the terminal window as (columns, lines).
The optional argument fd (default standard output) specifies
which file descriptor should be queried.
If the file descriptor is not connected to a terminal, an OSError
is thrown.
This function will only be defined if an implementation is
available for this system.
shutil.get_terminal_size is the high-level function which should
normally be used, os.get_terminal_size is the low-level implementation.
getcwd()
Return a unicode string representing the current working directory.
getcwdb()
Return a bytes string representing the current working directory.
getenv(key, default=None)
Get an environment variable, return None if it doesn't exist.
The optional second argument can specify an alternate default.
key, default and the result are str.
getlogin()
Return the actual login name.
getpid()
Return the current process id.
getppid()
Return the parent's process id.
If the parent process has already exited, Windows machines will still
return its id; others systems will return the id of the 'init' process (1).
isatty(fd, /)
Return True if the fd is connected to a terminal.
Return True if the file descriptor is an open file descriptor
connected to the slave end of a terminal.
kill(pid, signal, /)
Kill a process with a signal.
link(src, dst, *, src_dir_fd=None, dst_dir_fd=None, follow_symlinks=True)
Create a hard link to a file.
If either src_dir_fd or dst_dir_fd is not None, it should be a file
descriptor open to a directory, and the respective path string (src or dst)
should be relative; the path will then be relative to that directory.
If follow_symlinks is False, and the last element of src is a symbolic
link, link will create a link to the symbolic link itself instead of the
file the link points to.
src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your
platform. If they are unavailable, using them will raise a
NotImplementedError.
listdir(path=None)
Return a list containing the names of the files in the directory.
path can be specified as either str, bytes, or a path-like object. If path is bytes,
the filenames returned will also be bytes; in all other circumstances
the filenames returned will be str.
If path is None, uses the path='.'.
On some platforms, path may also be specified as an open file descriptor;\
the file descriptor must refer to a directory.
If this functionality is unavailable, using it raises NotImplementedError.
The list is in arbitrary order. It does not include the special
entries '.' and '..' even if they are present in the directory.
listdrives()
Return a list containing the names of drives in the system.
A drive name typically looks like 'C:\\'.
listmounts(volume)
Return a list containing mount points for a particular volume.
'volume' should be a GUID path as returned from os.listvolumes.
listvolumes()
Return a list containing the volumes in the system.
Volumes are typically represented as a GUID path.
lseek(fd, position, whence, /)
Set the position of a file descriptor. Return the new position.
fd
An open file descriptor, as returned by os.open().
position
Position, interpreted relative to 'whence'.
whence
The relative position to seek from. Valid values are:
- SEEK_SET: seek from the start of the file.
- SEEK_CUR: seek from the current file position.
- SEEK_END: seek from the end of the file.
The return value is the number of bytes relative to the beginning of the file.
lstat(path, *, dir_fd=None)
Perform a stat system call on the given path, without following symbolic links.
Like stat(), but do not follow symbolic links.
Equivalent to stat(path, follow_symlinks=False).
makedirs(name, mode=511, exist_ok=False)
makedirs(name [, mode=0o777][, exist_ok=False])
Super-mkdir; create a leaf directory and all intermediate ones. Works like
mkdir, except that any intermediate path segment (not just the rightmost)
will be created if it does not exist. If the target directory already
exists, raise an OSError if exist_ok is False. Otherwise no exception is
raised. This is recursive.
mkdir(path, mode=511, *, dir_fd=None)
Create a directory.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
The mode argument is ignored on Windows. Where it is used, the current umask
value is first masked out.
open(path, flags, mode=511, *, dir_fd=None)
Open a file for low level IO. Returns a file descriptor (integer).
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
pipe()
Create a pipe.
Returns a tuple of two file descriptors:
(read_fd, write_fd)
popen(cmd, mode='r', buffering=-1)
putenv(name, value, /)
Change or add an environment variable.
read(fd, length, /)
Read from a file descriptor. Returns a bytes object.
readlink(path, *, dir_fd=None)
Return a string representing the path to which the symbolic link points.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform. If it is unavailable,
using it will raise a NotImplementedError.
remove(path, *, dir_fd=None)
Remove a file (same as unlink()).
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
removedirs(name)
removedirs(name)
Super-rmdir; remove a leaf directory and all empty intermediate
ones. Works like rmdir except that, if the leaf directory is
successfully removed, directories corresponding to rightmost path
segments will be pruned away until either the whole path is
consumed or an error occurs. Errors during this latter phase are
ignored -- they generally mean that a directory was not empty.
rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
Rename a file or directory.
If either src_dir_fd or dst_dir_fd is not None, it should be a file
descriptor open to a directory, and the respective path string (src or dst)
should be relative; the path will then be relative to that directory.
src_dir_fd and dst_dir_fd, may not be implemented on your platform.
If they are unavailable, using them will raise a NotImplementedError.
renames(old, new)
renames(old, new)
Super-rename; create directories as necessary and delete any left
empty. Works like rename, except creation of any intermediate
directories needed to make the new pathname good is attempted
first. After the rename, directories corresponding to rightmost
path segments of the old name will be pruned until either the
whole path is consumed or a nonempty directory is found.
Note: this function can fail with the new directory structure made
if you lack permissions needed to unlink the leaf directory or
file.
replace(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
Rename a file or directory, overwriting the destination.
If either src_dir_fd or dst_dir_fd is not None, it should be a file
descriptor open to a directory, and the respective path string (src or dst)
should be relative; the path will then be relative to that directory.
src_dir_fd and dst_dir_fd, may not be implemented on your platform.
If they are unavailable, using them will raise a NotImplementedError.
rmdir(path, *, dir_fd=None)
Remove a directory.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
scandir(path=None)
Return an iterator of DirEntry objects for given path.
path can be specified as either str, bytes, or a path-like object. If path
is bytes, the names of yielded DirEntry objects will also be bytes; in
all other circumstances they will be str.
If path is None, uses the path='.'.
set_blocking(fd, blocking, /)
Set the blocking mode of the specified file descriptor.
Set the O_NONBLOCK flag if blocking is False,
clear the O_NONBLOCK flag otherwise.
set_handle_inheritable(handle, inheritable, /)
Set the inheritable flag of the specified handle.
set_inheritable(fd, inheritable, /)
Set the inheritable flag of the specified file descriptor.
spawnl(mode, file, *args)
spawnl(mode, file, *args) -> integer
Execute file with arguments from args in a subprocess.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it.
spawnle(mode, file, *args)
spawnle(mode, file, *args, env) -> integer
Execute file with arguments from args in a subprocess with the
supplied environment.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it.
spawnv(mode, path, argv, /)
Execute the program specified by path in a new process.
mode
Mode of process creation.
path
Path of executable file.
argv
Tuple or list of strings.
spawnve(mode, path, argv, env, /)
Execute the program specified by path in a new process.
mode
Mode of process creation.
path
Path of executable file.
argv
Tuple or list of strings.
env
Dictionary of strings mapping to strings.
startfile(...)
Start a file with its associated application.
When "operation" is not specified or "open", this acts like
double-clicking the file in Explorer, or giving the file name as an
argument to the DOS "start" command: the file is opened with whatever
application (if any) its extension is associated.
When another "operation" is given, it specifies what should be done with
the file. A typical operation is "print".
"arguments" is passed to the application, but should be omitted if the
file is a document.
"cwd" is the working directory for the operation. If "filepath" is
relative, it will be resolved against this directory. This argument
should usually be an absolute path.
"show_cmd" can be used to override the recommended visibility option.
See the Windows ShellExecute documentation for values.
startfile returns as soon as the associated application is launched.
There is no option to wait for the application to close, and no way
to retrieve the application's exit status.
The filepath is relative to the current directory. If you want to use
an absolute path, make sure the first character is not a slash ("/");
the underlying Win32 ShellExecute function doesn't work if it is.
stat(path, *, dir_fd=None, follow_symlinks=True)
Perform a stat system call on the given path.
path
Path to be examined; can be string, bytes, a path-like object or
open-file-descriptor int.
dir_fd
If not None, it should be a file descriptor open to a directory,
and path should be a relative string; path will then be relative to
that directory.
follow_symlinks
If False, and the last element of the path is a symbolic link,
stat will examine the symbolic link itself instead of the file
the link points to.
dir_fd and follow_symlinks may not be implemented
on your platform. If they are unavailable, using them will raise a
NotImplementedError.
It's an error to use dir_fd or follow_symlinks when specifying path as
an open file descriptor.
strerror(code, /)
Translate an error code to a message string.
symlink(src, dst, target_is_directory=False, *, dir_fd=None)
Create a symbolic link pointing to src named dst.
target_is_directory is required on Windows if the target is to be
interpreted as a directory. (On Windows, symlink requires
Windows 6.0 or greater, and raises a NotImplementedError otherwise.)
target_is_directory is ignored on non-Windows platforms.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
system(command)
Execute the command in a subshell.
times()
Return a collection containing process timing information.
The object returned behaves like a named tuple with these fields:
(utime, stime, cutime, cstime, elapsed_time)
All fields are floating-point numbers.
truncate(path, length)
Truncate a file, specified by path, to a specific length.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
umask(mask, /)
Set the current numeric umask and return the previous umask.
unlink(path, *, dir_fd=None)
Remove a file (same as remove()).
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
unsetenv(name, /)
Delete an environment variable.
urandom(size, /)
Return a bytes object containing random bytes suitable for cryptographic use.
utime(...)
Set the access and modified time of path.
path may always be specified as a string.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
If times is not None, it must be a tuple (atime, mtime);
atime and mtime should be expressed as float seconds since the epoch.
If ns is specified, it must be a tuple (atime_ns, mtime_ns);
atime_ns and mtime_ns should be expressed as integer nanoseconds
since the epoch.
If times is None and ns is unspecified, utime uses the current time.
Specifying tuples for both times and ns is an error.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
If follow_symlinks is False, and the last element of the path is a symbolic
link, utime will modify the symbolic link itself instead of the file the
link points to.
It is an error to use dir_fd or follow_symlinks when specifying path
as an open file descriptor.
dir_fd and follow_symlinks may not be available on your platform.
If they are unavailable, using them will raise a NotImplementedError.
waitpid(pid, options, /)
Wait for completion of a given process.
Returns a tuple of information regarding the process:
(pid, status << 8)
The options argument is ignored on Windows.
waitstatus_to_exitcode(status)
Convert a wait status to an exit code.
On Unix:
* If WIFEXITED(status) is true, return WEXITSTATUS(status).
* If WIFSIGNALED(status) is true, return -WTERMSIG(status).
* Otherwise, raise a ValueError.
On Windows, return status shifted right by 8 bits.
On Unix, if the process is being traced or if waitpid() was called with
WUNTRACED option, the caller must first check if WIFSTOPPED(status) is true.
This function must not be called if WIFSTOPPED(status) is true.
walk(top, topdown=True, onerror=None, followlinks=False)
Directory tree generator.
For each directory in the directory tree rooted at top (including top
itself, but excluding '.' and '..'), yields a 3-tuple
dirpath, dirnames, filenames
dirpath is a string, the path to the directory. dirnames is a list of
the names of the subdirectories in dirpath (including symlinks to directories,
and excluding '.' and '..').
filenames is a list of the names of the non-directory files in dirpath.
Note that the names in the lists are just names, with no path components.
To get a full path (which begins with top) to a file or directory in
dirpath, do os.path.join(dirpath, name).
If optional arg 'topdown' is true or not specified, the triple for a
directory is generated before the triples for any of its subdirectories
(directories are generated top down). If topdown is false, the triple
for a directory is generated after the triples for all of its
subdirectories (directories are generated bottom up).
When topdown is true, the caller can modify the dirnames list in-place
(e.g., via del or slice assignment), and walk will only recurse into the
subdirectories whose names remain in dirnames; this can be used to prune the
search, or to impose a specific order of visiting. Modifying dirnames when
topdown is false has no effect on the behavior of os.walk(), since the
directories in dirnames have already been generated by the time dirnames
itself is generated. No matter the value of topdown, the list of
subdirectories is retrieved before the tuples for the directory and its
subdirectories are generated.
By default errors from the os.scandir() call are ignored. If
optional arg 'onerror' is specified, it should be a function; it
will be called with one argument, an OSError instance. It can
report the error to continue with the walk, or raise the exception
to abort the walk. Note that the filename is available as the
filename attribute of the exception object.
By default, os.walk does not follow symbolic links to subdirectories on
systems that support them. In order to get this functionality, set the
optional argument 'followlinks' to true.
Caution: if you pass a relative pathname for top, don't change the
current working directory between resumptions of walk. walk never
changes the current directory, and assumes that the client doesn't
either.
Example:
import os
from os.path import join, getsize
for root, dirs, files in os.walk('python/Lib/email'):
print(root, "consumes ")
print(sum(getsize(join(root, name)) for name in files), end=" ")
print("bytes in", len(files), "non-directory files")
if 'CVS' in dirs:
dirs.remove('CVS') # don't visit CVS directories
write(fd, data, /)
Write a bytes object to a file descriptor.
DATA
EX_OK = 0
F_OK = 0
O_APPEND = 8
O_BINARY = 32768
O_CREAT = 256
O_EXCL = 1024
O_NOINHERIT = 128
O_RANDOM = 16
O_RDONLY = 0
O_RDWR = 2
O_SEQUENTIAL = 32
O_SHORT_LIVED = 4096
O_TEMPORARY = 64
O_TEXT = 16384
O_TRUNC = 512
O_WRONLY = 1
P_DETACH = 4
P_NOWAIT = 1
P_NOWAITO = 3
P_OVERLAY = 2
P_WAIT = 0
R_OK = 4
SEEK_CUR = 1
SEEK_END = 2
SEEK_SET = 0
TMP_MAX = 2147483647
W_OK = 2
X_OK = 1
__all__ = ['altsep', 'curdir', 'pardir', 'sep', 'pathsep', 'linesep', ...
altsep = '/'
curdir = '.'
defpath = r'.;C:\bin'
devnull = 'nul'
environ = environ({'ALLUSERSPROFILE': 'C:\\ProgramData', '...undled\\l...
extsep = '.'
linesep = '\r\n'
name = 'nt'
pardir = '..'
pathsep = ';'
sep = r'\'
supports_bytes_environ = False
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\os.py
torch.outer
Python Library Documentation: built-in function outer in module torch
outer(...)
outer(input, vec2, *, out=None) -> Tensor
Outer product of :attr:`input` and :attr:`vec2`.
If :attr:`input` is a vector of size :math:`n` and :attr:`vec2` is a vector of
size :math:`m`, then :attr:`out` must be a matrix of size :math:`(n \times m)`.
.. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
Args:
input (Tensor): 1-D input vector
vec2 (Tensor): 1-D input vector
Keyword args:
out (Tensor, optional): optional output matrix
Example::
>>> v1 = torch.arange(1., 5.)
>>> v2 = torch.arange(1., 4.)
>>> torch.outer(v1, v2)
tensor([[ 1., 2., 3.],
[ 2., 4., 6.],
[ 3., 6., 9.],
[ 4., 8., 12.]])
torch.overrides
Python Library Documentation: module torch.overrides in torch
NAME
torch.overrides - Python implementation of ``__torch_function__``
DESCRIPTION
While most of the torch API and handling for ``__torch_function__`` happens
at the C++ level, some of the torch API is written in Python so we need
python-level handling for ``__torch_function__`` overrides as well. The main
developer-facing functionality in this file are handle_torch_function and
has_torch_function. See torch/functional.py and test/test_overrides.py
for usage examples.
Note
----
heavily inspired by NumPy's ``__array_function__`` (see:
https://github.com/pytorch/pytorch/issues/24015 and
https://www.numpy.org/neps/nep-0018-array-function-protocol.html
)
If changing this file in a way that can affect ``__torch_function__`` overhead,
please report the benchmarks in ``benchmarks/overrides_benchmark``. See the
instructions in the ``README.md`` in that directory.
FUNCTIONS
enable_reentrant_dispatch()
get_ignored_functions() -> set[collections.abc.Callable]
Return public functions that cannot be overridden by ``__torch_function__``.
Returns
-------
set[Callable]
A tuple of functions that are publicly available in the torch API but cannot
be overridden with ``__torch_function__``. Mostly this is because none of the
arguments of these functions are tensors or tensor-likes.
Examples
--------
>>> torch.Tensor.as_subclass in torch.overrides.get_ignored_functions()
True
>>> torch.add in torch.overrides.get_ignored_functions()
False
get_overridable_functions() -> dict[typing.Any, list[collections.abc.Callable]]
List functions that are overridable via __torch_function__
Returns
-------
Dict[Any, List[Callable]]
A dictionary that maps namespaces that contain overridable functions
to functions in that namespace that can be overridden.
get_testing_overrides() -> dict[collections.abc.Callable, collections.abc.Callable]
Return a dict containing dummy overrides for all overridable functions
Returns
-------
Dict[Callable, Callable]
A dictionary that maps overridable functions in the PyTorch API to
lambda functions that have the same signature as the real function
and unconditionally return -1. These lambda functions are useful
for testing API coverage for a type that defines ``__torch_function__``.
Examples
--------
>>> import inspect
>>> my_add = torch.overrides.get_testing_overrides()[torch.add]
>>> inspect.signature(my_add)
<Signature (input, other, out=None)>
handle_torch_function(public_api: collections.abc.Callable[~_P, ~_R], relevant_args: collections.abc.Iterable[typing.Any], *args: _P.args, **kwargs: _P.kwargs) -> ~_R
Implement a function with checks for ``__torch_function__`` overrides.
See torch::autograd::handle_torch_function for the equivalent of this
function in the C++ implementation.
Arguments
---------
public_api : function
Function exposed by the public torch API originally called like
``public_api(*args, **kwargs)`` on which arguments are now being
checked.
relevant_args : iterable
Iterable of arguments to check for __torch_function__ methods.
args : tuple
Arbitrary positional arguments originally passed into ``public_api``.
kwargs : tuple
Arbitrary keyword arguments originally passed into ``public_api``.
Returns
-------
object
Result from calling ``implementation`` or an ``__torch_function__``
method, as appropriate.
Raises
------
TypeError : if no implementation is found.
Example
-------
>>> def func(a):
... if has_torch_function_unary(a):
... return handle_torch_function(func, (a,), a)
... return a + 0
has_torch_function = _has_torch_function(...)
Check for __torch_function__ implementations in the elements of an iterable
or if a __torch_function__ mode is enabled. Considers exact ``Tensor`` s
and ``Parameter`` s non-dispatchable. Use this to guard a call to
:func:`handle_torch_function`; don't use it to test if something
is Tensor-like, use :func:`is_tensor_like` instead.
Arguments
---------
relevant_args : iterable
Iterable or arguments to check for __torch_function__ methods.
Returns
-------
bool
True if any of the elements of relevant_args have __torch_function__
implementations, False otherwise.
See Also
________
torch.is_tensor_like
Checks if something is a Tensor-like, including an exact ``Tensor``.
is_tensor_like(inp)
Returns ``True`` if the passed-in input is a Tensor-like.
Currently, this occurs whenever there's a ``__torch_function__``
attribute on the type of the input.
Examples
--------
A subclass of tensor is generally a Tensor-like.
>>> class SubTensor(torch.Tensor): ...
>>> is_tensor_like(SubTensor([0]))
True
Built-in or user types aren't usually Tensor-like.
>>> is_tensor_like(6)
False
>>> is_tensor_like(None)
False
>>> class NotATensor: ...
>>> is_tensor_like(NotATensor())
False
But, they can be made Tensor-like by implementing __torch_function__.
>>> class TensorLike:
... @classmethod
... def __torch_function__(cls, func, types, args, kwargs):
... return -1
>>> is_tensor_like(TensorLike())
True
is_tensor_method_or_property(func: collections.abc.Callable) -> bool
Returns True if the function passed in is a handler for a
method or property belonging to ``torch.Tensor``, as passed
into ``__torch_function__``.
.. note::
For properties, their ``__get__`` method must be passed in.
This may be needed, in particular, for the following reasons:
1. Methods/properties sometimes don't contain a `__module__` slot.
2. They require that the first passed-in argument is an instance
of ``torch.Tensor``.
Examples
--------
>>> is_tensor_method_or_property(torch.Tensor.add)
True
>>> is_tensor_method_or_property(torch.add)
False
redispatch_function(func, types, args, kwargs)
Skip one level of ``__torch_function__`` dispatch and call the function.
This is primarily useful for **Tensor subclasses** that want to call into
a function's implementation while still intercepting PyTorch operations
inside that function.
Example with Tensor subclass. Only ops whose inputs include a
``LoggingTensor`` are intercepted; once ``redispatch_function`` returns
a plain ``torch.Tensor``, subsequent ops (here ``+ 1``) are not logged.
>>> from torch.overrides import has_torch_function, handle_torch_function
>>> class LoggingTensor(torch.Tensor):
... depth = 0
...
... @classmethod
... def __torch_function__(cls, func, types, args, kwargs=None):
... print(f"{' ' * cls.depth}Calling {func.__name__}")
... cls.depth += 1
... r = torch.overrides.redispatch_function(func, types, args, kwargs)
... cls.depth -= 1
... return r
>>> def scaled_mul(a, b):
... if has_torch_function((a, b)):
... return handle_torch_function(scaled_mul, (a, b), a, b)
... return a * b + 1
>>> x = LoggingTensor(torch.tensor([3.0]))
>>> y = LoggingTensor(torch.tensor([4.0]))
>>> result = scaled_mul(x, y)
Calling scaled_mul
Calling mul
>>> result
tensor([13.])
Note that only ``mul`` is logged, not ``add``: ``redispatch_function``
returns a plain ``torch.Tensor``, so the ``+ 1`` inside ``scaled_mul``
no longer sees a ``LoggingTensor`` input and ``__torch_function__`` is
not triggered.
With ``TorchFunctionMode`` the mode stays active across all inner ops,
so the ``+ 1`` is now visible too. Use ``with self:`` after
``redispatch_function`` to re-enable the mode for those inner calls.
>>> from torch.overrides import TorchFunctionMode
>>> class LoggingMode(TorchFunctionMode):
... def __init__(self):
... self.depth = 0
...
... def __torch_function__(self, func, types, args, kwargs=None):
... print(f"{' ' * self.depth}Calling {func.__name__}")
... self.depth += 1
... with self:
... r = torch.overrides.redispatch_function(
... func, types, args, kwargs
... )
... self.depth -= 1
... return r
>>> a = torch.tensor([3.0])
>>> b = torch.tensor([4.0])
>>> with LoggingMode():
... result = scaled_mul(a, b)
Calling scaled_mul
Calling mul
Calling add
>>> result
tensor([13.])
resolve_name(f)
Get a human readable string name for a function passed to
__torch_function__
Arguments
---------
f : Callable
Function to resolve the name of.
Returns
-------
str
Name of the function; if eval'ed it should give back the input
function.
wrap_torch_function(dispatcher: collections.abc.Callable[~_P, collections.abc.Iterable[typing.Any]]) -> collections.abc.Callable[[collections.abc.Callable[~_P, ~_R]], collections.abc.Callable[~_P, ~_R]]
Wraps a given function with ``__torch_function__`` -related functionality.
Parameters
----------
dispatcher: Callable
A callable that returns an iterable of Tensor-likes passed into the function.
Note
----
This decorator may reduce the performance of your code. Generally, it's enough to express
your code as a series of functions that, themselves, support __torch_function__. If you
find yourself in the rare situation where this is not the case, e.g. if you're wrapping a
low-level library and you also need it to work for Tensor-likes, then this function is available.
Examples
--------
>>> def dispatcher(a): # Must have the same signature as func
... return (a,)
>>> @torch.overrides.wrap_torch_function(dispatcher)
>>> def func(a): # This will make func dispatchable by __torch_function__
... return a + 0
DATA
__all__ = ['get_ignored_functions', 'get_overridable_functions', 'get_...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\overrides.py
torch.package
Python Library Documentation: package torch.package in torch
NAME
torch.package
PACKAGE CONTENTS
_digraph
_directory_reader
_importlib
_mangling
_mock
_package_pickler
_package_unpickler
_stdlib
analyze (package)
file_structure_representation
find_file_dependencies
glob_group
importer
package_exporter
package_importer
DATA
sys_importer = <torch.package.importer._SysImporter object>
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\package\__init__.py
torch.pairwise_distance
Python Library Documentation: built-in function pairwise_distance in module torch
pairwise_distance(...)
pairwise_distance(x1, x2, p=2.0, eps=1e-6, keepdim=False) -> Tensor
See :class:`torch.nn.PairwiseDistance` for details
torch.parse_ir
Python Library Documentation: built-in function parse_ir in module torch
parse_ir(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
parse_ir(input: str, parse_tensor_constants: bool = False) -> torch::jit::Graph
torch.parse_schema
Python Library Documentation: built-in function parse_schema in module torch
parse_schema(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
parse_schema(schema: str, allow_typevars: bool = True) -> c10::FunctionSchema
torch.parse_type_comment
Python Library Documentation: built-in function parse_type_comment in module torch
parse_type_comment(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
parse_type_comment(arg0: str) -> torch._C._jit_tree_views.Decl
torch.pca_lowrank
Python Library Documentation: function pca_lowrank in module torch._lowrank
pca_lowrank(A: torch.Tensor, q: int | None = None, center: bool = True, niter: int = 2) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]
Performs linear Principal Component Analysis (PCA) on a low-rank
matrix, batches of such matrices, or sparse matrix.
This function returns a namedtuple ``(U, S, V)`` which is the
nearly optimal approximation of a singular value decomposition of
a centered matrix :math:`A` such that :math:`A \approx U \operatorname{diag}(S) V^{\text{H}}`
.. note:: The relation of ``(U, S, V)`` to PCA is as follows:
- :math:`A` is a data matrix with ``m`` samples and
``n`` features
- the :math:`V` columns represent the principal directions
- :math:`S ** 2 / (m - 1)` contains the eigenvalues of
:math:`A^T A / (m - 1)` which is the covariance of
``A`` when ``center=True`` is provided.
- ``matmul(A, V[:, :k])`` projects data to the first k
principal components
.. note:: Different from the standard SVD, the size of returned
matrices depend on the specified rank and q
values as follows:
- :math:`U` is m x q matrix
- :math:`S` is q-vector
- :math:`V` is n x q matrix
.. note:: To obtain repeatable results, reset the seed for the
pseudorandom number generator
Args:
A (Tensor): the input tensor of size :math:`(*, m, n)`
q (int, optional): a slightly overestimated rank of
:math:`A`. By default, ``q = min(6, m,
n)``.
center (bool, optional): if True, center the input tensor,
otherwise, assume that the input is
centered.
niter (int, optional): the number of subspace iterations to
conduct; niter must be a nonnegative
integer, and defaults to 2.
References::
- Nathan Halko, Per-Gunnar Martinsson, and Joel Tropp, Finding
structure with randomness: probabilistic algorithms for
constructing approximate matrix decompositions,
arXiv:0909.4061 [math.NA; math.PR], 2009 (available at
`arXiv <http://arxiv.org/abs/0909.4061>`_).
torch.pdist
Python Library Documentation: built-in function pdist in module torch
pdist(...)
pdist(input, p=2) -> Tensor
Computes the p-norm distance between every pair of row vectors in the input.
This is identical to the upper triangular portion, excluding the diagonal, of
`torch.norm(input[:, None] - input, dim=2, p=p)`. This function will be faster
if the rows are contiguous.
If input has shape :math:`N \times M` then the output will have shape
:math:`\frac{1}{2} N (N - 1)`.
This function is equivalent to ``scipy.spatial.distance.pdist(input,
'minkowski', p=p)`` if :math:`p \in (0, \infty)`. When :math:`p = 0` it is
equivalent to ``scipy.spatial.distance.pdist(input, 'hamming') * M``.
When :math:`p = \infty`, the closest scipy function is
``scipy.spatial.distance.pdist(xn, lambda x, y: np.abs(x - y).max())``.
Args:
input: input tensor of shape :math:`N \times M`.
p: p value for the p-norm distance to calculate between each vector pair
:math:`\in [0, \infty]`.
torch.per_channel_affine
Python Library Documentation: qscheme object class qscheme(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self).
torch.per_channel_affine_float_qparams
Python Library Documentation: qscheme object class qscheme(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self).
torch.per_channel_symmetric
Python Library Documentation: qscheme object class qscheme(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self).
torch.per_tensor_affine
Python Library Documentation: qscheme object class qscheme(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self).
torch.per_tensor_symmetric
Python Library Documentation: qscheme object class qscheme(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self).
torch.permute
Python Library Documentation: built-in function permute in module torch
permute(...)
permute(input, dims) -> Tensor
Returns a view of the original tensor :attr:`input` with its dimensions permuted.
Args:
input (Tensor): the input tensor.
dims (torch.Size, tuple of int or list of int): the desired ordering of dimensions.
Example:
>>> x = torch.randn(2, 3, 5)
>>> x.size()
torch.Size([2, 3, 5])
>>> torch.permute(x, (2, 0, 1)).size()
torch.Size([5, 2, 3])
torch.permute_copy
Python Library Documentation: built-in function permute_copy in module torch
permute_copy(...)
Performs the same operation as :func:`torch.permute`, but all output tensors
are freshly created instead of aliasing the input.
torch.pi
Python Library Documentation: float object
class float(object)
| float(x=0, /)
|
| Convert a string or number to a floating-point number, if possible.
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(self, /)
| Return the ceiling as an Integral.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(self, /)
| Return the floor as an Integral.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Formats the float according to format_spec.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __int__(self, /)
| int(self)
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __repr__(self, /)
| Return repr(self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __round__(self, ndigits=None, /)
| Return the Integral closest to x, rounding half toward even.
|
| When an argument is passed, work like built-in round(x, ndigits).
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(self, /)
| Return the Integral closest to x between 0 and x.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is exactly equal to the original float.
|
| The ratio is in lowest terms and has a positive denominator. Raise
| OverflowError on infinities and a ValueError on NaNs.
|
| >>> (10.0).as_integer_ratio()
| (10, 1)
| >>> (0.0).as_integer_ratio()
| (0, 1)
| >>> (-.25).as_integer_ratio()
| (-1, 4)
|
| conjugate(self, /)
| Return self, the complex conjugate of any float.
|
| hex(self, /)
| Return a hexadecimal representation of a floating-point number.
|
| >>> (-0.1).hex()
| '-0x1.999999999999ap-4'
| >>> 3.14159.hex()
| '0x1.921f9f01b866ep+1'
|
| is_integer(self, /)
| Return True if the float is an integer.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __getformat__(typestr, /)
| You probably don't want to use this function.
|
| typestr
| Must be 'double' or 'float'.
|
| It exists mainly to be used in Python's test suite.
|
| This function returns whichever of 'unknown', 'IEEE, big-endian' or 'IEEE,
| little-endian' best describes the format of floating-point numbers used by the
| C type named by typestr.
|
| fromhex(string, /)
| Create a floating-point number from a hexadecimal string.
|
| >>> float.fromhex('0x1.ffffp10')
| 2047.984375
| >>> float.fromhex('-0x1p-1074')
| -5e-324
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| imag
| the imaginary part of a complex number
|
| real
| the real part of a complex number
torch.pinverse
Python Library Documentation: built-in function pinverse in module torch
pinverse(...)
pinverse(input, rcond=1e-15) -> Tensor
Alias for :func:`torch.linalg.pinv`
torch.pixel_shuffle
Python Library Documentation: built-in function pixel_shuffle in module torch
pixel_shuffle(...)
pixel_shuffle(input, upscale_factor) -> Tensor
Rearranges elements in a tensor of shape :math:`(*, C \times r^2, H, W)` to a
tensor of shape :math:`(*, C, H \times r, W \times r)`, where r is the :attr:`upscale_factor`.
See :class:`~torch.nn.PixelShuffle` for details.
Args:
input (Tensor): the input tensor
upscale_factor (int): factor to increase spatial resolution by
Examples::
>>> input = torch.randn(1, 9, 4, 4)
>>> output = torch.nn.functional.pixel_shuffle(input, 3)
>>> print(output.size())
torch.Size([1, 1, 12, 12])
torch.pixel_unshuffle
Python Library Documentation: built-in function pixel_unshuffle in module torch
pixel_unshuffle(...)
pixel_unshuffle(input, downscale_factor) -> Tensor
Reverses the :class:`~torch.nn.PixelShuffle` operation by rearranging elements in a
tensor of shape :math:`(*, C, H \times r, W \times r)` to a tensor of shape
:math:`(*, C \times r^2, H, W)`, where r is the :attr:`downscale_factor`.
See :class:`~torch.nn.PixelUnshuffle` for details.
Args:
input (Tensor): the input tensor
downscale_factor (int): factor to increase spatial resolution by
Examples::
>>> input = torch.randn(1, 1, 12, 12)
>>> output = torch.nn.functional.pixel_unshuffle(input, 3)
>>> print(output.size())
torch.Size([1, 9, 4, 4])
torch.platform
Python Library Documentation: module platform
NAME
platform
MODULE REFERENCE
https://docs.python.org/3.12/library/platform.html
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
DESCRIPTION
This module tries to retrieve as much platform-identifying data as
possible. It makes this information available via function APIs.
If called from the command line, it prints the platform
information concatenated as single string to stdout. The output
format is usable as part of a filename.
CLASSES
uname_result_base(builtins.tuple)
uname_result
class uname_result(uname_result_base)
| uname_result(system, node, release, version, machine)
|
| A uname_result that's largely compatible with a
| simple namedtuple except that 'processor' is
| resolved late and cached to avoid calling "uname"
| except when needed.
|
| Method resolution order:
| uname_result
| uname_result_base
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| processor = <functools.cached_property object>
| __getitem__(self, key)
| Return self[key].
|
| __iter__(self)
| Implement iter(self).
|
| __len__(self)
| Return len(self).
|
| __reduce__(self)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| _make(iterable)
| Make a new uname_result_base object from a sequence or iterable
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| _fields = ('system', 'node', 'release', 'version', 'machine', 'process...
|
| ----------------------------------------------------------------------
| Methods inherited from uname_result_base:
|
| __getnewargs__(self) from collections.uname_result_base
| Return self as a plain tuple. Used by copy and pickle.
|
| __repr__(self) from collections.uname_result_base
| Return a nicely formatted representation string
|
| _asdict(self) from collections.uname_result_base
| Return a new dict which maps field names to their values.
|
| _replace(self, /, **kwds) from collections.uname_result_base
| Return a new uname_result_base object replacing specified fields with new values
|
| ----------------------------------------------------------------------
| Static methods inherited from uname_result_base:
|
| __new__(_cls, system, node, release, version, machine) from namedtuple_uname_result_base.uname_result_base
| Create new instance of uname_result_base(system, node, release, version, machine)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from uname_result_base:
|
| system
| Alias for field number 0
|
| node
| Alias for field number 1
|
| release
| Alias for field number 2
|
| version
| Alias for field number 3
|
| machine
| Alias for field number 4
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from uname_result_base:
|
| __match_args__ = ('system', 'node', 'release', 'version', 'machine')
|
| _field_defaults = {}
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
FUNCTIONS
architecture(executable='C:\\Users\\Youse\\AppData\\Local\\Programs\\Python\\Python312\\python.exe', bits='', linkage='')
Queries the given executable (defaults to the Python interpreter
binary) for various architecture information.
Returns a tuple (bits, linkage) which contains information about
the bit architecture and the linkage format used for the
executable. Both values are returned as strings.
Values that cannot be determined are returned as given by the
parameter presets. If bits is given as '', the sizeof(pointer)
(or sizeof(long) on Python version < 1.5.2) is used as
indicator for the supported pointer size.
The function relies on the system's "file" command to do the
actual work. This is available on most if not all Unix
platforms. On some non-Unix platforms where the "file" command
does not exist and the executable is set to the Python interpreter
binary defaults from _default_architecture are used.
freedesktop_os_release()
Return operation system identification from freedesktop.org os-release
java_ver(release='', vendor='', vminfo=('', '', ''), osinfo=('', '', ''))
Version interface for Jython.
Returns a tuple (release, vendor, vminfo, osinfo) with vminfo being
a tuple (vm_name, vm_release, vm_vendor) and osinfo being a
tuple (os_name, os_version, os_arch).
Values which cannot be determined are set to the defaults
given as parameters (which all default to '').
libc_ver(executable=None, lib='', version='', chunksize=16384)
Tries to determine the libc version that the file executable
(which defaults to the Python interpreter) is linked against.
Returns a tuple of strings (lib,version) which default to the
given parameters in case the lookup fails.
Note that the function has intimate knowledge of how different
libc versions add symbols to the executable and thus is probably
only usable for executables compiled using gcc.
The file is read and scanned in chunks of chunksize bytes.
mac_ver(release='', versioninfo=('', '', ''), machine='')
Get macOS version information and return it as tuple (release,
versioninfo, machine) with versioninfo being a tuple (version,
dev_stage, non_release_version).
Entries which cannot be determined are set to the parameter values
which default to ''. All tuple entries are strings.
machine()
Returns the machine type, e.g. 'i386'
An empty string is returned if the value cannot be determined.
node()
Returns the computer's network name (which may not be fully
qualified)
An empty string is returned if the value cannot be determined.
platform(aliased=False, terse=False)
Returns a single string identifying the underlying platform
with as much useful information as possible (but no more :).
The output is intended to be human readable rather than
machine parseable. It may look different on different
platforms and this is intended.
If "aliased" is true, the function will use aliases for
various platforms that report system names which differ from
their common names, e.g. SunOS will be reported as
Solaris. The system_alias() function is used to implement
this.
Setting terse to true causes the function to return only the
absolute minimum information needed to identify the platform.
processor()
Returns the (true) processor name, e.g. 'amdk6'
An empty string is returned if the value cannot be
determined. Note that many platforms do not provide this
information or simply return the same value as for machine(),
e.g. NetBSD does this.
python_branch()
Returns a string identifying the Python implementation
branch.
For CPython this is the SCM branch from which the
Python binary was built.
If not available, an empty string is returned.
python_build()
Returns a tuple (buildno, builddate) stating the Python
build number and date as strings.
python_compiler()
Returns a string identifying the compiler used for compiling
Python.
python_implementation()
Returns a string identifying the Python implementation.
Currently, the following implementations are identified:
'CPython' (C implementation of Python),
'Jython' (Java implementation of Python),
'PyPy' (Python implementation of Python).
python_revision()
Returns a string identifying the Python implementation
revision.
For CPython this is the SCM revision from which the
Python binary was built.
If not available, an empty string is returned.
python_version()
Returns the Python version as string 'major.minor.patchlevel'
Note that unlike the Python sys.version, the returned value
will always include the patchlevel (it defaults to 0).
python_version_tuple()
Returns the Python version as tuple (major, minor, patchlevel)
of strings.
Note that unlike the Python sys.version, the returned value
will always include the patchlevel (it defaults to 0).
release()
Returns the system's release, e.g. '2.2.0' or 'NT'
An empty string is returned if the value cannot be determined.
system()
Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'.
An empty string is returned if the value cannot be determined.
system_alias(system, release, version)
Returns (system, release, version) aliased to common
marketing names used for some systems.
It also does some reordering of the information in some cases
where it would otherwise cause confusion.
uname()
Fairly portable uname interface. Returns a tuple
of strings (system, node, release, version, machine, processor)
identifying the underlying platform.
Note that unlike the os.uname function this also returns
possible processor information as an additional tuple entry.
Entries which cannot be determined are set to ''.
version()
Returns the system's release version, e.g. '#3 on degas'
An empty string is returned if the value cannot be determined.
win32_edition()
win32_is_iot()
win32_ver(release='', version='', csd='', ptype='')
DATA
__copyright__ = '\n Copyright (c) 1999-2000, Marc-Andre Lemburg... ...
VERSION
1.0.8
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\platform.py
torch.poisson
Python Library Documentation: built-in function poisson in module torch
poisson(...)
poisson(input, generator=None) -> Tensor
Returns a tensor of the same size as :attr:`input` with each element
sampled from a Poisson distribution with rate parameter given by the corresponding
element in :attr:`input` i.e.,
.. math::
\text{out}_i \sim \text{Poisson}(\text{input}_i)
:attr:`input` must be non-negative.
Args:
input (Tensor): the input tensor containing the rates of the Poisson distribution
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
Example::
>>> rates = torch.rand(4, 4) * 5 # rate parameter between 0 and 5
>>> torch.poisson(rates)
tensor([[9., 1., 3., 5.],
[8., 6., 6., 0.],
[0., 4., 5., 3.],
[2., 1., 4., 2.]])
torch.poisson_nll_loss
Python Library Documentation: built-in function poisson_nll_loss in module torch poisson_nll_loss(...)
torch.polar
Python Library Documentation: built-in function polar in module torch
polar(...)
polar(abs, angle, *, out=None) -> Tensor
Constructs a complex tensor whose elements are Cartesian coordinates
corresponding to the polar coordinates with absolute value :attr:`abs` and angle
:attr:`angle`.
.. math::
\text{out} = \text{abs} \cdot \cos(\text{angle}) + \text{abs} \cdot \sin(\text{angle}) \cdot j
.. note::
`torch.polar` is similar to
`std::polar <https://en.cppreference.com/w/cpp/numeric/complex/polar>`_
and does not compute the polar decomposition
of a complex tensor like Python's `cmath.polar` and SciPy's `linalg.polar` do.
The behavior of this function is undefined if `abs` is negative or NaN, or if `angle` is
infinite.
Args:
abs (Tensor): The absolute value the complex tensor. Must be float or double.
angle (Tensor): The angle of the complex tensor. Must be same dtype as
:attr:`abs`.
Keyword args:
out (Tensor): If the inputs are ``torch.float32``, must be
``torch.complex64``. If the inputs are ``torch.float64``, must be
``torch.complex128``.
Example::
>>> import numpy as np
>>> abs = torch.tensor([1, 2], dtype=torch.float64)
>>> angle = torch.tensor([np.pi / 2, 5 * np.pi / 4], dtype=torch.float64)
>>> z = torch.polar(abs, angle)
>>> z
tensor([(0.0000+1.0000j), (-1.4142-1.4142j)], dtype=torch.complex128)
torch.polygamma
Python Library Documentation: built-in function polygamma in module torch
polygamma(...)
polygamma(n, input, *, out=None) -> Tensor
Alias for :func:`torch.special.polygamma`.
torch.positive
Python Library Documentation: built-in function positive in module torch
positive(...)
positive(input) -> Tensor
Returns :attr:`input`.
Throws a runtime error if :attr:`input` is a bool tensor.
Args:
input (Tensor): the input tensor.
Example::
>>> t = torch.randn(5)
>>> t
tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
>>> torch.positive(t)
tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
torch.pow
Python Library Documentation: built-in function pow in module torch
pow(...)
pow(input, exponent, *, out=None) -> Tensor
Takes the power of each element in :attr:`input` with :attr:`exponent` and
returns a tensor with the result.
:attr:`exponent` can be either a single ``float`` number or a `Tensor`
with the same number of elements as :attr:`input`.
When :attr:`exponent` is a scalar value, the operation applied is:
.. math::
\text{out}_i = x_i ^ \text{exponent}
When :attr:`exponent` is a tensor, the operation applied is:
.. math::
\text{out}_i = x_i ^ {\text{exponent}_i}
When :attr:`exponent` is a tensor, the shapes of :attr:`input`
and :attr:`exponent` must be :ref:`broadcastable <broadcasting-semantics>`.
Args:
input (Tensor): the input tensor.
exponent (float or tensor): the exponent value
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.4331, 1.2475, 0.6834, -0.2791])
>>> torch.pow(a, 2)
tensor([ 0.1875, 1.5561, 0.4670, 0.0779])
>>> exp = torch.arange(1., 5.)
>>> a = torch.arange(1., 5.)
>>> a
tensor([ 1., 2., 3., 4.])
>>> exp
tensor([ 1., 2., 3., 4.])
>>> torch.pow(a, exp)
tensor([ 1., 4., 27., 256.])
.. function:: pow(self, exponent, *, out=None) -> Tensor
:noindex:
:attr:`self` is a scalar ``float`` value, and :attr:`exponent` is a tensor.
The returned tensor :attr:`out` is of the same shape as :attr:`exponent`
The operation applied is:
.. math::
\text{out}_i = \text{self} ^ {\text{exponent}_i}
Args:
self (float): the scalar base value for the power operation
exponent (Tensor): the exponent tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> exp = torch.arange(1., 5.)
>>> base = 2
>>> torch.pow(base, exp)
tensor([ 2., 4., 8., 16.])
torch.prelu
Python Library Documentation: built-in function prelu in module torch
prelu(...)
prelu(input, weight) -> Tensor
Applies element-wise the function
:math:`\text{PReLU}(x) = \max(0,x) + \text{weight} * \min(0,x)` where weight is a
learnable parameter.
.. note::
`weight` is expected to be a scalar or 1-D tensor. If `weight` is 1-D,
its size must match the number of input channels, determined by
`input.size(1)` when `input.dim() >= 2`, otherwise 1.
In the 1-D case, note that when `input` has dim > 2, `weight` can be expanded
to the shape of `input` in a way that is not possible using normal
:ref:`broadcasting semantics<broadcasting-semantics>`.
See :class:`~torch.nn.PReLU` for more details.
torch.prepare_multiprocessing_environment
Python Library Documentation: function prepare_multiprocessing_environment in module torch._utils_internal prepare_multiprocessing_environment(path: str) -> None
torch.preserve_format
Python Library Documentation: memory_format object class memory_format(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self).
torch.prod
Python Library Documentation: built-in function prod in module torch
prod(...)
prod(input: Tensor, *, dtype: Optional[_dtype]) -> Tensor
Returns the product of all elements in the :attr:`input` tensor.
Args:
input (Tensor): the input tensor.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[-0.8020, 0.5428, -1.5854]])
>>> torch.prod(a)
tensor(0.6902)
.. function:: prod(input, dim, keepdim=False, *, dtype=None) -> Tensor
:noindex:
Returns the product of each row of the :attr:`input` tensor in the given
dimension :attr:`dim`.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
the output tensor having 1 fewer dimension than :attr:`input`.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> a = torch.randn(4, 2)
>>> a
tensor([[ 0.5261, -0.3837],
[ 1.1857, -0.2498],
[-1.1646, 0.0705],
[ 1.1131, -1.0629]])
>>> torch.prod(a, 1)
tensor([-0.2018, -0.2962, -0.0821, -1.1831])
torch.profiler
Python Library Documentation: package torch.profiler in torch
NAME
torch.profiler
DESCRIPTION
PyTorch Profiler is a tool that allows the collection of performance metrics during training and inference.
Profiler's context manager API can be used to better understand what model operators are the most expensive,
examine their input shapes and stack traces, study device kernel activity and visualize the execution trace.
.. note::
An earlier version of the API in :mod:`torch.autograd` module is considered legacy and will be deprecated.
PACKAGE CONTENTS
_chrome_trace_export
_cupti_monitor
_cupti_monitor_trace
_memory_profiler
_pattern_matcher
_trace_validator
_utils
itt
profiler
python_tracer
CLASSES
contextlib.ContextDecorator(builtins.object)
torch.autograd.profiler.record_function
enum.Enum(builtins.object)
torch.profiler.profiler.ProfilerAction
pybind11_builtins.pybind11_object(builtins.object)
torch._C._autograd.DeviceType
torch._C._profiler.ProfilerActivity
torch.profiler.profiler._ITraceObserver(abc.ABC)
torch.profiler.profiler.ExecutionTraceObserver
torch.profiler.profiler._KinetoProfile(builtins.object)
torch.profiler.profiler.profile
class DeviceType(pybind11_builtins.pybind11_object)
| Method resolution order:
| DeviceType
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __eq__(...)
| __eq__(self: object, other: object, /) -> bool
|
| __getstate__(...)
| __getstate__(self: object, /) -> int
|
| __hash__(...)
| __hash__(self: object, /) -> int
|
| __index__(...)
| __index__(self: torch._C._autograd.DeviceType, /) -> int
|
| __init__(...)
| __init__(self: torch._C._autograd.DeviceType, value: typing.SupportsInt | typing.SupportsIndex) -> None
|
| __int__(...)
| __int__(self: torch._C._autograd.DeviceType, /) -> int
|
| __ne__(...)
| __ne__(self: object, other: object, /) -> bool
|
| __repr__(...)
| __repr__(self: object, /) -> str
|
| __setstate__(...)
| __setstate__(self: torch._C._autograd.DeviceType, state: typing.SupportsInt | typing.SupportsIndex, /) -> None
|
| __str__(...)
| __str__(self: object, /) -> str
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __members__
|
| name
| name(self: object, /) -> str
|
| value
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| CPU = <DeviceType.CPU: 0>
|
| CUDA = <DeviceType.CUDA: 1>
|
| FPGA = <DeviceType.FPGA: 7>
|
| HIP = <DeviceType.HIP: 6>
|
| HPU = <DeviceType.HPU: 15>
|
| IDEEP = <DeviceType.IDEEP: 5>
|
| IPU = <DeviceType.IPU: 18>
|
| Lazy = <DeviceType.Lazy: 17>
|
| MAIA = <DeviceType.MAIA: 8>
|
| MKLDNN = <DeviceType.MKLDNN: 2>
|
| MPS = <DeviceType.MPS: 13>
|
| MTIA = <DeviceType.MTIA: 19>
|
| Meta = <DeviceType.Meta: 14>
|
| Metal = <DeviceType.Metal: 11>
|
| OPENCL = <DeviceType.OPENCL: 4>
|
| OPENGL = <DeviceType.OPENGL: 3>
|
| PrivateUse1 = <DeviceType.PrivateUse1: 20>
|
| VE = <DeviceType.VE: 16>
|
| Vulkan = <DeviceType.Vulkan: 10>
|
| XLA = <DeviceType.XLA: 9>
|
| XPU = <DeviceType.XPU: 12>
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ExecutionTraceObserver(_ITraceObserver)
| ExecutionTraceObserver() -> 'None'
|
| Execution Trace Observer
|
| Each process can have a single ExecutionTraceObserver instance. The observer
| can be added to record function callbacks via calling register_callback()
| explicitly. Without calling unregister_callback(), repeated calls to
| register_callback() will not add additional observers to record function
| callbacks. Once an ExecutionTraceObserver is created, the start() and stop()
| methods control when the event data is recorded.
|
| Deleting or calling unregister_callback() will remove the observer from the
| record function callbacks, finalize the output file, and will stop
| incurring any overheads.
|
| Method resolution order:
| ExecutionTraceObserver
| _ITraceObserver
| abc.ABC
| builtins.object
|
| Methods defined here:
|
| __del__(self) -> 'None'
| Calls unregister_callback() to make sure to finalize outputs.
|
| __init__(self) -> 'None'
| Initializes the default states.
|
| cleanup(self) -> 'None'
| Calls unregister_callback() to make sure to finalize outputs.
|
| get_output_file_path(self) -> 'str | None'
| Returns the output file name or None.
|
| get_resources_dir(self, can_create=False) -> 'str | None'
| Generates the resources directory for the generated kernels,
| or index tensor data or any other metadata that is required
| to complete the Execution Trace content.
|
| The directory is created right where the ET file is being output.
|
| Only works if the observer has called set_extra_resource_collection(val=True).
|
| Returns None if the observer is not configured with extra resource collection.
|
| is_running(self)
| Returns True if the observer is running, otherwise False.
|
| register_callback(self, output_file_path: 'str') -> 'Self'
| Adds ET observer to record function callbacks. The data will be
| written to output_file_path.
|
| set_extra_resource_collection(self, val) -> 'None'
| Collects extra resources such as generated kernels, index tensor data, and any other
| metadata that is required to complete the Execution Trace content.
|
| The caller should call this method with val=True after calling register_callback() if they want
| to collect the extra resources.
|
| start(self) -> 'None'
| Starts to capture.
|
| stop(self) -> 'None'
| Stops to capture.
|
| unregister_callback(self) -> 'None'
| Removes ET observer from record function callbacks.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| build_execution_trace_obs_from_env() -> 'ExecutionTraceObserver | None'
| Returns an ExecutionTraceObserver instance if the environment variable
| ENABLE_PYTORCH_EXECUTION_TRACE is set to 1, otherwise returns None.
|
| Configures the observer to also collect extra resources if the environment variable
| ``ENABLE_PYTORCH_EXECUTION_TRACE_EXTRAS=1``. These are resources such as generated kernels,
| index tensor data etc. that are required to make the Execution Trace replayable.
|
| get_resources_dir_for_et_path(trace_path, create_dir: 'bool' = False) -> 'str | None'
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| is_registered
| Returns True if the execution trace observer is registered, otherwise False.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _ITraceObserver:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class ProfilerAction(enum.Enum)
| ProfilerAction(*values)
|
| Profiler actions that can be taken at the specified intervals.
|
| NONE, WARMUP, RECORD, and RECORD_AND_SAVE are user-facing values that may
| be returned from a user-provided schedule. DEVICE_STOPPED is set
| internally by the profiler when device collection stops early due to
| errors; it must not be returned from a user-provided schedule.
|
| Method resolution order:
| ProfilerAction
| enum.Enum
| builtins.object
|
| Data and other attributes defined here:
|
| DEVICE_STOPPED = <ProfilerAction.DEVICE_STOPPED: 4>
|
| NONE = <ProfilerAction.NONE: 0>
|
| RECORD = <ProfilerAction.RECORD: 2>
|
| RECORD_AND_SAVE = <ProfilerAction.RECORD_AND_SAVE: 3>
|
| WARMUP = <ProfilerAction.WARMUP: 1>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Static methods inherited from enum.EnumType:
|
| __contains__(value)
| Return True if `value` is in `cls`.
|
| `value` is in `cls` if:
| 1) `value` is a member of `cls`, or
| 2) `value` is the value of one of the `cls`'s members.
|
| __getitem__(name)
| Return the member matching `name`.
|
| __iter__()
| Return members in definition order.
|
| __len__()
| Return the number of members (no aliases)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class ProfilerActivity(pybind11_builtins.pybind11_object)
| Method resolution order:
| ProfilerActivity
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __eq__(...)
| __eq__(self: object, other: object, /) -> bool
|
| __getstate__(...)
| __getstate__(self: object, /) -> int
|
| __hash__(...)
| __hash__(self: object, /) -> int
|
| __index__(...)
| __index__(self: torch._C._profiler.ProfilerActivity, /) -> int
|
| __init__(...)
| __init__(self: torch._C._profiler.ProfilerActivity, value: typing.SupportsInt | typing.SupportsIndex) -> None
|
| __int__(...)
| __int__(self: torch._C._profiler.ProfilerActivity, /) -> int
|
| __ne__(...)
| __ne__(self: object, other: object, /) -> bool
|
| __repr__(...)
| __repr__(self: object, /) -> str
|
| __setstate__(...)
| __setstate__(self: torch._C._profiler.ProfilerActivity, state: typing.SupportsInt | typing.SupportsIndex, /) -> None
|
| __str__(...)
| __str__(self: object, /) -> str
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __members__
|
| name
| name(self: object, /) -> str
|
| value
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| CPU = <ProfilerActivity.CPU: 0>
|
| CUDA = <ProfilerActivity.CUDA: 2>
|
| HPU = <ProfilerActivity.HPU: 3>
|
| MTIA = <ProfilerActivity.MTIA: 4>
|
| PrivateUse1 = <ProfilerActivity.PrivateUse1: 5>
|
| XPU = <ProfilerActivity.XPU: 1>
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class profile(_KinetoProfile)
| profile(*, activities: 'Iterable[ProfilerActivity | dict[ProfilerActivity, list[str]]] | None' = None, schedule: 'Callable[[int], ProfilerAction] | None' = None, on_trace_ready: 'Callable[..., Any] | None' = None, record_shapes: 'bool' = False, profile_memory: 'bool' = False, with_stack: 'bool' = False, with_flops: 'bool' = False, with_modules: 'bool' = False, experimental_config: '_ExperimentalConfig | None' = None, execution_trace_observer: '_ITraceObserver | None' = None, acc_events: 'bool' = False, use_cuda: 'bool | None' = None, custom_trace_id_callback: 'Callable[[], str] | None' = None, post_processing_timeout_s: 'float | None' = None) -> 'None'
|
| Profiler context manager.
|
| Args:
| activities (iterable): list of activity groups (CPU, CUDA) to use in profiling, supported values:
| ``torch.profiler.ProfilerActivity.CPU``, ``torch.profiler.ProfilerActivity.CUDA``,
| ``torch.profiler.ProfilerActivity.XPU``.
| Default value: ProfilerActivity.CPU and (when available) ProfilerActivity.CUDA
| or (when available) ProfilerActivity.XPU.
|
| Each item can be a ``ProfilerActivity`` enum (collects all default
| activity types for that group) or a ``dict`` mapping a ``ProfilerActivity``
| to a list of individual activity type names to collect, e.g.
| ``{ProfilerActivity.CUDA: ["GPU_MEMCPY", "CUDA_RUNTIME"]}``.
| An empty list (e.g. ``{ProfilerActivity.CUDA: []}``) means collect
| nothing for that group.
| The same activity group must not appear more than once.
| schedule (Callable): callable that takes step (int) as a single parameter and returns
| ``ProfilerAction`` value that specifies the profiler action to perform at each step.
| on_trace_ready (Callable): callable invoked at the end of each profiling cycle
| (when ``schedule`` returns ``ProfilerAction.RECORD_AND_SAVE``). Receives the
| :class:`profile` instance as its only argument, typically used to export the
| trace (e.g. via :meth:`export_chrome_trace`) or print a summary.
| record_shapes (bool): save information about operator's input shapes.
| profile_memory (bool): track tensor memory allocation/deallocation.
| with_stack (bool): record source information (file and line number) for the ops.
| with_flops (bool): use formula to estimate the FLOPs (floating point operations) of specific operators
| (matrix multiplication and 2D convolution).
| with_modules (bool): record module hierarchy (including function names)
| corresponding to the callstack of the op. e.g. If module A's forward call's
| module B's forward which contains an aten::add op,
| then aten::add's module hierarchy is A.B
| Note that this support exist, at the moment, only for TorchScript models
| and not eager mode models.
| experimental_config (_ExperimentalConfig) : A set of experimental options
| used for Kineto library features. Note, backward compatibility is not guaranteed.
| execution_trace_observer (ExecutionTraceObserver) : A PyTorch Execution Trace Observer object.
| `PyTorch Execution Traces <https://arxiv.org/pdf/2305.14516.pdf>`__ offer a graph based
| representation of AI/ML workloads and enable replay benchmarks, simulators, and emulators.
| When this argument is included the observer start() and stop() will be called for the
| same time window as PyTorch profiler. See the examples section below for a code sample.
| acc_events (bool): Enable the accumulation of FunctionEvents across multiple profiling cycles
| post_processing_timeout_s (float): Optional timeout in seconds for post-processing profiler
| results. If specified, event parsing will stop after this duration and return partial
| results. Useful for handling large traces that may take too long to process.
| custom_trace_id_callback (Callable[[], str], optional): User-supplied trace ID generator,
| invoked once per profiling cycle. Defaults to a random UUID; retrieve via
| :meth:`get_trace_id`.
| use_cuda (bool):
| .. deprecated:: 1.8.1
| use ``activities`` instead.
|
| .. note::
| Use :func:`~torch.profiler.schedule` to generate the callable schedule.
| Non-default schedules are useful when profiling long training jobs
| and allow the user to obtain multiple traces at the different iterations
| of the training process.
| The default schedule simply records all the events continuously for the
| duration of the context manager.
|
| .. note::
| Use :func:`~torch.profiler.tensorboard_trace_handler` to generate result files for TensorBoard:
|
| ``on_trace_ready=torch.profiler.tensorboard_trace_handler(dir_name)``
|
| After profiling, result files can be found in the specified directory. Use the command:
|
| ``tensorboard --logdir dir_name``
|
| to see the results in TensorBoard.
| For more information, see
| `PyTorch Profiler TensorBoard Plugin <https://github.com/pytorch/kineto/tree/master/tb_plugin>`__
|
| .. note::
| Enabling shape and stack tracing results in additional overhead.
| When record_shapes=True is specified, profiler will temporarily hold references to the tensors;
| that may further prevent certain optimizations that depend on the reference count and introduce
| extra tensor copies.
|
|
| Examples:
|
| .. code-block:: python
|
| with torch.profiler.profile(
| activities=[
| torch.profiler.ProfilerActivity.CPU,
| torch.profiler.ProfilerActivity.CUDA,
| ]
| ) as p:
| code_to_profile()
| print(p.key_averages().table(sort_by="self_cuda_time_total", row_limit=-1))
|
| Using the profiler's ``schedule``, ``on_trace_ready`` and ``step`` functions:
|
| .. code-block:: python
|
| # Non-default profiler schedule allows user to turn profiler on and off
| # on different iterations of the training loop;
| # trace_handler is called every time a new trace becomes available
| def trace_handler(prof):
| print(
| prof.key_averages().table(sort_by="self_cuda_time_total", row_limit=-1)
| )
| # prof.export_chrome_trace("/tmp/test_trace_" + str(prof.step_num) + ".json")
|
|
| with torch.profiler.profile(
| activities=[
| torch.profiler.ProfilerActivity.CPU,
| torch.profiler.ProfilerActivity.CUDA,
| ],
| # In this example with wait=1, warmup=1, active=2, repeat=1,
| # profiler will skip the first step/iteration,
| # start warming up on the second, record
| # the third and the forth iterations,
| # after which the trace will become available
| # and on_trace_ready (when set) is called;
| # the cycle repeats starting with the next step
| schedule=torch.profiler.schedule(wait=1, warmup=1, active=2, repeat=1),
| on_trace_ready=trace_handler,
| # on_trace_ready=torch.profiler.tensorboard_trace_handler('./log')
| # used when outputting for tensorboard
| ) as p:
| for iter in range(N):
| code_iteration_to_profile(iter)
| # send a signal to the profiler that the next iteration has started
| p.step()
|
| The following sample shows how to setup up an Execution Trace Observer (`execution_trace_observer`)
|
| .. code-block:: python
|
| with torch.profiler.profile(
| ...
| execution_trace_observer=(
| ExecutionTraceObserver().register_callback("./execution_trace.json")
| ),
| ) as p:
| for iter in range(N):
| code_iteration_to_profile(iter)
| p.step()
|
| You can also refer to test_execution_trace_with_kineto() in tests/profiler/test_profiler.py.
| Note: One can also pass any object satisfying the _ITraceObserver interface.
|
| Method resolution order:
| profile
| _KinetoProfile
| builtins.object
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, exc_type, exc_val, exc_tb)
|
| __init__(self, *, activities: 'Iterable[ProfilerActivity | dict[ProfilerActivity, list[str]]] | None' = None, schedule: 'Callable[[int], ProfilerAction] | None' = None, on_trace_ready: 'Callable[..., Any] | None' = None, record_shapes: 'bool' = False, profile_memory: 'bool' = False, with_stack: 'bool' = False, with_flops: 'bool' = False, with_modules: 'bool' = False, experimental_config: '_ExperimentalConfig | None' = None, execution_trace_observer: '_ITraceObserver | None' = None, acc_events: 'bool' = False, use_cuda: 'bool | None' = None, custom_trace_id_callback: 'Callable[[], str] | None' = None, post_processing_timeout_s: 'float | None' = None) -> 'None'
| Initialize self. See help(type(self)) for accurate signature.
|
| get_trace_id(self)
| Returns the current trace ID.
|
| set_custom_trace_id_callback(self, callback) -> 'None'
| Set the trace ID generator. Called at the start of each cycle, so updating
| it between cycles yields distinct IDs per cycle.
|
| start(self) -> 'None'
|
| step(self) -> 'None'
| Signals the profiler that the next profiling step has started.
|
| stop(self) -> 'None'
|
| ----------------------------------------------------------------------
| Methods inherited from _KinetoProfile:
|
| add_metadata(self, key: 'str', value: 'str') -> 'None'
| Adds a user defined metadata with a string key and a string value
| into the trace file
|
| add_metadata_json(self, key: 'str', value: 'str') -> 'None'
| Adds a user defined metadata with a string key and a valid json value
| into the trace file
|
| events(self)
| Return the list of unaggregated :class:`~torch.autograd.profiler_util.FunctionEvent`
| objects, for use in the trace callback or after profiling has finished.
|
| export_chrome_trace(self, path: 'str', use_python_export: 'bool' = False)
| Exports the collected trace in Chrome JSON format. If kineto is enabled, only
| last cycle in schedule is exported.
|
| export_memory_timeline(self, path: 'str', device: 'str | None' = None) -> 'None'
| Export memory event information from the profiler collected
| tree for a given device, and export a timeline plot. There are 3
| exportable files using ``export_memory_timeline``, each controlled by the
| ``path``'s suffix.
|
| - For an HTML compatible plot, use the suffix ``.html``, and a memory timeline
| plot will be embedded as a PNG file in the HTML file.
|
| - For plot points consisting of ``[times, [sizes by category]]``, where
| ``times`` are timestamps and ``sizes`` are memory usage for each category.
| The memory timeline plot will be saved a JSON (``.json``) or gzipped JSON
| (``.json.gz``) depending on the suffix.
|
| - For raw memory points, use the suffix ``.raw.json.gz``. Each raw memory
| event will consist of ``(timestamp, action, numbytes, category)``, where
| ``action`` is one of ``[PREEXISTING, CREATE, INCREMENT_VERSION, DESTROY]``,
| and ``category`` is one of the enums from
| ``torch.profiler._memory_profiler.Category``.
|
| Output: Memory timeline written as gzipped JSON, JSON, or HTML.
|
| .. deprecated::
| ``export_memory_timeline`` is deprecated and will be removed in a future version.
| Please use ``torch.cuda.memory._record_memory_history`` and
| ``torch.cuda.memory._export_memory_snapshot`` instead.
|
| export_stacks(self, path: 'str', metric: 'str' = 'self_cpu_time_total')
| Save stack traces to a file
|
| Args:
| path (str): save stacks file to this location;
| metric (str): metric to use: "self_cpu_time_total" or "self_cuda_time_total"
|
| key_averages(self, group_by_input_shape: 'bool' = False, group_by_stack_n: 'int' = 0, group_by_overload_name: 'bool' = False)
| Averages events, grouping them by operator name and (optionally) input shapes, stack
| and overload name.
|
| Returns an :class:`~torch.autograd.profiler_util.EventList` of the aggregated events.
|
| .. note::
| To use shape/stack functionality make sure to set record_shapes/with_stack
| when creating profiler context manager.
|
| prepare_trace(self) -> 'None'
|
| preset_metadata_json(self, key: 'str', value: 'str') -> 'None'
| Preset a user defined metadata when the profiler is not started
| and added into the trace file later.
| Metadata is in the format of a string key and a valid json value
|
| start_trace(self) -> 'None'
|
| stop_trace(self) -> 'None'
|
| toggle_collection_dynamic(self, enable: 'bool', activities: 'Iterable[ProfilerActivity]') -> 'None'
| Toggle collection of activities on/off at any point of collection. Currently supports toggling Torch Ops
| (CPU) and CUDA activity supported in Kineto
|
| Args:
| activities (iterable): list of activity groups to use in profiling, supported values:
| ``torch.profiler.ProfilerActivity.CPU``, ``torch.profiler.ProfilerActivity.CUDA``
| Examples:
|
| .. code-block:: python
|
| with torch.profiler.profile(
| activities=[
| torch.profiler.ProfilerActivity.CPU,
| torch.profiler.ProfilerActivity.CUDA,
| ]
| ) as p:
| code_to_profile_0()
| // turn off collection of all CUDA activity
| p.toggle_collection_dynamic(False, [torch.profiler.ProfilerActivity.CUDA])
| code_to_profile_1()
| // turn on collection of all CUDA activity
| p.toggle_collection_dynamic(True, [torch.profiler.ProfilerActivity.CUDA])
| code_to_profile_2()
| print(p.key_averages().table(
| sort_by="self_cuda_time_total", row_limit=-1))
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _KinetoProfile:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class record_function(contextlib.ContextDecorator)
| record_function(name: str, args: str | None = None)
|
| Context manager/function decorator that adds a label to a code block/function when running autograd profiler.
| Label will only appear if CPU activity tracing is enabled.
|
| It is useful when tracing the code profile.
|
| Args:
| name (str): Label assigned to the block of code.
| node_id (int): ID of node, for distributed profiling. Unset in
| non-distributed cases.
|
| Example:
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_AUTOGRAD_PROFILER)
| >>> x = torch.randn((1, 1), requires_grad=True)
| >>> with torch.autograd.profiler.profile() as prof:
| ... y = x**2
| ... with torch.autograd.profiler.record_function(
| ... "label-z"
| ... ): # label the block
| ... z = y**3
| ... y.backward()
| >>> # xdoctest: +IGNORE_WANT
| >>> # NOTE: some columns were removed for brevity
| >>> print(prof.key_averages().table(sort_by="self_cpu_time_total"))
| ----------------------------------- --------------- --------------- ---------------
| Name Self CPU total % CPU time avg Number of Calls
| ----------------------------------- --------------- --------------- ---------------
| pow 60.77% 47.470us 3
| mul 21.73% 25.465us 2
| PowBackward0 12.03% 121.891us 1
| torch::autograd::AccumulateGrad 2.70% 6.324us 1
| label-z 2.13% 12.421us 1
| torch::autograd::GraphRoot 0.64% 1.503us 1
| ----------------------------------- --------------- --------------- ---------------
| Self CPU time total: 234.344us
| CUDA time total: 0.000us
|
| Method resolution order:
| record_function
| contextlib.ContextDecorator
| builtins.object
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, exc_type: Any, exc_value: Any, traceback: Any)
|
| __init__(self, name: str, args: str | None = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from contextlib.ContextDecorator:
|
| __call__(self, func)
| Call self as a function.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from contextlib.ContextDecorator:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
kineto_available(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
kineto_available() -> bool
schedule(*, wait: 'int', warmup: 'int', active: 'int', repeat: 'int' = 0, skip_first: 'int' = 0, skip_first_wait: 'int' = 0) -> 'Callable'
Returns a callable that can be used as profiler ``schedule`` argument. The profiler will skip
the first ``skip_first`` steps, then wait for ``wait`` steps, then do the warmup for the next ``warmup`` steps,
then do the active recording for the next ``active`` steps and then repeat the cycle starting with ``wait`` steps.
The optional number of cycles is specified with the ``repeat`` parameter, the zero value means that
the cycles will continue until the profiling is finished.
The ``skip_first_wait`` parameter controls whether the first ``wait`` stage should be skipped.
This can be useful if a user wants to wait longer than ``skip_first`` between cycles, but not
for the first profile. For example, if ``skip_first`` is 10 and ``wait`` is 20, the first cycle will
wait 10 + 20 = 30 steps before warmup if ``skip_first_wait`` is zero, but will wait only 10
steps if ``skip_first_wait`` is non-zero. All subsequent cycles will then wait 20 steps between the
last active and warmup.
supported_activities()
Returns a set of supported profiler tracing activities.
Note: profiler uses CUPTI library to trace on-device CUDA kernels.
In case when CUDA is enabled but CUPTI is not available, passing
``ProfilerActivity.CUDA`` to profiler results in using the legacy CUDA
profiling code (same as in the legacy ``torch.autograd.profiler``).
This, in turn, results in including CUDA time in the profiler table output,
but not in the JSON trace.
tensorboard_trace_handler(dir_name: 'str', worker_name: 'str | None' = None, use_gzip: 'bool' = False, use_python_export: 'bool' = False)
Outputs tracing files to directory of ``dir_name``, then that directory can be
directly delivered to tensorboard as logdir.
``worker_name`` should be unique for each worker in distributed scenario,
it will be set to '[hostname]_[pid]' by default.
DATA
__all__ = ['profile', 'schedule', 'supported_activities', 'tensorboard...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\profiler\__init__.py
torch.profiler_allow_cudagraph_cupti_lazy_reinit_cuda12
Python Library Documentation: function profiler_allow_cudagraph_cupti_lazy_reinit_cuda12 in module torch._utils_internal profiler_allow_cudagraph_cupti_lazy_reinit_cuda12()
torch.promote_types
Python Library Documentation: built-in function promote_types in module torch
promote_types(...)
promote_types(type1, type2) -> dtype
Returns the :class:`torch.dtype` with the smallest size and scalar kind that is
not smaller nor of lower kind than either `type1` or `type2`. See type promotion
:ref:`documentation <type-promotion-doc>` for more information on the type
promotion logic.
Args:
type1 (:class:`torch.dtype`)
type2 (:class:`torch.dtype`)
Example::
>>> torch.promote_types(torch.int32, torch.float32)
torch.float32
>>> torch.promote_types(torch.uint8, torch.long)
torch.long
torch.put
Python Library Documentation: built-in function put in module torch put(...)
torch.q_per_channel_axis
Python Library Documentation: built-in function q_per_channel_axis in module torch q_per_channel_axis(...)
torch.q_per_channel_scales
Python Library Documentation: built-in function q_per_channel_scales in module torch q_per_channel_scales(...)
torch.q_per_channel_zero_points
Python Library Documentation: built-in function q_per_channel_zero_points in module torch q_per_channel_zero_points(...)
torch.q_scale
Python Library Documentation: built-in function q_scale in module torch q_scale(...)
torch.q_zero_point
Python Library Documentation: built-in function q_zero_point in module torch q_zero_point(...)
torch.qint32
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.qint8
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.qr
Python Library Documentation: built-in function qr in module torch
qr(...)
qr(input: Tensor, some: bool = True, *, out: Union[Tensor, Tuple[Tensor, ...], List[Tensor], None]) -> (Tensor, Tensor)
Computes the QR decomposition of a matrix or a batch of matrices :attr:`input`,
and returns a namedtuple (Q, R) of tensors such that :math:`\text{input} = Q R`
with :math:`Q` being an orthogonal matrix or batch of orthogonal matrices and
:math:`R` being an upper triangular matrix or batch of upper triangular matrices.
If :attr:`some` is ``True``, then this function returns the thin (reduced) QR factorization.
Otherwise, if :attr:`some` is ``False``, this function returns the complete QR factorization.
.. warning::
:func:`torch.qr` is deprecated in favor of :func:`torch.linalg.qr`
and will be removed in a future PyTorch release. The boolean parameter :attr:`some` has been
replaced with a string parameter :attr:`mode`.
``Q, R = torch.qr(A)`` should be replaced with
.. code:: python
Q, R = torch.linalg.qr(A)
``Q, R = torch.qr(A, some=False)`` should be replaced with
.. code:: python
Q, R = torch.linalg.qr(A, mode="complete")
.. warning::
If you plan to backpropagate through QR, note that the current backward implementation
is only well-defined when the first :math:`\min(input.size(-1), input.size(-2))`
columns of :attr:`input` are linearly independent.
This behavior will probably change once QR supports pivoting.
.. note:: This function uses LAPACK for CPU inputs and MAGMA for CUDA inputs,
and may produce different (valid) decompositions on different device types
or different platforms.
Args:
input (Tensor): the input tensor of size :math:`(*, m, n)` where `*` is zero or more
batch dimensions consisting of matrices of dimension :math:`m \times n`.
some (bool, optional): Set to ``True`` for reduced QR decomposition and ``False`` for
complete QR decomposition. If `k = min(m, n)` then:
* ``some=True`` : returns `(Q, R)` with dimensions (m, k), (k, n) (default)
* ``'some=False'``: returns `(Q, R)` with dimensions (m, m), (m, n)
Keyword args:
out (tuple, optional): tuple of `Q` and `R` tensors.
The dimensions of `Q` and `R` are detailed in the description of :attr:`some` above.
Example::
>>> a = torch.tensor([[12., -51, 4], [6, 167, -68], [-4, 24, -41]])
>>> q, r = torch.qr(a)
>>> q
tensor([[-0.8571, 0.3943, 0.3314],
[-0.4286, -0.9029, -0.0343],
[ 0.2857, -0.1714, 0.9429]])
>>> r
tensor([[ -14.0000, -21.0000, 14.0000],
[ 0.0000, -175.0000, 70.0000],
[ 0.0000, 0.0000, -35.0000]])
>>> torch.mm(q, r).round()
tensor([[ 12., -51., 4.],
[ 6., 167., -68.],
[ -4., 24., -41.]])
>>> torch.mm(q.t(), q).round()
tensor([[ 1., 0., 0.],
[ 0., 1., -0.],
[ 0., -0., 1.]])
>>> a = torch.randn(3, 4, 5)
>>> q, r = torch.qr(a, some=False)
>>> torch.allclose(torch.matmul(q, r), a)
True
>>> torch.allclose(torch.matmul(q.mT, q), torch.eye(5))
True
torch.qscheme
Python Library Documentation: class qscheme in module torch class qscheme(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self).
torch.quantile
Python Library Documentation: built-in function quantile in module torch
quantile(...)
quantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
Computes the q-th quantiles of each row of the :attr:`input` tensor along the dimension :attr:`dim`.
To compute the quantile, we map q in [0, 1] to the range of indices [0, n] to find the location
of the quantile in the sorted input. If the quantile lies between two data points ``a < b`` with
indices ``i`` and ``j`` in the sorted order, result is computed according to the given
:attr:`interpolation` method as follows:
- ``linear``: ``a + (b - a) * fraction``, where ``fraction`` is the fractional part of the computed quantile index.
- ``lower``: ``a``.
- ``higher``: ``b``.
- ``nearest``: ``a`` or ``b``, whichever's index is closer to the computed quantile index (follows :func:`torch.round`).
- ``midpoint``: ``(a + b) / 2``.
If :attr:`q` is a 1D tensor, the first dimension of the output represents the quantiles and has size
equal to the size of :attr:`q`, the remaining dimensions are what remains from the reduction.
.. note::
By default :attr:`dim` is ``None`` resulting in the :attr:`input` tensor being flattened before computation.
Args:
input (Tensor): the input tensor.
q (float or Tensor): a scalar or 1D tensor of values in the range [0, 1].
dim (int, optional): the dimension to reduce.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword arguments:
interpolation (str, optional): interpolation method to use when the desired quantile lies between two data points.
Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
Default is ``linear``.
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(2, 3)
>>> a
tensor([[ 0.0795, -1.2117, 0.9765],
[ 1.1707, 0.6706, 0.4884]])
>>> q = torch.tensor([0.25, 0.5, 0.75])
>>> torch.quantile(a, q, dim=1, keepdim=True)
tensor([[[-0.5661],
[ 0.5795]],
[[ 0.0795],
[ 0.6706]],
[[ 0.5280],
[ 0.9206]]])
>>> torch.quantile(a, q, dim=1, keepdim=True).shape
torch.Size([3, 2, 1])
>>> a = torch.arange(4.)
>>> a
tensor([0., 1., 2., 3.])
>>> torch.quantile(a, 0.6, interpolation='linear')
tensor(1.8000)
>>> torch.quantile(a, 0.6, interpolation='lower')
tensor(1.)
>>> torch.quantile(a, 0.6, interpolation='higher')
tensor(2.)
>>> torch.quantile(a, 0.6, interpolation='midpoint')
tensor(1.5000)
>>> torch.quantile(a, 0.6, interpolation='nearest')
tensor(2.)
>>> torch.quantile(a, 0.4, interpolation='nearest')
tensor(1.)
torch.quantization
Python Library Documentation: package torch.quantization in torch
NAME
torch.quantization - # mypy: allow-untyped-defs
PACKAGE CONTENTS
_numeric_suite
_numeric_suite_fx
_quantized_conversions
fake_quantize
fuse_modules
fuser_method_mappings
fx (package)
observer
qconfig
quant_type
quantization_mappings
quantize
quantize_fx
quantize_jit
stubs
utils
CLASSES
abc.ABC(builtins.object)
torch.ao.quantization.observer.ObserverBase(abc.ABC, torch.nn.modules.module.Module)
torch.ao.quantization.observer.PlaceholderObserver
enum.IntEnum(builtins.int, enum.ReprEnum)
torch.ao.quantization.quant_type.QuantType
torch.ao.quantization.observer.UniformQuantizationObserverBase(torch.ao.quantization.observer.ObserverBase)
torch.ao.quantization.observer.HistogramObserver
torch.ao.quantization.qconfig.QConfig(builtins.tuple)
torch.ao.quantization.qconfig.QConfig
torch.nn.modules.module.Module(builtins.object)
torch.ao.quantization.observer.ObserverBase(abc.ABC, torch.nn.modules.module.Module)
torch.ao.quantization.observer.PlaceholderObserver
torch.ao.quantization.stubs.DeQuantStub
torch.ao.quantization.stubs.QuantStub
torch.ao.quantization.stubs.QuantWrapper
class DeQuantStub(torch.nn.modules.module.Module)
| DeQuantStub(qconfig: typing.Any | None = None)
|
| Dequantize stub module, before calibration, this is same as identity,
| this will be swapped as `nnq.DeQuantize` in `convert`.
|
| Args:
| qconfig: quantization configuration for the tensor,
| if qconfig is not provided, we will get qconfig from parent modules
|
| Method resolution order:
| DeQuantStub
| torch.nn.modules.module.Module
| builtins.object
|
| Methods defined here:
|
| __init__(self, qconfig: typing.Any | None = None)
| Initialize internal Module state, shared by both nn.Module and ScriptModule.
|
| forward(self, x: torch.Tensor) -> torch.Tensor
| Define the computation performed at every call.
|
| Should be overridden by all subclasses.
|
| .. note::
| Although the recipe for forward pass needs to be defined within
| this function, one should call the :class:`Module` instance afterwards
| instead of this since the former takes care of running the
| registered hooks while the latter silently ignores them.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.nn.modules.module.Module:
|
| __call__ = _wrapped_call_impl(self, *args, **kwargs)
|
| __delattr__(self, name) -> None
| Implement delattr(self, name).
|
| __dir__(self)
| Default dir() implementation.
|
| __getattr__(self, name: str) -> Union[torch.Tensor, ForwardRef('Module')]
| # It is crucial that the return type is not annotated as `Any`, otherwise type checking
| # on `torch.nn.Module` and all its subclasses is largely disabled as a result. See:
| # https://github.com/pytorch/pytorch/pull/115074
|
| __getstate__(self)
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setattr__(self, name: str, value: Union[torch.Tensor, ForwardRef('Module')]) -> None
| Implement setattr(self, name, value).
|
| __setstate__(self, state)
|
| add_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Add a child module to the current module.
|
| The module can be accessed as an attribute using the given name.
|
| Args:
| name (str): name of the child module. The child module can be
| accessed from this module using the given name
| module (Module): child module to be added to the module.
|
| apply(self, fn: collections.abc.Callable[['Module'], None]) -> Self
| Apply ``fn`` recursively to every submodule (as returned by ``.children()``) as well as self.
|
| Typical use includes initializing the parameters of a model
| (see also :ref:`nn-init-doc`).
|
| Args:
| fn (:class:`Module` -> None): function to be applied to each submodule
|
| Returns:
| Module: self
|
| Example::
|
| >>> @torch.no_grad()
| >>> def init_weights(m):
| >>> print(m)
| >>> if type(m) is nn.Linear:
| >>> m.weight.fill_(1.0)
| >>> print(m.weight)
| >>> net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
| >>> net.apply(init_weights)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
|
| bfloat16(self) -> Self
| Casts all floating point parameters and buffers to ``bfloat16`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| buffers(self, recurse: bool = True) -> collections.abc.Iterator[torch.Tensor]
| Return an iterator over module buffers.
|
| Args:
| recurse (bool): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module.
|
| Yields:
| torch.Tensor: module buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for buf in model.buffers():
| >>> print(type(buf), buf.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| children(self) -> collections.abc.Iterator['Module']
| Return an iterator over immediate children modules.
|
| Yields:
| Module: a child module
|
| compile(self, *args, **kwargs) -> None
| Compile this Module's forward using :func:`torch.compile`.
|
| This Module's `__call__` method is compiled and all arguments are passed as-is
| to :func:`torch.compile`.
|
| See :func:`torch.compile` for details on the arguments for this function.
|
| cpu(self) -> Self
| Move all model parameters and buffers to the CPU.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| cuda(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the GPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on GPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| double(self) -> Self
| Casts all floating point parameters and buffers to ``double`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| eval(self) -> Self
| Set the module in evaluation mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e. whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| This is equivalent with :meth:`self.train(False) <torch.nn.Module.train>`.
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.eval()` and several similar mechanisms that may be confused with it.
|
| Returns:
| Module: self
|
| extra_repr(self) -> str
| Return the extra representation of the module.
|
| To print customized extra information, you should re-implement
| this method in your own modules. Both single-line and multi-line
| strings are acceptable.
|
| float(self) -> Self
| Casts all floating point parameters and buffers to ``float`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| get_buffer(self, target: str) -> torch.Tensor
| Return the buffer given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the buffer
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.Tensor: The buffer referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not a
| buffer
|
| get_extra_state(self) -> Any
| Return any extra state to include in the module's state_dict.
|
| Implement this and a corresponding :func:`set_extra_state` for your module
| if you need to store extra state. This function is called when building the
| module's `state_dict()`.
|
| Note that extra state should be picklable to ensure working serialization
| of the state_dict. We only provide backwards compatibility guarantees
| for serializing Tensors; other objects may break backwards compatibility if
| their serialized pickled form changes.
|
| Returns:
| object: Any extra state to store in the module's state_dict
|
| get_parameter(self, target: str) -> torch.nn.parameter.Parameter
| Return the parameter given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the Parameter
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Parameter: The Parameter referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not an
| ``nn.Parameter``
|
| get_submodule(self, target: str) -> 'Module'
| Return the submodule given by ``target`` if it exists, otherwise throw an error.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(16, 33, kernel_size=(3, 3), stride=(2, 2))
| )
| (linear): Linear(in_features=100, out_features=200, bias=True)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` which has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To check whether or not we have the ``linear`` submodule, we
| would call ``get_submodule("net_b.linear")``. To check whether
| we have the ``conv`` submodule, we would call
| ``get_submodule("net_b.net_c.conv")``.
|
| The runtime of ``get_submodule`` is bounded by the degree
| of module nesting in ``target``. A query against
| ``named_modules`` achieves the same result, but it is O(N) in
| the number of transitive modules. So, for a simple check to see
| if some submodule exists, ``get_submodule`` should always be
| used.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Module: The submodule referenced by ``target``
|
| Raises:
| AttributeError: If at any point along the path resulting from
| the target string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| half(self) -> Self
| Casts all floating point parameters and buffers to ``half`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| ipu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the IPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on IPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| load_state_dict(self, state_dict: collections.abc.Mapping[str, typing.Any], strict: bool = True, assign: bool = False)
| Copy parameters and buffers from :attr:`state_dict` into this module and its descendants.
|
| If :attr:`strict` is ``True``, then
| the keys of :attr:`state_dict` must exactly match the keys returned
| by this module's :meth:`~torch.nn.Module.state_dict` function.
|
| .. warning::
| If :attr:`assign` is ``True`` the optimizer must be created after
| the call to :attr:`load_state_dict` unless
| :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| Args:
| state_dict (dict): a dict containing parameters and
| persistent buffers.
| strict (bool, optional): whether to strictly enforce that the keys
| in :attr:`state_dict` match the keys returned by this module's
| :meth:`~torch.nn.Module.state_dict` function. Default: ``True``
| assign (bool, optional): When set to ``False``, the properties of the tensors
| in the current module are preserved whereas setting it to ``True`` preserves
| properties of the Tensors in the state dict. The only
| exception is the ``requires_grad`` field of :class:`~torch.nn.Parameter`
| for which the value from the module is preserved. Default: ``False``
|
| Returns:
| ``NamedTuple`` with ``missing_keys`` and ``unexpected_keys`` fields:
| * ``missing_keys`` is a list of str containing any keys that are expected
| by this module but missing from the provided ``state_dict``.
| * ``unexpected_keys`` is a list of str containing the keys that are not
| expected by this module but present in the provided ``state_dict``.
|
| Note:
| If a parameter or buffer is registered as ``None`` and its corresponding key
| exists in :attr:`state_dict`, :meth:`load_state_dict` will raise a
| ``RuntimeError``.
|
| modules(self, remove_duplicate: bool = True) -> collections.abc.Iterator['Module']
| Return an iterator over all modules in the network.
|
| Args:
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not.
|
| Yields:
| Module: a module in the network
|
| Note:
| Duplicate modules are returned only once by default. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.modules()):
| ... print(idx, '->', m)
|
| 0 -> Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
| 1 -> Linear(in_features=2, out_features=2, bias=True)
|
| mtia(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the MTIA.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on MTIA while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| named_buffers(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.Tensor]]
| Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
|
| Args:
| prefix (str): prefix to prepend to all buffer names.
| recurse (bool, optional): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module. Defaults to True.
| remove_duplicate (bool, optional): whether to remove the duplicated buffers in the result. Defaults to True.
|
| Yields:
| (str, torch.Tensor): Tuple containing the name and buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, buf in self.named_buffers():
| >>> if name in ['running_var']:
| >>> print(buf.size())
|
| named_children(self) -> collections.abc.Iterator[tuple[str, 'Module']]
| Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
|
| Yields:
| (str, Module): Tuple containing a name and child module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, module in model.named_children():
| >>> if name in ['conv4', 'conv5']:
| >>> print(module)
|
| named_modules(self, memo: set['Module'] | None = None, prefix: str = '', remove_duplicate: bool = True)
| Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
|
| Args:
| memo: a memo to store the set of modules already added to the result
| prefix: a prefix that will be added to the name of the module
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not
|
| Yields:
| (str, Module): Tuple of name and module
|
| Note:
| Duplicate modules are returned only once. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.named_modules()):
| ... print(idx, '->', m)
|
| 0 -> ('', Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| ))
| 1 -> ('0', Linear(in_features=2, out_features=2, bias=True))
|
| named_parameters(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.nn.parameter.Parameter]]
| Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
|
| Args:
| prefix (str): prefix to prepend to all parameter names.
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
| remove_duplicate (bool, optional): whether to remove the duplicated
| parameters in the result. Defaults to True.
|
| Yields:
| (str, Parameter): Tuple containing the name and parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, param in self.named_parameters():
| >>> if name in ['bias']:
| >>> print(param.size())
|
| parameters(self, recurse: bool = True) -> collections.abc.Iterator[torch.nn.parameter.Parameter]
| Return an iterator over module parameters.
|
| This is typically passed to an optimizer.
|
| Args:
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
|
| Yields:
| Parameter: module parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for param in model.parameters():
| >>> print(type(param), param.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| register_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None]) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| This function is deprecated in favor of :meth:`~torch.nn.Module.register_full_backward_hook` and
| the behavior of this function will change in future versions.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_buffer(self, name: str, tensor: torch.Tensor | None, persistent: bool = True) -> None
| Add a buffer to the module.
|
| This is typically used to register a buffer that should not be
| considered a model parameter. For example, BatchNorm's ``running_mean``
| is not a parameter, but is part of the module's state. Buffers, by
| default, are persistent and will be saved alongside parameters. This
| behavior can be changed by setting :attr:`persistent` to ``False``. The
| only difference between a persistent buffer and a non-persistent buffer
| is that the latter will not be a part of this module's
| :attr:`state_dict`.
|
| Buffers can be accessed as attributes using given names.
|
| Args:
| name (str): name of the buffer. The buffer can be accessed
| from this module using the given name
| tensor (Tensor or None): buffer to be registered. If ``None``, then operations
| that run on buffers, such as :attr:`cuda`, are ignored. If ``None``,
| the buffer is **not** included in the module's :attr:`state_dict`.
| persistent (bool): whether the buffer is part of this module's
| :attr:`state_dict`.
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> self.register_buffer('running_mean', torch.zeros(num_features))
|
| register_forward_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...], typing.Any], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any], typing.Any], typing.Any | None], *, prepend: bool = False, with_kwargs: bool = False, always_call: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward hook on the module.
|
| The hook will be called every time after :func:`forward` has computed an output.
|
| If ``with_kwargs`` is ``False`` or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| output. It can modify the input inplace but it will not have effect on
| forward since this is called after :func:`forward` is called. The hook
| should have the following signature::
|
| hook(module, args, output) -> None or modified output
|
| If ``with_kwargs`` is ``True``, the forward hook will be passed the
| ``kwargs`` given to the forward function and be expected to return the
| output possibly modified. The hook should have the following signature::
|
| hook(module, args, kwargs, output) -> None or modified output
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If ``True``, the provided ``hook`` will be fired
| before all existing ``forward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``forward`` hooks registered with
| :func:`register_module_forward_hook` will fire before all hooks
| registered by this method.
| Default: ``False``
| with_kwargs (bool): If ``True``, the ``hook`` will be passed the
| kwargs given to the forward function.
| Default: ``False``
| always_call (bool): If ``True`` the ``hook`` will be run regardless of
| whether an exception is raised while calling the Module.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_forward_pre_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...]], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[typing.Any, dict[str, typing.Any]] | None], *, prepend: bool = False, with_kwargs: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward pre-hook on the module.
|
| The hook will be called every time before :func:`forward` is invoked.
|
|
| If ``with_kwargs`` is false or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| input. User can either return a tuple or a single modified value in the
| hook. We will wrap the value into a tuple if a single value is returned
| (unless that value is already a tuple). The hook should have the
| following signature::
|
| hook(module, args) -> None or modified input
|
| If ``with_kwargs`` is true, the forward pre-hook will be passed the
| kwargs given to the forward function. And if the hook modifies the
| input, both the args and kwargs should be returned. The hook should have
| the following signature::
|
| hook(module, args, kwargs) -> None or a tuple of modified input and kwargs
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``forward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``forward_pre`` hooks registered with
| :func:`register_module_forward_pre_hook` will fire before all
| hooks registered by this method.
| Default: ``False``
| with_kwargs (bool): If true, the ``hook`` will be passed the kwargs
| given to the forward function.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| The hook will be called every time the gradients with respect to a module are computed, and its firing rules are as follows:
|
| 1. Ordinarily, the hook fires when the gradients are computed with respect to the module inputs.
| 2. If none of the module inputs require gradients, the hook will fire when the gradients are computed
| with respect to module outputs.
| 3. If none of the module outputs require gradients, then the hooks will not fire.
|
| The hook should have the following signature::
|
| hook(module, grad_input, grad_output) -> tuple(Tensor) or None
|
| The :attr:`grad_input` and :attr:`grad_output` are tuples that contain the gradients
| with respect to the inputs and outputs respectively. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the input that will be used in place of :attr:`grad_input` in
| subsequent computations. :attr:`grad_input` will only correspond to the inputs given
| as positional arguments and all kwarg arguments are ignored. Entries
| in :attr:`grad_input` and :attr:`grad_output` will be ``None`` for all non-Tensor
| arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs or outputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``backward`` hooks registered with
| :func:`register_module_full_backward_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_pre_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward pre-hook on the module.
|
| The hook will be called every time the gradients for the module are computed.
| The hook should have the following signature::
|
| hook(module, grad_output) -> tuple[Tensor, ...], Tensor or None
|
| The :attr:`grad_output` is a tuple. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the output that will be used in place of :attr:`grad_output` in
| subsequent computations. Entries in :attr:`grad_output` will be ``None`` for
| all non-Tensor arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``backward_pre`` hooks registered with
| :func:`register_module_full_backward_pre_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_post_hook(self, hook)
| Register a post-hook to be run after module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, incompatible_keys) -> None
|
| The ``module`` argument is the current module that this hook is registered
| on, and the ``incompatible_keys`` argument is a ``NamedTuple`` consisting
| of attributes ``missing_keys`` and ``unexpected_keys``. ``missing_keys``
| is a ``list`` of ``str`` containing the missing keys and
| ``unexpected_keys`` is a ``list`` of ``str`` containing the unexpected keys.
|
| The given incompatible_keys can be modified inplace if needed.
|
| Note that the checks performed when calling :func:`load_state_dict` with
| ``strict=True`` are affected by modifications the hook makes to
| ``missing_keys`` or ``unexpected_keys``, as expected. Additions to either
| set of keys will result in an error being thrown when ``strict=True``, and
| clearing out both missing and unexpected keys will avoid an error.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook)
| Register a pre-hook to be run before module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) -> None # noqa: B950
|
| Arguments:
| hook (Callable): Callable hook that will be invoked before
| loading the state dict.
|
| register_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Alias for :func:`add_module`.
|
| register_parameter(self, name: str, param: torch.nn.parameter.Parameter | None) -> None
| Add a parameter to the module.
|
| The parameter can be accessed as an attribute using given name.
|
| Args:
| name (str): name of the parameter. The parameter can be accessed
| from this module using the given name
| param (Parameter or None): parameter to be added to the module. If
| ``None``, then operations that run on parameters, such as :attr:`cuda`,
| are ignored. If ``None``, the parameter is **not** included in the
| module's :attr:`state_dict`.
|
| register_state_dict_post_hook(self, hook)
| Register a post-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata) -> None
|
| The registered hooks can modify the ``state_dict`` inplace.
|
| register_state_dict_pre_hook(self, hook)
| Register a pre-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, prefix, keep_vars) -> None
|
| The registered hooks can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| requires_grad_(self, requires_grad: bool = True) -> Self
| Change if autograd should record operations on parameters in this module.
|
| This method sets the parameters' :attr:`requires_grad` attributes
| in-place.
|
| This method is helpful for freezing part of the module for finetuning
| or training parts of a model individually (e.g., GAN training).
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.requires_grad_()` and several similar mechanisms that may be confused with it.
|
| Args:
| requires_grad (bool): whether autograd should record operations on
| parameters in this module. Default: ``True``.
|
| Returns:
| Module: self
|
| set_extra_state(self, state: Any) -> None
| Set extra state contained in the loaded `state_dict`.
|
| This function is called from :func:`load_state_dict` to handle any extra state
| found within the `state_dict`. Implement this function and a corresponding
| :func:`get_extra_state` for your module if you need to store extra state within its
| `state_dict`.
|
| Args:
| state (dict): Extra state from the `state_dict`
|
| set_submodule(self, target: str, module: 'Module', strict: bool = False) -> None
| Set the submodule given by ``target`` if it exists, otherwise throw an error.
|
| .. note::
| If ``strict`` is set to ``False`` (default), the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``strict`` is set to ``True``,
| the method will only attempt to replace an existing submodule and throw an error if
| the submodule does not exist.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(3, 3, 3)
| )
| (linear): Linear(3, 3)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To override the ``Conv2d`` with a new submodule ``Linear``, you
| could call ``set_submodule("net_b.net_c.conv", nn.Linear(1, 1))``
| where ``strict`` could be ``True`` or ``False``
|
| To add a new submodule ``Conv2d`` to the existing ``net_b`` module,
| you would call ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1))``.
|
| In the above if you set ``strict=True`` and call
| ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1), strict=True)``, an AttributeError
| will be raised because ``net_b`` does not have a submodule named ``conv``.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
| module: The module to set the submodule to.
| strict: If ``False``, the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``True``,
| the method will only attempt to replace an existing submodule and throw an error
| if the submodule doesn't already exist.
|
| Raises:
| ValueError: If the ``target`` string is empty or if ``module`` is not an instance of ``nn.Module``.
| AttributeError: If at any point along the path resulting from
| the ``target`` string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| share_memory(self) -> Self
| See :meth:`torch.Tensor.share_memory_`.
|
| state_dict(self, *args, destination=None, prefix='', keep_vars=False)
| Return a dictionary containing references to the whole state of the module.
|
| Both parameters and persistent buffers (e.g. running averages) are
| included. Keys are corresponding parameter and buffer names.
| Parameters and buffers set to ``None`` are not included.
|
| .. note::
| The returned object is a shallow copy. It contains references
| to the module's parameters and buffers.
|
| .. warning::
| Currently ``state_dict()`` also accepts positional arguments for
| ``destination``, ``prefix`` and ``keep_vars`` in order. However,
| this is being deprecated and keyword arguments will be enforced in
| future releases.
|
| .. warning::
| Please avoid the use of argument ``destination`` as it is not
| designed for end-users.
|
| Args:
| destination (dict, optional): If provided, the state of module will
| be updated into the dict and the same object is returned.
| Otherwise, an ``OrderedDict`` will be created and returned.
| Default: ``None``.
| prefix (str, optional): a prefix added to parameter and buffer
| names to compose the keys in state_dict. Default: ``''``.
| keep_vars (bool, optional): by default the :class:`~torch.Tensor` s
| returned in the state dict are detached from autograd. If it's
| set to ``True``, detaching will not be performed.
| Default: ``False``.
|
| Returns:
| dict:
| a dictionary containing a whole state of the module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> module.state_dict().keys()
| ['bias', 'weight']
|
| to(self, *args, **kwargs)
| Move and/or cast the parameters and buffers.
|
| This can be called as
|
| .. function:: to(device=None, dtype=None, non_blocking=False)
| :noindex:
|
| .. function:: to(dtype, non_blocking=False)
| :noindex:
|
| .. function:: to(tensor, non_blocking=False)
| :noindex:
|
| .. function:: to(memory_format=torch.channels_last)
| :noindex:
|
| Its signature is similar to :meth:`torch.Tensor.to`, but only accepts
| floating point or complex :attr:`dtype`\ s. In addition, this method will
| only cast the floating point or complex parameters and buffers to :attr:`dtype`
| (if given). The integral parameters and buffers will be moved
| :attr:`device`, if that is given, but with dtypes unchanged. When
| :attr:`non_blocking` is set, it tries to convert/move asynchronously
| with respect to the host if possible, e.g., moving CPU Tensors with
| pinned memory to CUDA devices.
|
| See below for examples.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (:class:`torch.device`): the desired device of the parameters
| and buffers in this module
| dtype (:class:`torch.dtype`): the desired floating point or complex dtype of
| the parameters and buffers in this module
| tensor (torch.Tensor): Tensor whose dtype and device are the desired
| dtype and device for all parameters and buffers in this module
| memory_format (:class:`torch.memory_format`): the desired memory
| format for 4D parameters and buffers in this module (keyword
| only argument)
|
| Returns:
| Module: self
|
| Examples::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> linear = nn.Linear(2, 2)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]])
| >>> linear.to(torch.double)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]], dtype=torch.float64)
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA1)
| >>> gpu1 = torch.device("cuda:1")
| >>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
| >>> cpu = torch.device("cpu")
| >>> linear.to(cpu)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16)
|
| >>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.3741+0.j, 0.2382+0.j],
| [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
| >>> linear(torch.ones(3, 2, dtype=torch.cdouble))
| tensor([[0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
|
| to_empty(self, *, device: str | torch.device | int | None, recurse: bool = True) -> Self
| Move the parameters and buffers to the specified device without copying storage.
|
| Args:
| device (:class:`torch.device`): The desired device of the parameters
| and buffers in this module.
| recurse (bool): Whether parameters and buffers of submodules should
| be recursively moved to the specified device.
|
| Returns:
| Module: self
|
| train(self, mode: bool = True) -> Self
| Set the module in training mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e., whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| Args:
| mode (bool): whether to set training mode (``True``) or evaluation
| mode (``False``). Default: ``True``.
|
| Returns:
| Module: self
|
| type(self, dst_type: torch.dtype | str) -> Self
| Casts all parameters and buffers to :attr:`dst_type`.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| dst_type (type or string): the desired type
|
| Returns:
| Module: self
|
| xpu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the XPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing optimizer if the module will
| live on XPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset gradients of all model parameters.
|
| See similar function under :class:`torch.optim.Optimizer` for more context.
|
| Args:
| set_to_none (bool): instead of setting to zero, set the grads to None.
| See :meth:`torch.optim.Optimizer.zero_grad` for details.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.nn.modules.module.Module:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.nn.modules.module.Module:
|
| T_destination = ~T_destination
|
| call_super_init = False
|
| dump_patches = False
class HistogramObserver(UniformQuantizationObserverBase)
| HistogramObserver(bins: int = 2048, dtype: torch.dtype = torch.quint8, qscheme=torch.per_tensor_affine, reduce_range=False, quant_min=None, quant_max=None, factory_kwargs=None, eps=1.1920928955078125e-07, is_dynamic=False, **kwargs) -> None
|
| The module records the running histogram of tensor values along with
| min/max values. ``calculate_qparams`` will calculate scale and zero_point.
|
| Args:
| bins: Number of bins to use for the histogram
| dtype: dtype argument to the `quantize` node needed to implement the
| reference model spec
| qscheme: Quantization scheme to be used
| reduce_range: Reduces the range of the quantized data type by 1 bit
| eps: Epsilon value for float32, Defaults to `torch.finfo(torch.float32).eps`.
|
| The scale and zero point are computed as follows:
|
| 1. Create the histogram of the incoming inputs.
| The histogram is computed continuously, and the ranges per bin change
| with every new tensor observed.
| 2. Search the distribution in the histogram for optimal min/max values.
| The search for the min/max values ensures the minimization of the
| quantization error with respect to the floating point model.
| 3. Compute the scale and zero point the same way as in the
| :class:`~torch.ao.quantization.MinMaxObserver`
|
| Method resolution order:
| HistogramObserver
| UniformQuantizationObserverBase
| ObserverBase
| abc.ABC
| torch.nn.modules.module.Module
| builtins.object
|
| Methods defined here:
|
| __init__(self, bins: int = 2048, dtype: torch.dtype = torch.quint8, qscheme=torch.per_tensor_affine, reduce_range=False, quant_min=None, quant_max=None, factory_kwargs=None, eps=1.1920928955078125e-07, is_dynamic=False, **kwargs) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| calculate_qparams(self)
|
| extra_repr(self)
| Return the extra representation of the module.
|
| To print customized extra information, you should re-implement
| this method in your own modules. Both single-line and multi-line
| strings are acceptable.
|
| forward(self, x_orig: torch.Tensor) -> torch.Tensor
| Define the computation performed at every call.
|
| Should be overridden by all subclasses.
|
| .. note::
| Although the recipe for forward pass needs to be defined within
| this function, one should call the :class:`Module` instance afterwards
| instead of this since the former takes care of running the
| registered hooks while the latter silently ignores them.
|
| reset_histogram(self, x: torch.Tensor, min_val: torch.Tensor, max_val: torch.Tensor) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {'histogram': <class 'torch.Tensor'>, 'max_val': <cl...
|
| ----------------------------------------------------------------------
| Methods inherited from UniformQuantizationObserverBase:
|
| reset_min_max_vals(self)
|
| ----------------------------------------------------------------------
| Class methods inherited from ObserverBase:
|
| with_args = _with_args(**kwargs) from torch.ao.quantization.observer
| Wrapper that allows creation of class factories.
|
| This can be useful when there is a need to create classes with the same
| constructor arguments, but different instances. Can be used in conjunction with
| _callable_args
|
| Example::
|
| >>> # xdoctest: +SKIP("Undefined vars")
| >>> Foo.with_args = classmethod(_with_args)
| >>> foo_builder = Foo.with_args(a=3, b=4).with_args(answer=42)
| >>> foo_instance1 = foo_builder()
| >>> foo_instance2 = foo_builder()
| >>> id(foo_instance1) == id(foo_instance2)
| False
|
| with_callable_args = _with_callable_args(**kwargs) from torch.ao.quantization.observer
| Wrapper that allows creation of class factories args that need to be
| called at construction time.
|
| This can be useful when there is a need to create classes with the same
| constructor arguments, but different instances and those arguments should only
| be calculated at construction time. Can be used in conjunction with _with_args
|
| Example::
|
| >>> # xdoctest: +SKIP("Undefined vars")
| >>> Foo.with_callable_args = classmethod(_with_callable_args)
| >>> Foo.with_args = classmethod(_with_args)
| >>> foo_builder = Foo.with_callable_args(cur_time=get_time_func).with_args(name="dan")
| >>> foo_instance1 = foo_builder()
| >>> # wait 50
| >>> foo_instance2 = foo_builder()
| >>> id(foo_instance1.creation_time) == id(foo_instance2.creation_time)
| False
|
| ----------------------------------------------------------------------
| Data descriptors inherited from abc.ABC:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from torch.nn.modules.module.Module:
|
| __call__ = _wrapped_call_impl(self, *args, **kwargs)
|
| __delattr__(self, name) -> None
| Implement delattr(self, name).
|
| __dir__(self)
| Default dir() implementation.
|
| __getattr__(self, name: str) -> Union[torch.Tensor, ForwardRef('Module')]
| # It is crucial that the return type is not annotated as `Any`, otherwise type checking
| # on `torch.nn.Module` and all its subclasses is largely disabled as a result. See:
| # https://github.com/pytorch/pytorch/pull/115074
|
| __getstate__(self)
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setattr__(self, name: str, value: Union[torch.Tensor, ForwardRef('Module')]) -> None
| Implement setattr(self, name, value).
|
| __setstate__(self, state)
|
| add_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Add a child module to the current module.
|
| The module can be accessed as an attribute using the given name.
|
| Args:
| name (str): name of the child module. The child module can be
| accessed from this module using the given name
| module (Module): child module to be added to the module.
|
| apply(self, fn: collections.abc.Callable[['Module'], None]) -> Self
| Apply ``fn`` recursively to every submodule (as returned by ``.children()``) as well as self.
|
| Typical use includes initializing the parameters of a model
| (see also :ref:`nn-init-doc`).
|
| Args:
| fn (:class:`Module` -> None): function to be applied to each submodule
|
| Returns:
| Module: self
|
| Example::
|
| >>> @torch.no_grad()
| >>> def init_weights(m):
| >>> print(m)
| >>> if type(m) is nn.Linear:
| >>> m.weight.fill_(1.0)
| >>> print(m.weight)
| >>> net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
| >>> net.apply(init_weights)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
|
| bfloat16(self) -> Self
| Casts all floating point parameters and buffers to ``bfloat16`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| buffers(self, recurse: bool = True) -> collections.abc.Iterator[torch.Tensor]
| Return an iterator over module buffers.
|
| Args:
| recurse (bool): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module.
|
| Yields:
| torch.Tensor: module buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for buf in model.buffers():
| >>> print(type(buf), buf.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| children(self) -> collections.abc.Iterator['Module']
| Return an iterator over immediate children modules.
|
| Yields:
| Module: a child module
|
| compile(self, *args, **kwargs) -> None
| Compile this Module's forward using :func:`torch.compile`.
|
| This Module's `__call__` method is compiled and all arguments are passed as-is
| to :func:`torch.compile`.
|
| See :func:`torch.compile` for details on the arguments for this function.
|
| cpu(self) -> Self
| Move all model parameters and buffers to the CPU.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| cuda(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the GPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on GPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| double(self) -> Self
| Casts all floating point parameters and buffers to ``double`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| eval(self) -> Self
| Set the module in evaluation mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e. whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| This is equivalent with :meth:`self.train(False) <torch.nn.Module.train>`.
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.eval()` and several similar mechanisms that may be confused with it.
|
| Returns:
| Module: self
|
| float(self) -> Self
| Casts all floating point parameters and buffers to ``float`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| get_buffer(self, target: str) -> torch.Tensor
| Return the buffer given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the buffer
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.Tensor: The buffer referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not a
| buffer
|
| get_extra_state(self) -> Any
| Return any extra state to include in the module's state_dict.
|
| Implement this and a corresponding :func:`set_extra_state` for your module
| if you need to store extra state. This function is called when building the
| module's `state_dict()`.
|
| Note that extra state should be picklable to ensure working serialization
| of the state_dict. We only provide backwards compatibility guarantees
| for serializing Tensors; other objects may break backwards compatibility if
| their serialized pickled form changes.
|
| Returns:
| object: Any extra state to store in the module's state_dict
|
| get_parameter(self, target: str) -> torch.nn.parameter.Parameter
| Return the parameter given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the Parameter
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Parameter: The Parameter referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not an
| ``nn.Parameter``
|
| get_submodule(self, target: str) -> 'Module'
| Return the submodule given by ``target`` if it exists, otherwise throw an error.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(16, 33, kernel_size=(3, 3), stride=(2, 2))
| )
| (linear): Linear(in_features=100, out_features=200, bias=True)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` which has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To check whether or not we have the ``linear`` submodule, we
| would call ``get_submodule("net_b.linear")``. To check whether
| we have the ``conv`` submodule, we would call
| ``get_submodule("net_b.net_c.conv")``.
|
| The runtime of ``get_submodule`` is bounded by the degree
| of module nesting in ``target``. A query against
| ``named_modules`` achieves the same result, but it is O(N) in
| the number of transitive modules. So, for a simple check to see
| if some submodule exists, ``get_submodule`` should always be
| used.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Module: The submodule referenced by ``target``
|
| Raises:
| AttributeError: If at any point along the path resulting from
| the target string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| half(self) -> Self
| Casts all floating point parameters and buffers to ``half`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| ipu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the IPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on IPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| load_state_dict(self, state_dict: collections.abc.Mapping[str, typing.Any], strict: bool = True, assign: bool = False)
| Copy parameters and buffers from :attr:`state_dict` into this module and its descendants.
|
| If :attr:`strict` is ``True``, then
| the keys of :attr:`state_dict` must exactly match the keys returned
| by this module's :meth:`~torch.nn.Module.state_dict` function.
|
| .. warning::
| If :attr:`assign` is ``True`` the optimizer must be created after
| the call to :attr:`load_state_dict` unless
| :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| Args:
| state_dict (dict): a dict containing parameters and
| persistent buffers.
| strict (bool, optional): whether to strictly enforce that the keys
| in :attr:`state_dict` match the keys returned by this module's
| :meth:`~torch.nn.Module.state_dict` function. Default: ``True``
| assign (bool, optional): When set to ``False``, the properties of the tensors
| in the current module are preserved whereas setting it to ``True`` preserves
| properties of the Tensors in the state dict. The only
| exception is the ``requires_grad`` field of :class:`~torch.nn.Parameter`
| for which the value from the module is preserved. Default: ``False``
|
| Returns:
| ``NamedTuple`` with ``missing_keys`` and ``unexpected_keys`` fields:
| * ``missing_keys`` is a list of str containing any keys that are expected
| by this module but missing from the provided ``state_dict``.
| * ``unexpected_keys`` is a list of str containing the keys that are not
| expected by this module but present in the provided ``state_dict``.
|
| Note:
| If a parameter or buffer is registered as ``None`` and its corresponding key
| exists in :attr:`state_dict`, :meth:`load_state_dict` will raise a
| ``RuntimeError``.
|
| modules(self, remove_duplicate: bool = True) -> collections.abc.Iterator['Module']
| Return an iterator over all modules in the network.
|
| Args:
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not.
|
| Yields:
| Module: a module in the network
|
| Note:
| Duplicate modules are returned only once by default. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.modules()):
| ... print(idx, '->', m)
|
| 0 -> Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
| 1 -> Linear(in_features=2, out_features=2, bias=True)
|
| mtia(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the MTIA.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on MTIA while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| named_buffers(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.Tensor]]
| Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
|
| Args:
| prefix (str): prefix to prepend to all buffer names.
| recurse (bool, optional): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module. Defaults to True.
| remove_duplicate (bool, optional): whether to remove the duplicated buffers in the result. Defaults to True.
|
| Yields:
| (str, torch.Tensor): Tuple containing the name and buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, buf in self.named_buffers():
| >>> if name in ['running_var']:
| >>> print(buf.size())
|
| named_children(self) -> collections.abc.Iterator[tuple[str, 'Module']]
| Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
|
| Yields:
| (str, Module): Tuple containing a name and child module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, module in model.named_children():
| >>> if name in ['conv4', 'conv5']:
| >>> print(module)
|
| named_modules(self, memo: set['Module'] | None = None, prefix: str = '', remove_duplicate: bool = True)
| Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
|
| Args:
| memo: a memo to store the set of modules already added to the result
| prefix: a prefix that will be added to the name of the module
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not
|
| Yields:
| (str, Module): Tuple of name and module
|
| Note:
| Duplicate modules are returned only once. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.named_modules()):
| ... print(idx, '->', m)
|
| 0 -> ('', Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| ))
| 1 -> ('0', Linear(in_features=2, out_features=2, bias=True))
|
| named_parameters(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.nn.parameter.Parameter]]
| Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
|
| Args:
| prefix (str): prefix to prepend to all parameter names.
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
| remove_duplicate (bool, optional): whether to remove the duplicated
| parameters in the result. Defaults to True.
|
| Yields:
| (str, Parameter): Tuple containing the name and parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, param in self.named_parameters():
| >>> if name in ['bias']:
| >>> print(param.size())
|
| parameters(self, recurse: bool = True) -> collections.abc.Iterator[torch.nn.parameter.Parameter]
| Return an iterator over module parameters.
|
| This is typically passed to an optimizer.
|
| Args:
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
|
| Yields:
| Parameter: module parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for param in model.parameters():
| >>> print(type(param), param.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| register_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None]) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| This function is deprecated in favor of :meth:`~torch.nn.Module.register_full_backward_hook` and
| the behavior of this function will change in future versions.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_buffer(self, name: str, tensor: torch.Tensor | None, persistent: bool = True) -> None
| Add a buffer to the module.
|
| This is typically used to register a buffer that should not be
| considered a model parameter. For example, BatchNorm's ``running_mean``
| is not a parameter, but is part of the module's state. Buffers, by
| default, are persistent and will be saved alongside parameters. This
| behavior can be changed by setting :attr:`persistent` to ``False``. The
| only difference between a persistent buffer and a non-persistent buffer
| is that the latter will not be a part of this module's
| :attr:`state_dict`.
|
| Buffers can be accessed as attributes using given names.
|
| Args:
| name (str): name of the buffer. The buffer can be accessed
| from this module using the given name
| tensor (Tensor or None): buffer to be registered. If ``None``, then operations
| that run on buffers, such as :attr:`cuda`, are ignored. If ``None``,
| the buffer is **not** included in the module's :attr:`state_dict`.
| persistent (bool): whether the buffer is part of this module's
| :attr:`state_dict`.
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> self.register_buffer('running_mean', torch.zeros(num_features))
|
| register_forward_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...], typing.Any], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any], typing.Any], typing.Any | None], *, prepend: bool = False, with_kwargs: bool = False, always_call: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward hook on the module.
|
| The hook will be called every time after :func:`forward` has computed an output.
|
| If ``with_kwargs`` is ``False`` or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| output. It can modify the input inplace but it will not have effect on
| forward since this is called after :func:`forward` is called. The hook
| should have the following signature::
|
| hook(module, args, output) -> None or modified output
|
| If ``with_kwargs`` is ``True``, the forward hook will be passed the
| ``kwargs`` given to the forward function and be expected to return the
| output possibly modified. The hook should have the following signature::
|
| hook(module, args, kwargs, output) -> None or modified output
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If ``True``, the provided ``hook`` will be fired
| before all existing ``forward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``forward`` hooks registered with
| :func:`register_module_forward_hook` will fire before all hooks
| registered by this method.
| Default: ``False``
| with_kwargs (bool): If ``True``, the ``hook`` will be passed the
| kwargs given to the forward function.
| Default: ``False``
| always_call (bool): If ``True`` the ``hook`` will be run regardless of
| whether an exception is raised while calling the Module.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_forward_pre_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...]], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[typing.Any, dict[str, typing.Any]] | None], *, prepend: bool = False, with_kwargs: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward pre-hook on the module.
|
| The hook will be called every time before :func:`forward` is invoked.
|
|
| If ``with_kwargs`` is false or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| input. User can either return a tuple or a single modified value in the
| hook. We will wrap the value into a tuple if a single value is returned
| (unless that value is already a tuple). The hook should have the
| following signature::
|
| hook(module, args) -> None or modified input
|
| If ``with_kwargs`` is true, the forward pre-hook will be passed the
| kwargs given to the forward function. And if the hook modifies the
| input, both the args and kwargs should be returned. The hook should have
| the following signature::
|
| hook(module, args, kwargs) -> None or a tuple of modified input and kwargs
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``forward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``forward_pre`` hooks registered with
| :func:`register_module_forward_pre_hook` will fire before all
| hooks registered by this method.
| Default: ``False``
| with_kwargs (bool): If true, the ``hook`` will be passed the kwargs
| given to the forward function.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| The hook will be called every time the gradients with respect to a module are computed, and its firing rules are as follows:
|
| 1. Ordinarily, the hook fires when the gradients are computed with respect to the module inputs.
| 2. If none of the module inputs require gradients, the hook will fire when the gradients are computed
| with respect to module outputs.
| 3. If none of the module outputs require gradients, then the hooks will not fire.
|
| The hook should have the following signature::
|
| hook(module, grad_input, grad_output) -> tuple(Tensor) or None
|
| The :attr:`grad_input` and :attr:`grad_output` are tuples that contain the gradients
| with respect to the inputs and outputs respectively. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the input that will be used in place of :attr:`grad_input` in
| subsequent computations. :attr:`grad_input` will only correspond to the inputs given
| as positional arguments and all kwarg arguments are ignored. Entries
| in :attr:`grad_input` and :attr:`grad_output` will be ``None`` for all non-Tensor
| arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs or outputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``backward`` hooks registered with
| :func:`register_module_full_backward_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_pre_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward pre-hook on the module.
|
| The hook will be called every time the gradients for the module are computed.
| The hook should have the following signature::
|
| hook(module, grad_output) -> tuple[Tensor, ...], Tensor or None
|
| The :attr:`grad_output` is a tuple. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the output that will be used in place of :attr:`grad_output` in
| subsequent computations. Entries in :attr:`grad_output` will be ``None`` for
| all non-Tensor arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``backward_pre`` hooks registered with
| :func:`register_module_full_backward_pre_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_post_hook(self, hook)
| Register a post-hook to be run after module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, incompatible_keys) -> None
|
| The ``module`` argument is the current module that this hook is registered
| on, and the ``incompatible_keys`` argument is a ``NamedTuple`` consisting
| of attributes ``missing_keys`` and ``unexpected_keys``. ``missing_keys``
| is a ``list`` of ``str`` containing the missing keys and
| ``unexpected_keys`` is a ``list`` of ``str`` containing the unexpected keys.
|
| The given incompatible_keys can be modified inplace if needed.
|
| Note that the checks performed when calling :func:`load_state_dict` with
| ``strict=True`` are affected by modifications the hook makes to
| ``missing_keys`` or ``unexpected_keys``, as expected. Additions to either
| set of keys will result in an error being thrown when ``strict=True``, and
| clearing out both missing and unexpected keys will avoid an error.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook)
| Register a pre-hook to be run before module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) -> None # noqa: B950
|
| Arguments:
| hook (Callable): Callable hook that will be invoked before
| loading the state dict.
|
| register_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Alias for :func:`add_module`.
|
| register_parameter(self, name: str, param: torch.nn.parameter.Parameter | None) -> None
| Add a parameter to the module.
|
| The parameter can be accessed as an attribute using given name.
|
| Args:
| name (str): name of the parameter. The parameter can be accessed
| from this module using the given name
| param (Parameter or None): parameter to be added to the module. If
| ``None``, then operations that run on parameters, such as :attr:`cuda`,
| are ignored. If ``None``, the parameter is **not** included in the
| module's :attr:`state_dict`.
|
| register_state_dict_post_hook(self, hook)
| Register a post-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata) -> None
|
| The registered hooks can modify the ``state_dict`` inplace.
|
| register_state_dict_pre_hook(self, hook)
| Register a pre-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, prefix, keep_vars) -> None
|
| The registered hooks can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| requires_grad_(self, requires_grad: bool = True) -> Self
| Change if autograd should record operations on parameters in this module.
|
| This method sets the parameters' :attr:`requires_grad` attributes
| in-place.
|
| This method is helpful for freezing part of the module for finetuning
| or training parts of a model individually (e.g., GAN training).
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.requires_grad_()` and several similar mechanisms that may be confused with it.
|
| Args:
| requires_grad (bool): whether autograd should record operations on
| parameters in this module. Default: ``True``.
|
| Returns:
| Module: self
|
| set_extra_state(self, state: Any) -> None
| Set extra state contained in the loaded `state_dict`.
|
| This function is called from :func:`load_state_dict` to handle any extra state
| found within the `state_dict`. Implement this function and a corresponding
| :func:`get_extra_state` for your module if you need to store extra state within its
| `state_dict`.
|
| Args:
| state (dict): Extra state from the `state_dict`
|
| set_submodule(self, target: str, module: 'Module', strict: bool = False) -> None
| Set the submodule given by ``target`` if it exists, otherwise throw an error.
|
| .. note::
| If ``strict`` is set to ``False`` (default), the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``strict`` is set to ``True``,
| the method will only attempt to replace an existing submodule and throw an error if
| the submodule does not exist.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(3, 3, 3)
| )
| (linear): Linear(3, 3)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To override the ``Conv2d`` with a new submodule ``Linear``, you
| could call ``set_submodule("net_b.net_c.conv", nn.Linear(1, 1))``
| where ``strict`` could be ``True`` or ``False``
|
| To add a new submodule ``Conv2d`` to the existing ``net_b`` module,
| you would call ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1))``.
|
| In the above if you set ``strict=True`` and call
| ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1), strict=True)``, an AttributeError
| will be raised because ``net_b`` does not have a submodule named ``conv``.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
| module: The module to set the submodule to.
| strict: If ``False``, the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``True``,
| the method will only attempt to replace an existing submodule and throw an error
| if the submodule doesn't already exist.
|
| Raises:
| ValueError: If the ``target`` string is empty or if ``module`` is not an instance of ``nn.Module``.
| AttributeError: If at any point along the path resulting from
| the ``target`` string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| share_memory(self) -> Self
| See :meth:`torch.Tensor.share_memory_`.
|
| state_dict(self, *args, destination=None, prefix='', keep_vars=False)
| Return a dictionary containing references to the whole state of the module.
|
| Both parameters and persistent buffers (e.g. running averages) are
| included. Keys are corresponding parameter and buffer names.
| Parameters and buffers set to ``None`` are not included.
|
| .. note::
| The returned object is a shallow copy. It contains references
| to the module's parameters and buffers.
|
| .. warning::
| Currently ``state_dict()`` also accepts positional arguments for
| ``destination``, ``prefix`` and ``keep_vars`` in order. However,
| this is being deprecated and keyword arguments will be enforced in
| future releases.
|
| .. warning::
| Please avoid the use of argument ``destination`` as it is not
| designed for end-users.
|
| Args:
| destination (dict, optional): If provided, the state of module will
| be updated into the dict and the same object is returned.
| Otherwise, an ``OrderedDict`` will be created and returned.
| Default: ``None``.
| prefix (str, optional): a prefix added to parameter and buffer
| names to compose the keys in state_dict. Default: ``''``.
| keep_vars (bool, optional): by default the :class:`~torch.Tensor` s
| returned in the state dict are detached from autograd. If it's
| set to ``True``, detaching will not be performed.
| Default: ``False``.
|
| Returns:
| dict:
| a dictionary containing a whole state of the module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> module.state_dict().keys()
| ['bias', 'weight']
|
| to(self, *args, **kwargs)
| Move and/or cast the parameters and buffers.
|
| This can be called as
|
| .. function:: to(device=None, dtype=None, non_blocking=False)
| :noindex:
|
| .. function:: to(dtype, non_blocking=False)
| :noindex:
|
| .. function:: to(tensor, non_blocking=False)
| :noindex:
|
| .. function:: to(memory_format=torch.channels_last)
| :noindex:
|
| Its signature is similar to :meth:`torch.Tensor.to`, but only accepts
| floating point or complex :attr:`dtype`\ s. In addition, this method will
| only cast the floating point or complex parameters and buffers to :attr:`dtype`
| (if given). The integral parameters and buffers will be moved
| :attr:`device`, if that is given, but with dtypes unchanged. When
| :attr:`non_blocking` is set, it tries to convert/move asynchronously
| with respect to the host if possible, e.g., moving CPU Tensors with
| pinned memory to CUDA devices.
|
| See below for examples.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (:class:`torch.device`): the desired device of the parameters
| and buffers in this module
| dtype (:class:`torch.dtype`): the desired floating point or complex dtype of
| the parameters and buffers in this module
| tensor (torch.Tensor): Tensor whose dtype and device are the desired
| dtype and device for all parameters and buffers in this module
| memory_format (:class:`torch.memory_format`): the desired memory
| format for 4D parameters and buffers in this module (keyword
| only argument)
|
| Returns:
| Module: self
|
| Examples::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> linear = nn.Linear(2, 2)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]])
| >>> linear.to(torch.double)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]], dtype=torch.float64)
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA1)
| >>> gpu1 = torch.device("cuda:1")
| >>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
| >>> cpu = torch.device("cpu")
| >>> linear.to(cpu)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16)
|
| >>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.3741+0.j, 0.2382+0.j],
| [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
| >>> linear(torch.ones(3, 2, dtype=torch.cdouble))
| tensor([[0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
|
| to_empty(self, *, device: str | torch.device | int | None, recurse: bool = True) -> Self
| Move the parameters and buffers to the specified device without copying storage.
|
| Args:
| device (:class:`torch.device`): The desired device of the parameters
| and buffers in this module.
| recurse (bool): Whether parameters and buffers of submodules should
| be recursively moved to the specified device.
|
| Returns:
| Module: self
|
| train(self, mode: bool = True) -> Self
| Set the module in training mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e., whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| Args:
| mode (bool): whether to set training mode (``True``) or evaluation
| mode (``False``). Default: ``True``.
|
| Returns:
| Module: self
|
| type(self, dst_type: torch.dtype | str) -> Self
| Casts all parameters and buffers to :attr:`dst_type`.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| dst_type (type or string): the desired type
|
| Returns:
| Module: self
|
| xpu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the XPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing optimizer if the module will
| live on XPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset gradients of all model parameters.
|
| See similar function under :class:`torch.optim.Optimizer` for more context.
|
| Args:
| set_to_none (bool): instead of setting to zero, set the grads to None.
| See :meth:`torch.optim.Optimizer.zero_grad` for details.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.nn.modules.module.Module:
|
| T_destination = ~T_destination
|
| call_super_init = False
|
| dump_patches = False
class ObserverBase(abc.ABC, torch.nn.modules.module.Module)
| ObserverBase(dtype, is_dynamic: bool = False)
|
| Base observer Module.
| Any observer implementation should derive from this class.
|
| Concrete observers should follow the same API. In forward, they will update
| the statistics of the observed Tensor. And they should provide a
| `calculate_qparams` function that computes the quantization parameters given
| the collected statistics.
|
| Args:
| dtype: dtype argument to the `quantize` node needed to implement the
| reference model spec.
| is_dynamic: indicator for whether the observer is a placeholder for dynamic quantization
| or static quantization
|
| Method resolution order:
| ObserverBase
| abc.ABC
| torch.nn.modules.module.Module
| builtins.object
|
| Methods defined here:
|
| __init__(self, dtype, is_dynamic: bool = False)
| Initialize self. See help(type(self)) for accurate signature.
|
| calculate_qparams(self, **kwargs)
|
| forward(self, x)
| Define the computation performed at every call.
|
| Should be overridden by all subclasses.
|
| .. note::
| Although the recipe for forward pass needs to be defined within
| this function, one should call the :class:`Module` instance afterwards
| instead of this since the former takes care of running the
| registered hooks while the latter silently ignores them.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| with_args = _with_args(**kwargs) from torch.ao.quantization.observer
| Wrapper that allows creation of class factories.
|
| This can be useful when there is a need to create classes with the same
| constructor arguments, but different instances. Can be used in conjunction with
| _callable_args
|
| Example::
|
| >>> # xdoctest: +SKIP("Undefined vars")
| >>> Foo.with_args = classmethod(_with_args)
| >>> foo_builder = Foo.with_args(a=3, b=4).with_args(answer=42)
| >>> foo_instance1 = foo_builder()
| >>> foo_instance2 = foo_builder()
| >>> id(foo_instance1) == id(foo_instance2)
| False
|
| with_callable_args = _with_callable_args(**kwargs) from torch.ao.quantization.observer
| Wrapper that allows creation of class factories args that need to be
| called at construction time.
|
| This can be useful when there is a need to create classes with the same
| constructor arguments, but different instances and those arguments should only
| be calculated at construction time. Can be used in conjunction with _with_args
|
| Example::
|
| >>> # xdoctest: +SKIP("Undefined vars")
| >>> Foo.with_callable_args = classmethod(_with_callable_args)
| >>> Foo.with_args = classmethod(_with_args)
| >>> foo_builder = Foo.with_callable_args(cur_time=get_time_func).with_args(name="dan")
| >>> foo_instance1 = foo_builder()
| >>> # wait 50
| >>> foo_instance2 = foo_builder()
| >>> id(foo_instance1.creation_time) == id(foo_instance2.creation_time)
| False
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset({'calculate_qparams', 'forward'})
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Data descriptors inherited from abc.ABC:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from torch.nn.modules.module.Module:
|
| __call__ = _wrapped_call_impl(self, *args, **kwargs)
|
| __delattr__(self, name) -> None
| Implement delattr(self, name).
|
| __dir__(self)
| Default dir() implementation.
|
| __getattr__(self, name: str) -> Union[torch.Tensor, ForwardRef('Module')]
| # It is crucial that the return type is not annotated as `Any`, otherwise type checking
| # on `torch.nn.Module` and all its subclasses is largely disabled as a result. See:
| # https://github.com/pytorch/pytorch/pull/115074
|
| __getstate__(self)
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setattr__(self, name: str, value: Union[torch.Tensor, ForwardRef('Module')]) -> None
| Implement setattr(self, name, value).
|
| __setstate__(self, state)
|
| add_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Add a child module to the current module.
|
| The module can be accessed as an attribute using the given name.
|
| Args:
| name (str): name of the child module. The child module can be
| accessed from this module using the given name
| module (Module): child module to be added to the module.
|
| apply(self, fn: collections.abc.Callable[['Module'], None]) -> Self
| Apply ``fn`` recursively to every submodule (as returned by ``.children()``) as well as self.
|
| Typical use includes initializing the parameters of a model
| (see also :ref:`nn-init-doc`).
|
| Args:
| fn (:class:`Module` -> None): function to be applied to each submodule
|
| Returns:
| Module: self
|
| Example::
|
| >>> @torch.no_grad()
| >>> def init_weights(m):
| >>> print(m)
| >>> if type(m) is nn.Linear:
| >>> m.weight.fill_(1.0)
| >>> print(m.weight)
| >>> net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
| >>> net.apply(init_weights)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
|
| bfloat16(self) -> Self
| Casts all floating point parameters and buffers to ``bfloat16`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| buffers(self, recurse: bool = True) -> collections.abc.Iterator[torch.Tensor]
| Return an iterator over module buffers.
|
| Args:
| recurse (bool): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module.
|
| Yields:
| torch.Tensor: module buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for buf in model.buffers():
| >>> print(type(buf), buf.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| children(self) -> collections.abc.Iterator['Module']
| Return an iterator over immediate children modules.
|
| Yields:
| Module: a child module
|
| compile(self, *args, **kwargs) -> None
| Compile this Module's forward using :func:`torch.compile`.
|
| This Module's `__call__` method is compiled and all arguments are passed as-is
| to :func:`torch.compile`.
|
| See :func:`torch.compile` for details on the arguments for this function.
|
| cpu(self) -> Self
| Move all model parameters and buffers to the CPU.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| cuda(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the GPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on GPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| double(self) -> Self
| Casts all floating point parameters and buffers to ``double`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| eval(self) -> Self
| Set the module in evaluation mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e. whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| This is equivalent with :meth:`self.train(False) <torch.nn.Module.train>`.
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.eval()` and several similar mechanisms that may be confused with it.
|
| Returns:
| Module: self
|
| extra_repr(self) -> str
| Return the extra representation of the module.
|
| To print customized extra information, you should re-implement
| this method in your own modules. Both single-line and multi-line
| strings are acceptable.
|
| float(self) -> Self
| Casts all floating point parameters and buffers to ``float`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| get_buffer(self, target: str) -> torch.Tensor
| Return the buffer given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the buffer
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.Tensor: The buffer referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not a
| buffer
|
| get_extra_state(self) -> Any
| Return any extra state to include in the module's state_dict.
|
| Implement this and a corresponding :func:`set_extra_state` for your module
| if you need to store extra state. This function is called when building the
| module's `state_dict()`.
|
| Note that extra state should be picklable to ensure working serialization
| of the state_dict. We only provide backwards compatibility guarantees
| for serializing Tensors; other objects may break backwards compatibility if
| their serialized pickled form changes.
|
| Returns:
| object: Any extra state to store in the module's state_dict
|
| get_parameter(self, target: str) -> torch.nn.parameter.Parameter
| Return the parameter given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the Parameter
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Parameter: The Parameter referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not an
| ``nn.Parameter``
|
| get_submodule(self, target: str) -> 'Module'
| Return the submodule given by ``target`` if it exists, otherwise throw an error.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(16, 33, kernel_size=(3, 3), stride=(2, 2))
| )
| (linear): Linear(in_features=100, out_features=200, bias=True)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` which has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To check whether or not we have the ``linear`` submodule, we
| would call ``get_submodule("net_b.linear")``. To check whether
| we have the ``conv`` submodule, we would call
| ``get_submodule("net_b.net_c.conv")``.
|
| The runtime of ``get_submodule`` is bounded by the degree
| of module nesting in ``target``. A query against
| ``named_modules`` achieves the same result, but it is O(N) in
| the number of transitive modules. So, for a simple check to see
| if some submodule exists, ``get_submodule`` should always be
| used.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Module: The submodule referenced by ``target``
|
| Raises:
| AttributeError: If at any point along the path resulting from
| the target string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| half(self) -> Self
| Casts all floating point parameters and buffers to ``half`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| ipu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the IPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on IPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| load_state_dict(self, state_dict: collections.abc.Mapping[str, typing.Any], strict: bool = True, assign: bool = False)
| Copy parameters and buffers from :attr:`state_dict` into this module and its descendants.
|
| If :attr:`strict` is ``True``, then
| the keys of :attr:`state_dict` must exactly match the keys returned
| by this module's :meth:`~torch.nn.Module.state_dict` function.
|
| .. warning::
| If :attr:`assign` is ``True`` the optimizer must be created after
| the call to :attr:`load_state_dict` unless
| :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| Args:
| state_dict (dict): a dict containing parameters and
| persistent buffers.
| strict (bool, optional): whether to strictly enforce that the keys
| in :attr:`state_dict` match the keys returned by this module's
| :meth:`~torch.nn.Module.state_dict` function. Default: ``True``
| assign (bool, optional): When set to ``False``, the properties of the tensors
| in the current module are preserved whereas setting it to ``True`` preserves
| properties of the Tensors in the state dict. The only
| exception is the ``requires_grad`` field of :class:`~torch.nn.Parameter`
| for which the value from the module is preserved. Default: ``False``
|
| Returns:
| ``NamedTuple`` with ``missing_keys`` and ``unexpected_keys`` fields:
| * ``missing_keys`` is a list of str containing any keys that are expected
| by this module but missing from the provided ``state_dict``.
| * ``unexpected_keys`` is a list of str containing the keys that are not
| expected by this module but present in the provided ``state_dict``.
|
| Note:
| If a parameter or buffer is registered as ``None`` and its corresponding key
| exists in :attr:`state_dict`, :meth:`load_state_dict` will raise a
| ``RuntimeError``.
|
| modules(self, remove_duplicate: bool = True) -> collections.abc.Iterator['Module']
| Return an iterator over all modules in the network.
|
| Args:
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not.
|
| Yields:
| Module: a module in the network
|
| Note:
| Duplicate modules are returned only once by default. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.modules()):
| ... print(idx, '->', m)
|
| 0 -> Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
| 1 -> Linear(in_features=2, out_features=2, bias=True)
|
| mtia(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the MTIA.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on MTIA while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| named_buffers(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.Tensor]]
| Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
|
| Args:
| prefix (str): prefix to prepend to all buffer names.
| recurse (bool, optional): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module. Defaults to True.
| remove_duplicate (bool, optional): whether to remove the duplicated buffers in the result. Defaults to True.
|
| Yields:
| (str, torch.Tensor): Tuple containing the name and buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, buf in self.named_buffers():
| >>> if name in ['running_var']:
| >>> print(buf.size())
|
| named_children(self) -> collections.abc.Iterator[tuple[str, 'Module']]
| Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
|
| Yields:
| (str, Module): Tuple containing a name and child module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, module in model.named_children():
| >>> if name in ['conv4', 'conv5']:
| >>> print(module)
|
| named_modules(self, memo: set['Module'] | None = None, prefix: str = '', remove_duplicate: bool = True)
| Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
|
| Args:
| memo: a memo to store the set of modules already added to the result
| prefix: a prefix that will be added to the name of the module
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not
|
| Yields:
| (str, Module): Tuple of name and module
|
| Note:
| Duplicate modules are returned only once. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.named_modules()):
| ... print(idx, '->', m)
|
| 0 -> ('', Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| ))
| 1 -> ('0', Linear(in_features=2, out_features=2, bias=True))
|
| named_parameters(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.nn.parameter.Parameter]]
| Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
|
| Args:
| prefix (str): prefix to prepend to all parameter names.
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
| remove_duplicate (bool, optional): whether to remove the duplicated
| parameters in the result. Defaults to True.
|
| Yields:
| (str, Parameter): Tuple containing the name and parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, param in self.named_parameters():
| >>> if name in ['bias']:
| >>> print(param.size())
|
| parameters(self, recurse: bool = True) -> collections.abc.Iterator[torch.nn.parameter.Parameter]
| Return an iterator over module parameters.
|
| This is typically passed to an optimizer.
|
| Args:
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
|
| Yields:
| Parameter: module parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for param in model.parameters():
| >>> print(type(param), param.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| register_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None]) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| This function is deprecated in favor of :meth:`~torch.nn.Module.register_full_backward_hook` and
| the behavior of this function will change in future versions.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_buffer(self, name: str, tensor: torch.Tensor | None, persistent: bool = True) -> None
| Add a buffer to the module.
|
| This is typically used to register a buffer that should not be
| considered a model parameter. For example, BatchNorm's ``running_mean``
| is not a parameter, but is part of the module's state. Buffers, by
| default, are persistent and will be saved alongside parameters. This
| behavior can be changed by setting :attr:`persistent` to ``False``. The
| only difference between a persistent buffer and a non-persistent buffer
| is that the latter will not be a part of this module's
| :attr:`state_dict`.
|
| Buffers can be accessed as attributes using given names.
|
| Args:
| name (str): name of the buffer. The buffer can be accessed
| from this module using the given name
| tensor (Tensor or None): buffer to be registered. If ``None``, then operations
| that run on buffers, such as :attr:`cuda`, are ignored. If ``None``,
| the buffer is **not** included in the module's :attr:`state_dict`.
| persistent (bool): whether the buffer is part of this module's
| :attr:`state_dict`.
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> self.register_buffer('running_mean', torch.zeros(num_features))
|
| register_forward_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...], typing.Any], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any], typing.Any], typing.Any | None], *, prepend: bool = False, with_kwargs: bool = False, always_call: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward hook on the module.
|
| The hook will be called every time after :func:`forward` has computed an output.
|
| If ``with_kwargs`` is ``False`` or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| output. It can modify the input inplace but it will not have effect on
| forward since this is called after :func:`forward` is called. The hook
| should have the following signature::
|
| hook(module, args, output) -> None or modified output
|
| If ``with_kwargs`` is ``True``, the forward hook will be passed the
| ``kwargs`` given to the forward function and be expected to return the
| output possibly modified. The hook should have the following signature::
|
| hook(module, args, kwargs, output) -> None or modified output
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If ``True``, the provided ``hook`` will be fired
| before all existing ``forward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``forward`` hooks registered with
| :func:`register_module_forward_hook` will fire before all hooks
| registered by this method.
| Default: ``False``
| with_kwargs (bool): If ``True``, the ``hook`` will be passed the
| kwargs given to the forward function.
| Default: ``False``
| always_call (bool): If ``True`` the ``hook`` will be run regardless of
| whether an exception is raised while calling the Module.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_forward_pre_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...]], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[typing.Any, dict[str, typing.Any]] | None], *, prepend: bool = False, with_kwargs: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward pre-hook on the module.
|
| The hook will be called every time before :func:`forward` is invoked.
|
|
| If ``with_kwargs`` is false or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| input. User can either return a tuple or a single modified value in the
| hook. We will wrap the value into a tuple if a single value is returned
| (unless that value is already a tuple). The hook should have the
| following signature::
|
| hook(module, args) -> None or modified input
|
| If ``with_kwargs`` is true, the forward pre-hook will be passed the
| kwargs given to the forward function. And if the hook modifies the
| input, both the args and kwargs should be returned. The hook should have
| the following signature::
|
| hook(module, args, kwargs) -> None or a tuple of modified input and kwargs
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``forward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``forward_pre`` hooks registered with
| :func:`register_module_forward_pre_hook` will fire before all
| hooks registered by this method.
| Default: ``False``
| with_kwargs (bool): If true, the ``hook`` will be passed the kwargs
| given to the forward function.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| The hook will be called every time the gradients with respect to a module are computed, and its firing rules are as follows:
|
| 1. Ordinarily, the hook fires when the gradients are computed with respect to the module inputs.
| 2. If none of the module inputs require gradients, the hook will fire when the gradients are computed
| with respect to module outputs.
| 3. If none of the module outputs require gradients, then the hooks will not fire.
|
| The hook should have the following signature::
|
| hook(module, grad_input, grad_output) -> tuple(Tensor) or None
|
| The :attr:`grad_input` and :attr:`grad_output` are tuples that contain the gradients
| with respect to the inputs and outputs respectively. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the input that will be used in place of :attr:`grad_input` in
| subsequent computations. :attr:`grad_input` will only correspond to the inputs given
| as positional arguments and all kwarg arguments are ignored. Entries
| in :attr:`grad_input` and :attr:`grad_output` will be ``None`` for all non-Tensor
| arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs or outputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``backward`` hooks registered with
| :func:`register_module_full_backward_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_pre_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward pre-hook on the module.
|
| The hook will be called every time the gradients for the module are computed.
| The hook should have the following signature::
|
| hook(module, grad_output) -> tuple[Tensor, ...], Tensor or None
|
| The :attr:`grad_output` is a tuple. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the output that will be used in place of :attr:`grad_output` in
| subsequent computations. Entries in :attr:`grad_output` will be ``None`` for
| all non-Tensor arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``backward_pre`` hooks registered with
| :func:`register_module_full_backward_pre_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_post_hook(self, hook)
| Register a post-hook to be run after module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, incompatible_keys) -> None
|
| The ``module`` argument is the current module that this hook is registered
| on, and the ``incompatible_keys`` argument is a ``NamedTuple`` consisting
| of attributes ``missing_keys`` and ``unexpected_keys``. ``missing_keys``
| is a ``list`` of ``str`` containing the missing keys and
| ``unexpected_keys`` is a ``list`` of ``str`` containing the unexpected keys.
|
| The given incompatible_keys can be modified inplace if needed.
|
| Note that the checks performed when calling :func:`load_state_dict` with
| ``strict=True`` are affected by modifications the hook makes to
| ``missing_keys`` or ``unexpected_keys``, as expected. Additions to either
| set of keys will result in an error being thrown when ``strict=True``, and
| clearing out both missing and unexpected keys will avoid an error.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook)
| Register a pre-hook to be run before module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) -> None # noqa: B950
|
| Arguments:
| hook (Callable): Callable hook that will be invoked before
| loading the state dict.
|
| register_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Alias for :func:`add_module`.
|
| register_parameter(self, name: str, param: torch.nn.parameter.Parameter | None) -> None
| Add a parameter to the module.
|
| The parameter can be accessed as an attribute using given name.
|
| Args:
| name (str): name of the parameter. The parameter can be accessed
| from this module using the given name
| param (Parameter or None): parameter to be added to the module. If
| ``None``, then operations that run on parameters, such as :attr:`cuda`,
| are ignored. If ``None``, the parameter is **not** included in the
| module's :attr:`state_dict`.
|
| register_state_dict_post_hook(self, hook)
| Register a post-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata) -> None
|
| The registered hooks can modify the ``state_dict`` inplace.
|
| register_state_dict_pre_hook(self, hook)
| Register a pre-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, prefix, keep_vars) -> None
|
| The registered hooks can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| requires_grad_(self, requires_grad: bool = True) -> Self
| Change if autograd should record operations on parameters in this module.
|
| This method sets the parameters' :attr:`requires_grad` attributes
| in-place.
|
| This method is helpful for freezing part of the module for finetuning
| or training parts of a model individually (e.g., GAN training).
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.requires_grad_()` and several similar mechanisms that may be confused with it.
|
| Args:
| requires_grad (bool): whether autograd should record operations on
| parameters in this module. Default: ``True``.
|
| Returns:
| Module: self
|
| set_extra_state(self, state: Any) -> None
| Set extra state contained in the loaded `state_dict`.
|
| This function is called from :func:`load_state_dict` to handle any extra state
| found within the `state_dict`. Implement this function and a corresponding
| :func:`get_extra_state` for your module if you need to store extra state within its
| `state_dict`.
|
| Args:
| state (dict): Extra state from the `state_dict`
|
| set_submodule(self, target: str, module: 'Module', strict: bool = False) -> None
| Set the submodule given by ``target`` if it exists, otherwise throw an error.
|
| .. note::
| If ``strict`` is set to ``False`` (default), the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``strict`` is set to ``True``,
| the method will only attempt to replace an existing submodule and throw an error if
| the submodule does not exist.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(3, 3, 3)
| )
| (linear): Linear(3, 3)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To override the ``Conv2d`` with a new submodule ``Linear``, you
| could call ``set_submodule("net_b.net_c.conv", nn.Linear(1, 1))``
| where ``strict`` could be ``True`` or ``False``
|
| To add a new submodule ``Conv2d`` to the existing ``net_b`` module,
| you would call ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1))``.
|
| In the above if you set ``strict=True`` and call
| ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1), strict=True)``, an AttributeError
| will be raised because ``net_b`` does not have a submodule named ``conv``.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
| module: The module to set the submodule to.
| strict: If ``False``, the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``True``,
| the method will only attempt to replace an existing submodule and throw an error
| if the submodule doesn't already exist.
|
| Raises:
| ValueError: If the ``target`` string is empty or if ``module`` is not an instance of ``nn.Module``.
| AttributeError: If at any point along the path resulting from
| the ``target`` string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| share_memory(self) -> Self
| See :meth:`torch.Tensor.share_memory_`.
|
| state_dict(self, *args, destination=None, prefix='', keep_vars=False)
| Return a dictionary containing references to the whole state of the module.
|
| Both parameters and persistent buffers (e.g. running averages) are
| included. Keys are corresponding parameter and buffer names.
| Parameters and buffers set to ``None`` are not included.
|
| .. note::
| The returned object is a shallow copy. It contains references
| to the module's parameters and buffers.
|
| .. warning::
| Currently ``state_dict()`` also accepts positional arguments for
| ``destination``, ``prefix`` and ``keep_vars`` in order. However,
| this is being deprecated and keyword arguments will be enforced in
| future releases.
|
| .. warning::
| Please avoid the use of argument ``destination`` as it is not
| designed for end-users.
|
| Args:
| destination (dict, optional): If provided, the state of module will
| be updated into the dict and the same object is returned.
| Otherwise, an ``OrderedDict`` will be created and returned.
| Default: ``None``.
| prefix (str, optional): a prefix added to parameter and buffer
| names to compose the keys in state_dict. Default: ``''``.
| keep_vars (bool, optional): by default the :class:`~torch.Tensor` s
| returned in the state dict are detached from autograd. If it's
| set to ``True``, detaching will not be performed.
| Default: ``False``.
|
| Returns:
| dict:
| a dictionary containing a whole state of the module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> module.state_dict().keys()
| ['bias', 'weight']
|
| to(self, *args, **kwargs)
| Move and/or cast the parameters and buffers.
|
| This can be called as
|
| .. function:: to(device=None, dtype=None, non_blocking=False)
| :noindex:
|
| .. function:: to(dtype, non_blocking=False)
| :noindex:
|
| .. function:: to(tensor, non_blocking=False)
| :noindex:
|
| .. function:: to(memory_format=torch.channels_last)
| :noindex:
|
| Its signature is similar to :meth:`torch.Tensor.to`, but only accepts
| floating point or complex :attr:`dtype`\ s. In addition, this method will
| only cast the floating point or complex parameters and buffers to :attr:`dtype`
| (if given). The integral parameters and buffers will be moved
| :attr:`device`, if that is given, but with dtypes unchanged. When
| :attr:`non_blocking` is set, it tries to convert/move asynchronously
| with respect to the host if possible, e.g., moving CPU Tensors with
| pinned memory to CUDA devices.
|
| See below for examples.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (:class:`torch.device`): the desired device of the parameters
| and buffers in this module
| dtype (:class:`torch.dtype`): the desired floating point or complex dtype of
| the parameters and buffers in this module
| tensor (torch.Tensor): Tensor whose dtype and device are the desired
| dtype and device for all parameters and buffers in this module
| memory_format (:class:`torch.memory_format`): the desired memory
| format for 4D parameters and buffers in this module (keyword
| only argument)
|
| Returns:
| Module: self
|
| Examples::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> linear = nn.Linear(2, 2)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]])
| >>> linear.to(torch.double)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]], dtype=torch.float64)
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA1)
| >>> gpu1 = torch.device("cuda:1")
| >>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
| >>> cpu = torch.device("cpu")
| >>> linear.to(cpu)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16)
|
| >>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.3741+0.j, 0.2382+0.j],
| [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
| >>> linear(torch.ones(3, 2, dtype=torch.cdouble))
| tensor([[0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
|
| to_empty(self, *, device: str | torch.device | int | None, recurse: bool = True) -> Self
| Move the parameters and buffers to the specified device without copying storage.
|
| Args:
| device (:class:`torch.device`): The desired device of the parameters
| and buffers in this module.
| recurse (bool): Whether parameters and buffers of submodules should
| be recursively moved to the specified device.
|
| Returns:
| Module: self
|
| train(self, mode: bool = True) -> Self
| Set the module in training mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e., whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| Args:
| mode (bool): whether to set training mode (``True``) or evaluation
| mode (``False``). Default: ``True``.
|
| Returns:
| Module: self
|
| type(self, dst_type: torch.dtype | str) -> Self
| Casts all parameters and buffers to :attr:`dst_type`.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| dst_type (type or string): the desired type
|
| Returns:
| Module: self
|
| xpu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the XPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing optimizer if the module will
| live on XPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset gradients of all model parameters.
|
| See similar function under :class:`torch.optim.Optimizer` for more context.
|
| Args:
| set_to_none (bool): instead of setting to zero, set the grads to None.
| See :meth:`torch.optim.Optimizer.zero_grad` for details.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.nn.modules.module.Module:
|
| T_destination = ~T_destination
|
| call_super_init = False
|
| dump_patches = False
class QConfig(QConfig)
| QConfig(activation, weight)
|
| Describes how to quantize a layer or a part of the network by providing
| settings (observer classes) for activations and weights respectively.
|
|
| Note that QConfig needs to contain observer **classes** (like MinMaxObserver) or a callable that returns
| instances on invocation, not the concrete observer instances themselves.
| Quantization preparation function will instantiate observers multiple times for each of the layers.
|
|
| Observer classes have usually reasonable default arguments, but they can be overwritten with `with_args`
| method (that behaves like functools.partial)::
|
| my_qconfig = QConfig(
| activation=MinMaxObserver.with_args(dtype=torch.qint8),
| weight=default_observer.with_args(dtype=torch.qint8),
| )
|
| Method resolution order:
| QConfig
| QConfig
| builtins.tuple
| builtins.object
|
| Static methods defined here:
|
| __new__(cls, activation, weight)
| Create new instance of QConfig(activation, weight)
|
| ----------------------------------------------------------------------
| Methods inherited from QConfig:
|
| __getnewargs__(self) from collections.QConfig
| Return self as a plain tuple. Used by copy and pickle.
|
| __repr__(self) from collections.QConfig
| Return a nicely formatted representation string
|
| _asdict(self) from collections.QConfig
| Return a new dict which maps field names to their values.
|
| _replace(self, /, **kwds) from collections.QConfig
| Return a new QConfig object replacing specified fields with new values
|
| ----------------------------------------------------------------------
| Class methods inherited from QConfig:
|
| _make(iterable) from collections.QConfig
| Make a new QConfig object from a sequence or iterable
|
| ----------------------------------------------------------------------
| Data descriptors inherited from QConfig:
|
| activation
| Alias for field number 0
|
| weight
| Alias for field number 1
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from QConfig:
|
| __match_args__ = ('activation', 'weight')
|
| _field_defaults = {}
|
| _fields = ('activation', 'weight')
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class QuantStub(torch.nn.modules.module.Module)
| QuantStub(qconfig: torch.ao.quantization.qconfig.QConfig | None = None)
|
| Quantize stub module, before calibration, this is same as an observer,
| it will be swapped as `nnq.Quantize` in `convert`.
|
| Args:
| qconfig: quantization configuration for the tensor,
| if qconfig is not provided, we will get qconfig from parent modules
|
| Method resolution order:
| QuantStub
| torch.nn.modules.module.Module
| builtins.object
|
| Methods defined here:
|
| __init__(self, qconfig: torch.ao.quantization.qconfig.QConfig | None = None)
| Initialize internal Module state, shared by both nn.Module and ScriptModule.
|
| forward(self, x: torch.Tensor) -> torch.Tensor
| Define the computation performed at every call.
|
| Should be overridden by all subclasses.
|
| .. note::
| Although the recipe for forward pass needs to be defined within
| this function, one should call the :class:`Module` instance afterwards
| instead of this since the former takes care of running the
| registered hooks while the latter silently ignores them.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch.nn.modules.module.Module:
|
| __call__ = _wrapped_call_impl(self, *args, **kwargs)
|
| __delattr__(self, name) -> None
| Implement delattr(self, name).
|
| __dir__(self)
| Default dir() implementation.
|
| __getattr__(self, name: str) -> Union[torch.Tensor, ForwardRef('Module')]
| # It is crucial that the return type is not annotated as `Any`, otherwise type checking
| # on `torch.nn.Module` and all its subclasses is largely disabled as a result. See:
| # https://github.com/pytorch/pytorch/pull/115074
|
| __getstate__(self)
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setattr__(self, name: str, value: Union[torch.Tensor, ForwardRef('Module')]) -> None
| Implement setattr(self, name, value).
|
| __setstate__(self, state)
|
| add_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Add a child module to the current module.
|
| The module can be accessed as an attribute using the given name.
|
| Args:
| name (str): name of the child module. The child module can be
| accessed from this module using the given name
| module (Module): child module to be added to the module.
|
| apply(self, fn: collections.abc.Callable[['Module'], None]) -> Self
| Apply ``fn`` recursively to every submodule (as returned by ``.children()``) as well as self.
|
| Typical use includes initializing the parameters of a model
| (see also :ref:`nn-init-doc`).
|
| Args:
| fn (:class:`Module` -> None): function to be applied to each submodule
|
| Returns:
| Module: self
|
| Example::
|
| >>> @torch.no_grad()
| >>> def init_weights(m):
| >>> print(m)
| >>> if type(m) is nn.Linear:
| >>> m.weight.fill_(1.0)
| >>> print(m.weight)
| >>> net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
| >>> net.apply(init_weights)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
|
| bfloat16(self) -> Self
| Casts all floating point parameters and buffers to ``bfloat16`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| buffers(self, recurse: bool = True) -> collections.abc.Iterator[torch.Tensor]
| Return an iterator over module buffers.
|
| Args:
| recurse (bool): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module.
|
| Yields:
| torch.Tensor: module buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for buf in model.buffers():
| >>> print(type(buf), buf.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| children(self) -> collections.abc.Iterator['Module']
| Return an iterator over immediate children modules.
|
| Yields:
| Module: a child module
|
| compile(self, *args, **kwargs) -> None
| Compile this Module's forward using :func:`torch.compile`.
|
| This Module's `__call__` method is compiled and all arguments are passed as-is
| to :func:`torch.compile`.
|
| See :func:`torch.compile` for details on the arguments for this function.
|
| cpu(self) -> Self
| Move all model parameters and buffers to the CPU.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| cuda(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the GPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on GPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| double(self) -> Self
| Casts all floating point parameters and buffers to ``double`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| eval(self) -> Self
| Set the module in evaluation mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e. whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| This is equivalent with :meth:`self.train(False) <torch.nn.Module.train>`.
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.eval()` and several similar mechanisms that may be confused with it.
|
| Returns:
| Module: self
|
| extra_repr(self) -> str
| Return the extra representation of the module.
|
| To print customized extra information, you should re-implement
| this method in your own modules. Both single-line and multi-line
| strings are acceptable.
|
| float(self) -> Self
| Casts all floating point parameters and buffers to ``float`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| get_buffer(self, target: str) -> torch.Tensor
| Return the buffer given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the buffer
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.Tensor: The buffer referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not a
| buffer
|
| get_extra_state(self) -> Any
| Return any extra state to include in the module's state_dict.
|
| Implement this and a corresponding :func:`set_extra_state` for your module
| if you need to store extra state. This function is called when building the
| module's `state_dict()`.
|
| Note that extra state should be picklable to ensure working serialization
| of the state_dict. We only provide backwards compatibility guarantees
| for serializing Tensors; other objects may break backwards compatibility if
| their serialized pickled form changes.
|
| Returns:
| object: Any extra state to store in the module's state_dict
|
| get_parameter(self, target: str) -> torch.nn.parameter.Parameter
| Return the parameter given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the Parameter
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Parameter: The Parameter referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not an
| ``nn.Parameter``
|
| get_submodule(self, target: str) -> 'Module'
| Return the submodule given by ``target`` if it exists, otherwise throw an error.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(16, 33, kernel_size=(3, 3), stride=(2, 2))
| )
| (linear): Linear(in_features=100, out_features=200, bias=True)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` which has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To check whether or not we have the ``linear`` submodule, we
| would call ``get_submodule("net_b.linear")``. To check whether
| we have the ``conv`` submodule, we would call
| ``get_submodule("net_b.net_c.conv")``.
|
| The runtime of ``get_submodule`` is bounded by the degree
| of module nesting in ``target``. A query against
| ``named_modules`` achieves the same result, but it is O(N) in
| the number of transitive modules. So, for a simple check to see
| if some submodule exists, ``get_submodule`` should always be
| used.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Module: The submodule referenced by ``target``
|
| Raises:
| AttributeError: If at any point along the path resulting from
| the target string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| half(self) -> Self
| Casts all floating point parameters and buffers to ``half`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| ipu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the IPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on IPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| load_state_dict(self, state_dict: collections.abc.Mapping[str, typing.Any], strict: bool = True, assign: bool = False)
| Copy parameters and buffers from :attr:`state_dict` into this module and its descendants.
|
| If :attr:`strict` is ``True``, then
| the keys of :attr:`state_dict` must exactly match the keys returned
| by this module's :meth:`~torch.nn.Module.state_dict` function.
|
| .. warning::
| If :attr:`assign` is ``True`` the optimizer must be created after
| the call to :attr:`load_state_dict` unless
| :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| Args:
| state_dict (dict): a dict containing parameters and
| persistent buffers.
| strict (bool, optional): whether to strictly enforce that the keys
| in :attr:`state_dict` match the keys returned by this module's
| :meth:`~torch.nn.Module.state_dict` function. Default: ``True``
| assign (bool, optional): When set to ``False``, the properties of the tensors
| in the current module are preserved whereas setting it to ``True`` preserves
| properties of the Tensors in the state dict. The only
| exception is the ``requires_grad`` field of :class:`~torch.nn.Parameter`
| for which the value from the module is preserved. Default: ``False``
|
| Returns:
| ``NamedTuple`` with ``missing_keys`` and ``unexpected_keys`` fields:
| * ``missing_keys`` is a list of str containing any keys that are expected
| by this module but missing from the provided ``state_dict``.
| * ``unexpected_keys`` is a list of str containing the keys that are not
| expected by this module but present in the provided ``state_dict``.
|
| Note:
| If a parameter or buffer is registered as ``None`` and its corresponding key
| exists in :attr:`state_dict`, :meth:`load_state_dict` will raise a
| ``RuntimeError``.
|
| modules(self, remove_duplicate: bool = True) -> collections.abc.Iterator['Module']
| Return an iterator over all modules in the network.
|
| Args:
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not.
|
| Yields:
| Module: a module in the network
|
| Note:
| Duplicate modules are returned only once by default. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.modules()):
| ... print(idx, '->', m)
|
| 0 -> Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
| 1 -> Linear(in_features=2, out_features=2, bias=True)
|
| mtia(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the MTIA.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on MTIA while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| named_buffers(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.Tensor]]
| Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
|
| Args:
| prefix (str): prefix to prepend to all buffer names.
| recurse (bool, optional): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module. Defaults to True.
| remove_duplicate (bool, optional): whether to remove the duplicated buffers in the result. Defaults to True.
|
| Yields:
| (str, torch.Tensor): Tuple containing the name and buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, buf in self.named_buffers():
| >>> if name in ['running_var']:
| >>> print(buf.size())
|
| named_children(self) -> collections.abc.Iterator[tuple[str, 'Module']]
| Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
|
| Yields:
| (str, Module): Tuple containing a name and child module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, module in model.named_children():
| >>> if name in ['conv4', 'conv5']:
| >>> print(module)
|
| named_modules(self, memo: set['Module'] | None = None, prefix: str = '', remove_duplicate: bool = True)
| Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
|
| Args:
| memo: a memo to store the set of modules already added to the result
| prefix: a prefix that will be added to the name of the module
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not
|
| Yields:
| (str, Module): Tuple of name and module
|
| Note:
| Duplicate modules are returned only once. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.named_modules()):
| ... print(idx, '->', m)
|
| 0 -> ('', Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| ))
| 1 -> ('0', Linear(in_features=2, out_features=2, bias=True))
|
| named_parameters(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.nn.parameter.Parameter]]
| Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
|
| Args:
| prefix (str): prefix to prepend to all parameter names.
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
| remove_duplicate (bool, optional): whether to remove the duplicated
| parameters in the result. Defaults to True.
|
| Yields:
| (str, Parameter): Tuple containing the name and parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, param in self.named_parameters():
| >>> if name in ['bias']:
| >>> print(param.size())
|
| parameters(self, recurse: bool = True) -> collections.abc.Iterator[torch.nn.parameter.Parameter]
| Return an iterator over module parameters.
|
| This is typically passed to an optimizer.
|
| Args:
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
|
| Yields:
| Parameter: module parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for param in model.parameters():
| >>> print(type(param), param.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| register_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None]) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| This function is deprecated in favor of :meth:`~torch.nn.Module.register_full_backward_hook` and
| the behavior of this function will change in future versions.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_buffer(self, name: str, tensor: torch.Tensor | None, persistent: bool = True) -> None
| Add a buffer to the module.
|
| This is typically used to register a buffer that should not be
| considered a model parameter. For example, BatchNorm's ``running_mean``
| is not a parameter, but is part of the module's state. Buffers, by
| default, are persistent and will be saved alongside parameters. This
| behavior can be changed by setting :attr:`persistent` to ``False``. The
| only difference between a persistent buffer and a non-persistent buffer
| is that the latter will not be a part of this module's
| :attr:`state_dict`.
|
| Buffers can be accessed as attributes using given names.
|
| Args:
| name (str): name of the buffer. The buffer can be accessed
| from this module using the given name
| tensor (Tensor or None): buffer to be registered. If ``None``, then operations
| that run on buffers, such as :attr:`cuda`, are ignored. If ``None``,
| the buffer is **not** included in the module's :attr:`state_dict`.
| persistent (bool): whether the buffer is part of this module's
| :attr:`state_dict`.
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> self.register_buffer('running_mean', torch.zeros(num_features))
|
| register_forward_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...], typing.Any], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any], typing.Any], typing.Any | None], *, prepend: bool = False, with_kwargs: bool = False, always_call: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward hook on the module.
|
| The hook will be called every time after :func:`forward` has computed an output.
|
| If ``with_kwargs`` is ``False`` or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| output. It can modify the input inplace but it will not have effect on
| forward since this is called after :func:`forward` is called. The hook
| should have the following signature::
|
| hook(module, args, output) -> None or modified output
|
| If ``with_kwargs`` is ``True``, the forward hook will be passed the
| ``kwargs`` given to the forward function and be expected to return the
| output possibly modified. The hook should have the following signature::
|
| hook(module, args, kwargs, output) -> None or modified output
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If ``True``, the provided ``hook`` will be fired
| before all existing ``forward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``forward`` hooks registered with
| :func:`register_module_forward_hook` will fire before all hooks
| registered by this method.
| Default: ``False``
| with_kwargs (bool): If ``True``, the ``hook`` will be passed the
| kwargs given to the forward function.
| Default: ``False``
| always_call (bool): If ``True`` the ``hook`` will be run regardless of
| whether an exception is raised while calling the Module.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_forward_pre_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...]], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[typing.Any, dict[str, typing.Any]] | None], *, prepend: bool = False, with_kwargs: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward pre-hook on the module.
|
| The hook will be called every time before :func:`forward` is invoked.
|
|
| If ``with_kwargs`` is false or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| input. User can either return a tuple or a single modified value in the
| hook. We will wrap the value into a tuple if a single value is returned
| (unless that value is already a tuple). The hook should have the
| following signature::
|
| hook(module, args) -> None or modified input
|
| If ``with_kwargs`` is true, the forward pre-hook will be passed the
| kwargs given to the forward function. And if the hook modifies the
| input, both the args and kwargs should be returned. The hook should have
| the following signature::
|
| hook(module, args, kwargs) -> None or a tuple of modified input and kwargs
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``forward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``forward_pre`` hooks registered with
| :func:`register_module_forward_pre_hook` will fire before all
| hooks registered by this method.
| Default: ``False``
| with_kwargs (bool): If true, the ``hook`` will be passed the kwargs
| given to the forward function.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| The hook will be called every time the gradients with respect to a module are computed, and its firing rules are as follows:
|
| 1. Ordinarily, the hook fires when the gradients are computed with respect to the module inputs.
| 2. If none of the module inputs require gradients, the hook will fire when the gradients are computed
| with respect to module outputs.
| 3. If none of the module outputs require gradients, then the hooks will not fire.
|
| The hook should have the following signature::
|
| hook(module, grad_input, grad_output) -> tuple(Tensor) or None
|
| The :attr:`grad_input` and :attr:`grad_output` are tuples that contain the gradients
| with respect to the inputs and outputs respectively. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the input that will be used in place of :attr:`grad_input` in
| subsequent computations. :attr:`grad_input` will only correspond to the inputs given
| as positional arguments and all kwarg arguments are ignored. Entries
| in :attr:`grad_input` and :attr:`grad_output` will be ``None`` for all non-Tensor
| arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs or outputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``backward`` hooks registered with
| :func:`register_module_full_backward_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_pre_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward pre-hook on the module.
|
| The hook will be called every time the gradients for the module are computed.
| The hook should have the following signature::
|
| hook(module, grad_output) -> tuple[Tensor, ...], Tensor or None
|
| The :attr:`grad_output` is a tuple. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the output that will be used in place of :attr:`grad_output` in
| subsequent computations. Entries in :attr:`grad_output` will be ``None`` for
| all non-Tensor arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``backward_pre`` hooks registered with
| :func:`register_module_full_backward_pre_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_post_hook(self, hook)
| Register a post-hook to be run after module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, incompatible_keys) -> None
|
| The ``module`` argument is the current module that this hook is registered
| on, and the ``incompatible_keys`` argument is a ``NamedTuple`` consisting
| of attributes ``missing_keys`` and ``unexpected_keys``. ``missing_keys``
| is a ``list`` of ``str`` containing the missing keys and
| ``unexpected_keys`` is a ``list`` of ``str`` containing the unexpected keys.
|
| The given incompatible_keys can be modified inplace if needed.
|
| Note that the checks performed when calling :func:`load_state_dict` with
| ``strict=True`` are affected by modifications the hook makes to
| ``missing_keys`` or ``unexpected_keys``, as expected. Additions to either
| set of keys will result in an error being thrown when ``strict=True``, and
| clearing out both missing and unexpected keys will avoid an error.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook)
| Register a pre-hook to be run before module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) -> None # noqa: B950
|
| Arguments:
| hook (Callable): Callable hook that will be invoked before
| loading the state dict.
|
| register_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Alias for :func:`add_module`.
|
| register_parameter(self, name: str, param: torch.nn.parameter.Parameter | None) -> None
| Add a parameter to the module.
|
| The parameter can be accessed as an attribute using given name.
|
| Args:
| name (str): name of the parameter. The parameter can be accessed
| from this module using the given name
| param (Parameter or None): parameter to be added to the module. If
| ``None``, then operations that run on parameters, such as :attr:`cuda`,
| are ignored. If ``None``, the parameter is **not** included in the
| module's :attr:`state_dict`.
|
| register_state_dict_post_hook(self, hook)
| Register a post-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata) -> None
|
| The registered hooks can modify the ``state_dict`` inplace.
|
| register_state_dict_pre_hook(self, hook)
| Register a pre-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, prefix, keep_vars) -> None
|
| The registered hooks can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| requires_grad_(self, requires_grad: bool = True) -> Self
| Change if autograd should record operations on parameters in this module.
|
| This method sets the parameters' :attr:`requires_grad` attributes
| in-place.
|
| This method is helpful for freezing part of the module for finetuning
| or training parts of a model individually (e.g., GAN training).
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.requires_grad_()` and several similar mechanisms that may be confused with it.
|
| Args:
| requires_grad (bool): whether autograd should record operations on
| parameters in this module. Default: ``True``.
|
| Returns:
| Module: self
|
| set_extra_state(self, state: Any) -> None
| Set extra state contained in the loaded `state_dict`.
|
| This function is called from :func:`load_state_dict` to handle any extra state
| found within the `state_dict`. Implement this function and a corresponding
| :func:`get_extra_state` for your module if you need to store extra state within its
| `state_dict`.
|
| Args:
| state (dict): Extra state from the `state_dict`
|
| set_submodule(self, target: str, module: 'Module', strict: bool = False) -> None
| Set the submodule given by ``target`` if it exists, otherwise throw an error.
|
| .. note::
| If ``strict`` is set to ``False`` (default), the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``strict`` is set to ``True``,
| the method will only attempt to replace an existing submodule and throw an error if
| the submodule does not exist.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(3, 3, 3)
| )
| (linear): Linear(3, 3)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To override the ``Conv2d`` with a new submodule ``Linear``, you
| could call ``set_submodule("net_b.net_c.conv", nn.Linear(1, 1))``
| where ``strict`` could be ``True`` or ``False``
|
| To add a new submodule ``Conv2d`` to the existing ``net_b`` module,
| you would call ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1))``.
|
| In the above if you set ``strict=True`` and call
| ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1), strict=True)``, an AttributeError
| will be raised because ``net_b`` does not have a submodule named ``conv``.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
| module: The module to set the submodule to.
| strict: If ``False``, the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``True``,
| the method will only attempt to replace an existing submodule and throw an error
| if the submodule doesn't already exist.
|
| Raises:
| ValueError: If the ``target`` string is empty or if ``module`` is not an instance of ``nn.Module``.
| AttributeError: If at any point along the path resulting from
| the ``target`` string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| share_memory(self) -> Self
| See :meth:`torch.Tensor.share_memory_`.
|
| state_dict(self, *args, destination=None, prefix='', keep_vars=False)
| Return a dictionary containing references to the whole state of the module.
|
| Both parameters and persistent buffers (e.g. running averages) are
| included. Keys are corresponding parameter and buffer names.
| Parameters and buffers set to ``None`` are not included.
|
| .. note::
| The returned object is a shallow copy. It contains references
| to the module's parameters and buffers.
|
| .. warning::
| Currently ``state_dict()`` also accepts positional arguments for
| ``destination``, ``prefix`` and ``keep_vars`` in order. However,
| this is being deprecated and keyword arguments will be enforced in
| future releases.
|
| .. warning::
| Please avoid the use of argument ``destination`` as it is not
| designed for end-users.
|
| Args:
| destination (dict, optional): If provided, the state of module will
| be updated into the dict and the same object is returned.
| Otherwise, an ``OrderedDict`` will be created and returned.
| Default: ``None``.
| prefix (str, optional): a prefix added to parameter and buffer
| names to compose the keys in state_dict. Default: ``''``.
| keep_vars (bool, optional): by default the :class:`~torch.Tensor` s
| returned in the state dict are detached from autograd. If it's
| set to ``True``, detaching will not be performed.
| Default: ``False``.
|
| Returns:
| dict:
| a dictionary containing a whole state of the module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> module.state_dict().keys()
| ['bias', 'weight']
|
| to(self, *args, **kwargs)
| Move and/or cast the parameters and buffers.
|
| This can be called as
|
| .. function:: to(device=None, dtype=None, non_blocking=False)
| :noindex:
|
| .. function:: to(dtype, non_blocking=False)
| :noindex:
|
| .. function:: to(tensor, non_blocking=False)
| :noindex:
|
| .. function:: to(memory_format=torch.channels_last)
| :noindex:
|
| Its signature is similar to :meth:`torch.Tensor.to`, but only accepts
| floating point or complex :attr:`dtype`\ s. In addition, this method will
| only cast the floating point or complex parameters and buffers to :attr:`dtype`
| (if given). The integral parameters and buffers will be moved
| :attr:`device`, if that is given, but with dtypes unchanged. When
| :attr:`non_blocking` is set, it tries to convert/move asynchronously
| with respect to the host if possible, e.g., moving CPU Tensors with
| pinned memory to CUDA devices.
|
| See below for examples.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (:class:`torch.device`): the desired device of the parameters
| and buffers in this module
| dtype (:class:`torch.dtype`): the desired floating point or complex dtype of
| the parameters and buffers in this module
| tensor (torch.Tensor): Tensor whose dtype and device are the desired
| dtype and device for all parameters and buffers in this module
| memory_format (:class:`torch.memory_format`): the desired memory
| format for 4D parameters and buffers in this module (keyword
| only argument)
|
| Returns:
| Module: self
|
| Examples::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> linear = nn.Linear(2, 2)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]])
| >>> linear.to(torch.double)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]], dtype=torch.float64)
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA1)
| >>> gpu1 = torch.device("cuda:1")
| >>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
| >>> cpu = torch.device("cpu")
| >>> linear.to(cpu)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16)
|
| >>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.3741+0.j, 0.2382+0.j],
| [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
| >>> linear(torch.ones(3, 2, dtype=torch.cdouble))
| tensor([[0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
|
| to_empty(self, *, device: str | torch.device | int | None, recurse: bool = True) -> Self
| Move the parameters and buffers to the specified device without copying storage.
|
| Args:
| device (:class:`torch.device`): The desired device of the parameters
| and buffers in this module.
| recurse (bool): Whether parameters and buffers of submodules should
| be recursively moved to the specified device.
|
| Returns:
| Module: self
|
| train(self, mode: bool = True) -> Self
| Set the module in training mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e., whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| Args:
| mode (bool): whether to set training mode (``True``) or evaluation
| mode (``False``). Default: ``True``.
|
| Returns:
| Module: self
|
| type(self, dst_type: torch.dtype | str) -> Self
| Casts all parameters and buffers to :attr:`dst_type`.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| dst_type (type or string): the desired type
|
| Returns:
| Module: self
|
| xpu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the XPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing optimizer if the module will
| live on XPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset gradients of all model parameters.
|
| See similar function under :class:`torch.optim.Optimizer` for more context.
|
| Args:
| set_to_none (bool): instead of setting to zero, set the grads to None.
| See :meth:`torch.optim.Optimizer.zero_grad` for details.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.nn.modules.module.Module:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.nn.modules.module.Module:
|
| T_destination = ~T_destination
|
| call_super_init = False
|
| dump_patches = False
class QuantType(enum.IntEnum)
| QuantType(*values)
|
| # Quantization type (dynamic quantization, static quantization).
| # Should match the c++ enum in quantization_type.h
|
| Method resolution order:
| QuantType
| enum.IntEnum
| builtins.int
| enum.ReprEnum
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec, /) from builtins.int
| Convert to a string according to format_spec.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DYNAMIC = <QuantType.DYNAMIC: 0>
|
| QAT = <QuantType.QAT: 2>
|
| STATIC = <QuantType.STATIC: 1>
|
| WEIGHT_ONLY = <QuantType.WEIGHT_ONLY: 3>
|
| ----------------------------------------------------------------------
| Methods inherited from enum.IntEnum:
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__ = __repr__(self, /) from builtins.int
| Return repr(self).
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.int:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.int:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.int:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Static methods inherited from enum.EnumType:
|
| __contains__(value)
| Return True if `value` is in `cls`.
|
| `value` is in `cls` if:
| 1) `value` is a member of `cls`, or
| 2) `value` is the value of one of the `cls`'s members.
|
| __getitem__(name)
| Return the member matching `name`.
|
| __iter__()
| Return members in definition order.
|
| __len__()
| Return the number of members (no aliases)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class QuantWrapper(torch.nn.modules.module.Module)
| QuantWrapper(module: torch.nn.modules.module.Module)
|
| A wrapper class that wraps the input module, adds QuantStub and
| DeQuantStub and surround the call to module with call to quant and dequant
| modules.
|
| This is used by the `quantization` utility functions to add the quant and
| dequant modules, before `convert` function `QuantStub` will just be observer,
| it observes the input tensor, after `convert`, `QuantStub`
| will be swapped to `nnq.Quantize` which does actual quantization. Similarly
| for `DeQuantStub`.
|
| Method resolution order:
| QuantWrapper
| torch.nn.modules.module.Module
| builtins.object
|
| Methods defined here:
|
| __init__(self, module: torch.nn.modules.module.Module)
| Initialize internal Module state, shared by both nn.Module and ScriptModule.
|
| forward(self, X: torch.Tensor) -> torch.Tensor
| Define the computation performed at every call.
|
| Should be overridden by all subclasses.
|
| .. note::
| Although the recipe for forward pass needs to be defined within
| this function, one should call the :class:`Module` instance afterwards
| instead of this since the former takes care of running the
| registered hooks while the latter silently ignores them.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'dequant': <class 'torch.ao.quantization.stubs.DeQu...
|
| ----------------------------------------------------------------------
| Methods inherited from torch.nn.modules.module.Module:
|
| __call__ = _wrapped_call_impl(self, *args, **kwargs)
|
| __delattr__(self, name) -> None
| Implement delattr(self, name).
|
| __dir__(self)
| Default dir() implementation.
|
| __getattr__(self, name: str) -> Union[torch.Tensor, ForwardRef('Module')]
| # It is crucial that the return type is not annotated as `Any`, otherwise type checking
| # on `torch.nn.Module` and all its subclasses is largely disabled as a result. See:
| # https://github.com/pytorch/pytorch/pull/115074
|
| __getstate__(self)
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setattr__(self, name: str, value: Union[torch.Tensor, ForwardRef('Module')]) -> None
| Implement setattr(self, name, value).
|
| __setstate__(self, state)
|
| add_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Add a child module to the current module.
|
| The module can be accessed as an attribute using the given name.
|
| Args:
| name (str): name of the child module. The child module can be
| accessed from this module using the given name
| module (Module): child module to be added to the module.
|
| apply(self, fn: collections.abc.Callable[['Module'], None]) -> Self
| Apply ``fn`` recursively to every submodule (as returned by ``.children()``) as well as self.
|
| Typical use includes initializing the parameters of a model
| (see also :ref:`nn-init-doc`).
|
| Args:
| fn (:class:`Module` -> None): function to be applied to each submodule
|
| Returns:
| Module: self
|
| Example::
|
| >>> @torch.no_grad()
| >>> def init_weights(m):
| >>> print(m)
| >>> if type(m) is nn.Linear:
| >>> m.weight.fill_(1.0)
| >>> print(m.weight)
| >>> net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
| >>> net.apply(init_weights)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
|
| bfloat16(self) -> Self
| Casts all floating point parameters and buffers to ``bfloat16`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| buffers(self, recurse: bool = True) -> collections.abc.Iterator[torch.Tensor]
| Return an iterator over module buffers.
|
| Args:
| recurse (bool): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module.
|
| Yields:
| torch.Tensor: module buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for buf in model.buffers():
| >>> print(type(buf), buf.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| children(self) -> collections.abc.Iterator['Module']
| Return an iterator over immediate children modules.
|
| Yields:
| Module: a child module
|
| compile(self, *args, **kwargs) -> None
| Compile this Module's forward using :func:`torch.compile`.
|
| This Module's `__call__` method is compiled and all arguments are passed as-is
| to :func:`torch.compile`.
|
| See :func:`torch.compile` for details on the arguments for this function.
|
| cpu(self) -> Self
| Move all model parameters and buffers to the CPU.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| cuda(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the GPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on GPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| double(self) -> Self
| Casts all floating point parameters and buffers to ``double`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| eval(self) -> Self
| Set the module in evaluation mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e. whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| This is equivalent with :meth:`self.train(False) <torch.nn.Module.train>`.
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.eval()` and several similar mechanisms that may be confused with it.
|
| Returns:
| Module: self
|
| extra_repr(self) -> str
| Return the extra representation of the module.
|
| To print customized extra information, you should re-implement
| this method in your own modules. Both single-line and multi-line
| strings are acceptable.
|
| float(self) -> Self
| Casts all floating point parameters and buffers to ``float`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| get_buffer(self, target: str) -> torch.Tensor
| Return the buffer given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the buffer
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.Tensor: The buffer referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not a
| buffer
|
| get_extra_state(self) -> Any
| Return any extra state to include in the module's state_dict.
|
| Implement this and a corresponding :func:`set_extra_state` for your module
| if you need to store extra state. This function is called when building the
| module's `state_dict()`.
|
| Note that extra state should be picklable to ensure working serialization
| of the state_dict. We only provide backwards compatibility guarantees
| for serializing Tensors; other objects may break backwards compatibility if
| their serialized pickled form changes.
|
| Returns:
| object: Any extra state to store in the module's state_dict
|
| get_parameter(self, target: str) -> torch.nn.parameter.Parameter
| Return the parameter given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the Parameter
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Parameter: The Parameter referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not an
| ``nn.Parameter``
|
| get_submodule(self, target: str) -> 'Module'
| Return the submodule given by ``target`` if it exists, otherwise throw an error.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(16, 33, kernel_size=(3, 3), stride=(2, 2))
| )
| (linear): Linear(in_features=100, out_features=200, bias=True)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` which has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To check whether or not we have the ``linear`` submodule, we
| would call ``get_submodule("net_b.linear")``. To check whether
| we have the ``conv`` submodule, we would call
| ``get_submodule("net_b.net_c.conv")``.
|
| The runtime of ``get_submodule`` is bounded by the degree
| of module nesting in ``target``. A query against
| ``named_modules`` achieves the same result, but it is O(N) in
| the number of transitive modules. So, for a simple check to see
| if some submodule exists, ``get_submodule`` should always be
| used.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Module: The submodule referenced by ``target``
|
| Raises:
| AttributeError: If at any point along the path resulting from
| the target string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| half(self) -> Self
| Casts all floating point parameters and buffers to ``half`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| ipu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the IPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on IPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| load_state_dict(self, state_dict: collections.abc.Mapping[str, typing.Any], strict: bool = True, assign: bool = False)
| Copy parameters and buffers from :attr:`state_dict` into this module and its descendants.
|
| If :attr:`strict` is ``True``, then
| the keys of :attr:`state_dict` must exactly match the keys returned
| by this module's :meth:`~torch.nn.Module.state_dict` function.
|
| .. warning::
| If :attr:`assign` is ``True`` the optimizer must be created after
| the call to :attr:`load_state_dict` unless
| :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| Args:
| state_dict (dict): a dict containing parameters and
| persistent buffers.
| strict (bool, optional): whether to strictly enforce that the keys
| in :attr:`state_dict` match the keys returned by this module's
| :meth:`~torch.nn.Module.state_dict` function. Default: ``True``
| assign (bool, optional): When set to ``False``, the properties of the tensors
| in the current module are preserved whereas setting it to ``True`` preserves
| properties of the Tensors in the state dict. The only
| exception is the ``requires_grad`` field of :class:`~torch.nn.Parameter`
| for which the value from the module is preserved. Default: ``False``
|
| Returns:
| ``NamedTuple`` with ``missing_keys`` and ``unexpected_keys`` fields:
| * ``missing_keys`` is a list of str containing any keys that are expected
| by this module but missing from the provided ``state_dict``.
| * ``unexpected_keys`` is a list of str containing the keys that are not
| expected by this module but present in the provided ``state_dict``.
|
| Note:
| If a parameter or buffer is registered as ``None`` and its corresponding key
| exists in :attr:`state_dict`, :meth:`load_state_dict` will raise a
| ``RuntimeError``.
|
| modules(self, remove_duplicate: bool = True) -> collections.abc.Iterator['Module']
| Return an iterator over all modules in the network.
|
| Args:
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not.
|
| Yields:
| Module: a module in the network
|
| Note:
| Duplicate modules are returned only once by default. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.modules()):
| ... print(idx, '->', m)
|
| 0 -> Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
| 1 -> Linear(in_features=2, out_features=2, bias=True)
|
| mtia(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the MTIA.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on MTIA while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| named_buffers(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.Tensor]]
| Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
|
| Args:
| prefix (str): prefix to prepend to all buffer names.
| recurse (bool, optional): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module. Defaults to True.
| remove_duplicate (bool, optional): whether to remove the duplicated buffers in the result. Defaults to True.
|
| Yields:
| (str, torch.Tensor): Tuple containing the name and buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, buf in self.named_buffers():
| >>> if name in ['running_var']:
| >>> print(buf.size())
|
| named_children(self) -> collections.abc.Iterator[tuple[str, 'Module']]
| Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
|
| Yields:
| (str, Module): Tuple containing a name and child module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, module in model.named_children():
| >>> if name in ['conv4', 'conv5']:
| >>> print(module)
|
| named_modules(self, memo: set['Module'] | None = None, prefix: str = '', remove_duplicate: bool = True)
| Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
|
| Args:
| memo: a memo to store the set of modules already added to the result
| prefix: a prefix that will be added to the name of the module
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not
|
| Yields:
| (str, Module): Tuple of name and module
|
| Note:
| Duplicate modules are returned only once. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.named_modules()):
| ... print(idx, '->', m)
|
| 0 -> ('', Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| ))
| 1 -> ('0', Linear(in_features=2, out_features=2, bias=True))
|
| named_parameters(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.nn.parameter.Parameter]]
| Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
|
| Args:
| prefix (str): prefix to prepend to all parameter names.
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
| remove_duplicate (bool, optional): whether to remove the duplicated
| parameters in the result. Defaults to True.
|
| Yields:
| (str, Parameter): Tuple containing the name and parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, param in self.named_parameters():
| >>> if name in ['bias']:
| >>> print(param.size())
|
| parameters(self, recurse: bool = True) -> collections.abc.Iterator[torch.nn.parameter.Parameter]
| Return an iterator over module parameters.
|
| This is typically passed to an optimizer.
|
| Args:
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
|
| Yields:
| Parameter: module parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for param in model.parameters():
| >>> print(type(param), param.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| register_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None]) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| This function is deprecated in favor of :meth:`~torch.nn.Module.register_full_backward_hook` and
| the behavior of this function will change in future versions.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_buffer(self, name: str, tensor: torch.Tensor | None, persistent: bool = True) -> None
| Add a buffer to the module.
|
| This is typically used to register a buffer that should not be
| considered a model parameter. For example, BatchNorm's ``running_mean``
| is not a parameter, but is part of the module's state. Buffers, by
| default, are persistent and will be saved alongside parameters. This
| behavior can be changed by setting :attr:`persistent` to ``False``. The
| only difference between a persistent buffer and a non-persistent buffer
| is that the latter will not be a part of this module's
| :attr:`state_dict`.
|
| Buffers can be accessed as attributes using given names.
|
| Args:
| name (str): name of the buffer. The buffer can be accessed
| from this module using the given name
| tensor (Tensor or None): buffer to be registered. If ``None``, then operations
| that run on buffers, such as :attr:`cuda`, are ignored. If ``None``,
| the buffer is **not** included in the module's :attr:`state_dict`.
| persistent (bool): whether the buffer is part of this module's
| :attr:`state_dict`.
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> self.register_buffer('running_mean', torch.zeros(num_features))
|
| register_forward_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...], typing.Any], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any], typing.Any], typing.Any | None], *, prepend: bool = False, with_kwargs: bool = False, always_call: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward hook on the module.
|
| The hook will be called every time after :func:`forward` has computed an output.
|
| If ``with_kwargs`` is ``False`` or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| output. It can modify the input inplace but it will not have effect on
| forward since this is called after :func:`forward` is called. The hook
| should have the following signature::
|
| hook(module, args, output) -> None or modified output
|
| If ``with_kwargs`` is ``True``, the forward hook will be passed the
| ``kwargs`` given to the forward function and be expected to return the
| output possibly modified. The hook should have the following signature::
|
| hook(module, args, kwargs, output) -> None or modified output
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If ``True``, the provided ``hook`` will be fired
| before all existing ``forward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``forward`` hooks registered with
| :func:`register_module_forward_hook` will fire before all hooks
| registered by this method.
| Default: ``False``
| with_kwargs (bool): If ``True``, the ``hook`` will be passed the
| kwargs given to the forward function.
| Default: ``False``
| always_call (bool): If ``True`` the ``hook`` will be run regardless of
| whether an exception is raised while calling the Module.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_forward_pre_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...]], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[typing.Any, dict[str, typing.Any]] | None], *, prepend: bool = False, with_kwargs: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward pre-hook on the module.
|
| The hook will be called every time before :func:`forward` is invoked.
|
|
| If ``with_kwargs`` is false or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| input. User can either return a tuple or a single modified value in the
| hook. We will wrap the value into a tuple if a single value is returned
| (unless that value is already a tuple). The hook should have the
| following signature::
|
| hook(module, args) -> None or modified input
|
| If ``with_kwargs`` is true, the forward pre-hook will be passed the
| kwargs given to the forward function. And if the hook modifies the
| input, both the args and kwargs should be returned. The hook should have
| the following signature::
|
| hook(module, args, kwargs) -> None or a tuple of modified input and kwargs
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``forward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``forward_pre`` hooks registered with
| :func:`register_module_forward_pre_hook` will fire before all
| hooks registered by this method.
| Default: ``False``
| with_kwargs (bool): If true, the ``hook`` will be passed the kwargs
| given to the forward function.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| The hook will be called every time the gradients with respect to a module are computed, and its firing rules are as follows:
|
| 1. Ordinarily, the hook fires when the gradients are computed with respect to the module inputs.
| 2. If none of the module inputs require gradients, the hook will fire when the gradients are computed
| with respect to module outputs.
| 3. If none of the module outputs require gradients, then the hooks will not fire.
|
| The hook should have the following signature::
|
| hook(module, grad_input, grad_output) -> tuple(Tensor) or None
|
| The :attr:`grad_input` and :attr:`grad_output` are tuples that contain the gradients
| with respect to the inputs and outputs respectively. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the input that will be used in place of :attr:`grad_input` in
| subsequent computations. :attr:`grad_input` will only correspond to the inputs given
| as positional arguments and all kwarg arguments are ignored. Entries
| in :attr:`grad_input` and :attr:`grad_output` will be ``None`` for all non-Tensor
| arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs or outputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``backward`` hooks registered with
| :func:`register_module_full_backward_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_pre_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward pre-hook on the module.
|
| The hook will be called every time the gradients for the module are computed.
| The hook should have the following signature::
|
| hook(module, grad_output) -> tuple[Tensor, ...], Tensor or None
|
| The :attr:`grad_output` is a tuple. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the output that will be used in place of :attr:`grad_output` in
| subsequent computations. Entries in :attr:`grad_output` will be ``None`` for
| all non-Tensor arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``backward_pre`` hooks registered with
| :func:`register_module_full_backward_pre_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_post_hook(self, hook)
| Register a post-hook to be run after module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, incompatible_keys) -> None
|
| The ``module`` argument is the current module that this hook is registered
| on, and the ``incompatible_keys`` argument is a ``NamedTuple`` consisting
| of attributes ``missing_keys`` and ``unexpected_keys``. ``missing_keys``
| is a ``list`` of ``str`` containing the missing keys and
| ``unexpected_keys`` is a ``list`` of ``str`` containing the unexpected keys.
|
| The given incompatible_keys can be modified inplace if needed.
|
| Note that the checks performed when calling :func:`load_state_dict` with
| ``strict=True`` are affected by modifications the hook makes to
| ``missing_keys`` or ``unexpected_keys``, as expected. Additions to either
| set of keys will result in an error being thrown when ``strict=True``, and
| clearing out both missing and unexpected keys will avoid an error.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook)
| Register a pre-hook to be run before module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) -> None # noqa: B950
|
| Arguments:
| hook (Callable): Callable hook that will be invoked before
| loading the state dict.
|
| register_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Alias for :func:`add_module`.
|
| register_parameter(self, name: str, param: torch.nn.parameter.Parameter | None) -> None
| Add a parameter to the module.
|
| The parameter can be accessed as an attribute using given name.
|
| Args:
| name (str): name of the parameter. The parameter can be accessed
| from this module using the given name
| param (Parameter or None): parameter to be added to the module. If
| ``None``, then operations that run on parameters, such as :attr:`cuda`,
| are ignored. If ``None``, the parameter is **not** included in the
| module's :attr:`state_dict`.
|
| register_state_dict_post_hook(self, hook)
| Register a post-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata) -> None
|
| The registered hooks can modify the ``state_dict`` inplace.
|
| register_state_dict_pre_hook(self, hook)
| Register a pre-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, prefix, keep_vars) -> None
|
| The registered hooks can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| requires_grad_(self, requires_grad: bool = True) -> Self
| Change if autograd should record operations on parameters in this module.
|
| This method sets the parameters' :attr:`requires_grad` attributes
| in-place.
|
| This method is helpful for freezing part of the module for finetuning
| or training parts of a model individually (e.g., GAN training).
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.requires_grad_()` and several similar mechanisms that may be confused with it.
|
| Args:
| requires_grad (bool): whether autograd should record operations on
| parameters in this module. Default: ``True``.
|
| Returns:
| Module: self
|
| set_extra_state(self, state: Any) -> None
| Set extra state contained in the loaded `state_dict`.
|
| This function is called from :func:`load_state_dict` to handle any extra state
| found within the `state_dict`. Implement this function and a corresponding
| :func:`get_extra_state` for your module if you need to store extra state within its
| `state_dict`.
|
| Args:
| state (dict): Extra state from the `state_dict`
|
| set_submodule(self, target: str, module: 'Module', strict: bool = False) -> None
| Set the submodule given by ``target`` if it exists, otherwise throw an error.
|
| .. note::
| If ``strict`` is set to ``False`` (default), the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``strict`` is set to ``True``,
| the method will only attempt to replace an existing submodule and throw an error if
| the submodule does not exist.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(3, 3, 3)
| )
| (linear): Linear(3, 3)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To override the ``Conv2d`` with a new submodule ``Linear``, you
| could call ``set_submodule("net_b.net_c.conv", nn.Linear(1, 1))``
| where ``strict`` could be ``True`` or ``False``
|
| To add a new submodule ``Conv2d`` to the existing ``net_b`` module,
| you would call ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1))``.
|
| In the above if you set ``strict=True`` and call
| ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1), strict=True)``, an AttributeError
| will be raised because ``net_b`` does not have a submodule named ``conv``.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
| module: The module to set the submodule to.
| strict: If ``False``, the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``True``,
| the method will only attempt to replace an existing submodule and throw an error
| if the submodule doesn't already exist.
|
| Raises:
| ValueError: If the ``target`` string is empty or if ``module`` is not an instance of ``nn.Module``.
| AttributeError: If at any point along the path resulting from
| the ``target`` string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| share_memory(self) -> Self
| See :meth:`torch.Tensor.share_memory_`.
|
| state_dict(self, *args, destination=None, prefix='', keep_vars=False)
| Return a dictionary containing references to the whole state of the module.
|
| Both parameters and persistent buffers (e.g. running averages) are
| included. Keys are corresponding parameter and buffer names.
| Parameters and buffers set to ``None`` are not included.
|
| .. note::
| The returned object is a shallow copy. It contains references
| to the module's parameters and buffers.
|
| .. warning::
| Currently ``state_dict()`` also accepts positional arguments for
| ``destination``, ``prefix`` and ``keep_vars`` in order. However,
| this is being deprecated and keyword arguments will be enforced in
| future releases.
|
| .. warning::
| Please avoid the use of argument ``destination`` as it is not
| designed for end-users.
|
| Args:
| destination (dict, optional): If provided, the state of module will
| be updated into the dict and the same object is returned.
| Otherwise, an ``OrderedDict`` will be created and returned.
| Default: ``None``.
| prefix (str, optional): a prefix added to parameter and buffer
| names to compose the keys in state_dict. Default: ``''``.
| keep_vars (bool, optional): by default the :class:`~torch.Tensor` s
| returned in the state dict are detached from autograd. If it's
| set to ``True``, detaching will not be performed.
| Default: ``False``.
|
| Returns:
| dict:
| a dictionary containing a whole state of the module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> module.state_dict().keys()
| ['bias', 'weight']
|
| to(self, *args, **kwargs)
| Move and/or cast the parameters and buffers.
|
| This can be called as
|
| .. function:: to(device=None, dtype=None, non_blocking=False)
| :noindex:
|
| .. function:: to(dtype, non_blocking=False)
| :noindex:
|
| .. function:: to(tensor, non_blocking=False)
| :noindex:
|
| .. function:: to(memory_format=torch.channels_last)
| :noindex:
|
| Its signature is similar to :meth:`torch.Tensor.to`, but only accepts
| floating point or complex :attr:`dtype`\ s. In addition, this method will
| only cast the floating point or complex parameters and buffers to :attr:`dtype`
| (if given). The integral parameters and buffers will be moved
| :attr:`device`, if that is given, but with dtypes unchanged. When
| :attr:`non_blocking` is set, it tries to convert/move asynchronously
| with respect to the host if possible, e.g., moving CPU Tensors with
| pinned memory to CUDA devices.
|
| See below for examples.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (:class:`torch.device`): the desired device of the parameters
| and buffers in this module
| dtype (:class:`torch.dtype`): the desired floating point or complex dtype of
| the parameters and buffers in this module
| tensor (torch.Tensor): Tensor whose dtype and device are the desired
| dtype and device for all parameters and buffers in this module
| memory_format (:class:`torch.memory_format`): the desired memory
| format for 4D parameters and buffers in this module (keyword
| only argument)
|
| Returns:
| Module: self
|
| Examples::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> linear = nn.Linear(2, 2)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]])
| >>> linear.to(torch.double)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]], dtype=torch.float64)
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA1)
| >>> gpu1 = torch.device("cuda:1")
| >>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
| >>> cpu = torch.device("cpu")
| >>> linear.to(cpu)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16)
|
| >>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.3741+0.j, 0.2382+0.j],
| [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
| >>> linear(torch.ones(3, 2, dtype=torch.cdouble))
| tensor([[0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
|
| to_empty(self, *, device: str | torch.device | int | None, recurse: bool = True) -> Self
| Move the parameters and buffers to the specified device without copying storage.
|
| Args:
| device (:class:`torch.device`): The desired device of the parameters
| and buffers in this module.
| recurse (bool): Whether parameters and buffers of submodules should
| be recursively moved to the specified device.
|
| Returns:
| Module: self
|
| train(self, mode: bool = True) -> Self
| Set the module in training mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e., whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| Args:
| mode (bool): whether to set training mode (``True``) or evaluation
| mode (``False``). Default: ``True``.
|
| Returns:
| Module: self
|
| type(self, dst_type: torch.dtype | str) -> Self
| Casts all parameters and buffers to :attr:`dst_type`.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| dst_type (type or string): the desired type
|
| Returns:
| Module: self
|
| xpu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the XPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing optimizer if the module will
| live on XPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset gradients of all model parameters.
|
| See similar function under :class:`torch.optim.Optimizer` for more context.
|
| Args:
| set_to_none (bool): instead of setting to zero, set the grads to None.
| See :meth:`torch.optim.Optimizer.zero_grad` for details.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.nn.modules.module.Module:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.nn.modules.module.Module:
|
| T_destination = ~T_destination
|
| call_super_init = False
|
| dump_patches = False
default_placeholder_observer = class PlaceholderObserver(ObserverBase)
| default_placeholder_observer(dtype=torch.float32, custom_op_name='', compute_dtype=None, quant_min=None, quant_max=None, qscheme=None, eps=None, is_dynamic=False) -> None
|
| Observer that doesn't do anything and just passes its configuration to the
| quantized module's ``.from_float()``.
|
| Can be used for quantization to float16 which doesn't require determining
| ranges.
|
| Args:
| dtype: dtype argument to the `quantize` node needed to implement the
| reference model spec.
| quant_min: minimum value in quantized domain (TODO: align behavior with other observers)
| quant_max: maximum value in quantized domain
| custom_op_name: (temporary) specify this observer for an operator that doesn't require any observation
| (Can be used in Graph Mode Passes for special case ops).
| compute_dtype (deprecated): if set, marks the future quantize function to use
| dynamic quantization instead of static quantization.
| This field is deprecated, use `is_dynamic=True` instead.
| is_dynamic: if True, the `quantize` function in the reference model
| representation taking stats from this observer instance will
| use dynamic quantization.
|
| Method resolution order:
| PlaceholderObserver
| ObserverBase
| abc.ABC
| torch.nn.modules.module.Module
| builtins.object
|
| Methods defined here:
|
| __init__(self, dtype=torch.float32, custom_op_name='', compute_dtype=None, quant_min=None, quant_max=None, qscheme=None, eps=None, is_dynamic=False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| calculate_qparams(self)
|
| extra_repr(self)
| Return the extra representation of the module.
|
| To print customized extra information, you should re-implement
| this method in your own modules. Both single-line and multi-line
| strings are acceptable.
|
| forward(self, x)
| Define the computation performed at every call.
|
| Should be overridden by all subclasses.
|
| .. note::
| Although the recipe for forward pass needs to be defined within
| this function, one should call the :class:`Module` instance afterwards
| instead of this since the former takes care of running the
| registered hooks while the latter silently ignores them.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Class methods inherited from ObserverBase:
|
| with_args = _with_args(**kwargs) from torch.ao.quantization.observer
| Wrapper that allows creation of class factories.
|
| This can be useful when there is a need to create classes with the same
| constructor arguments, but different instances. Can be used in conjunction with
| _callable_args
|
| Example::
|
| >>> # xdoctest: +SKIP("Undefined vars")
| >>> Foo.with_args = classmethod(_with_args)
| >>> foo_builder = Foo.with_args(a=3, b=4).with_args(answer=42)
| >>> foo_instance1 = foo_builder()
| >>> foo_instance2 = foo_builder()
| >>> id(foo_instance1) == id(foo_instance2)
| False
|
| with_callable_args = _with_callable_args(**kwargs) from torch.ao.quantization.observer
| Wrapper that allows creation of class factories args that need to be
| called at construction time.
|
| This can be useful when there is a need to create classes with the same
| constructor arguments, but different instances and those arguments should only
| be calculated at construction time. Can be used in conjunction with _with_args
|
| Example::
|
| >>> # xdoctest: +SKIP("Undefined vars")
| >>> Foo.with_callable_args = classmethod(_with_callable_args)
| >>> Foo.with_args = classmethod(_with_args)
| >>> foo_builder = Foo.with_callable_args(cur_time=get_time_func).with_args(name="dan")
| >>> foo_instance1 = foo_builder()
| >>> # wait 50
| >>> foo_instance2 = foo_builder()
| >>> id(foo_instance1.creation_time) == id(foo_instance2.creation_time)
| False
|
| ----------------------------------------------------------------------
| Data descriptors inherited from abc.ABC:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from torch.nn.modules.module.Module:
|
| __call__ = _wrapped_call_impl(self, *args, **kwargs)
|
| __delattr__(self, name) -> None
| Implement delattr(self, name).
|
| __dir__(self)
| Default dir() implementation.
|
| __getattr__(self, name: str) -> Union[torch.Tensor, ForwardRef('Module')]
| # It is crucial that the return type is not annotated as `Any`, otherwise type checking
| # on `torch.nn.Module` and all its subclasses is largely disabled as a result. See:
| # https://github.com/pytorch/pytorch/pull/115074
|
| __getstate__(self)
| Helper for pickle.
|
| __repr__(self) -> str
| Return repr(self).
|
| __setattr__(self, name: str, value: Union[torch.Tensor, ForwardRef('Module')]) -> None
| Implement setattr(self, name, value).
|
| __setstate__(self, state)
|
| add_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Add a child module to the current module.
|
| The module can be accessed as an attribute using the given name.
|
| Args:
| name (str): name of the child module. The child module can be
| accessed from this module using the given name
| module (Module): child module to be added to the module.
|
| apply(self, fn: collections.abc.Callable[['Module'], None]) -> Self
| Apply ``fn`` recursively to every submodule (as returned by ``.children()``) as well as self.
|
| Typical use includes initializing the parameters of a model
| (see also :ref:`nn-init-doc`).
|
| Args:
| fn (:class:`Module` -> None): function to be applied to each submodule
|
| Returns:
| Module: self
|
| Example::
|
| >>> @torch.no_grad()
| >>> def init_weights(m):
| >>> print(m)
| >>> if type(m) is nn.Linear:
| >>> m.weight.fill_(1.0)
| >>> print(m.weight)
| >>> net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
| >>> net.apply(init_weights)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Linear(in_features=2, out_features=2, bias=True)
| Parameter containing:
| tensor([[1., 1.],
| [1., 1.]], requires_grad=True)
| Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
|
| bfloat16(self) -> Self
| Casts all floating point parameters and buffers to ``bfloat16`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| buffers(self, recurse: bool = True) -> collections.abc.Iterator[torch.Tensor]
| Return an iterator over module buffers.
|
| Args:
| recurse (bool): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module.
|
| Yields:
| torch.Tensor: module buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for buf in model.buffers():
| >>> print(type(buf), buf.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| children(self) -> collections.abc.Iterator['Module']
| Return an iterator over immediate children modules.
|
| Yields:
| Module: a child module
|
| compile(self, *args, **kwargs) -> None
| Compile this Module's forward using :func:`torch.compile`.
|
| This Module's `__call__` method is compiled and all arguments are passed as-is
| to :func:`torch.compile`.
|
| See :func:`torch.compile` for details on the arguments for this function.
|
| cpu(self) -> Self
| Move all model parameters and buffers to the CPU.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| cuda(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the GPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on GPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| double(self) -> Self
| Casts all floating point parameters and buffers to ``double`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| eval(self) -> Self
| Set the module in evaluation mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e. whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| This is equivalent with :meth:`self.train(False) <torch.nn.Module.train>`.
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.eval()` and several similar mechanisms that may be confused with it.
|
| Returns:
| Module: self
|
| float(self) -> Self
| Casts all floating point parameters and buffers to ``float`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| get_buffer(self, target: str) -> torch.Tensor
| Return the buffer given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the buffer
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.Tensor: The buffer referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not a
| buffer
|
| get_extra_state(self) -> Any
| Return any extra state to include in the module's state_dict.
|
| Implement this and a corresponding :func:`set_extra_state` for your module
| if you need to store extra state. This function is called when building the
| module's `state_dict()`.
|
| Note that extra state should be picklable to ensure working serialization
| of the state_dict. We only provide backwards compatibility guarantees
| for serializing Tensors; other objects may break backwards compatibility if
| their serialized pickled form changes.
|
| Returns:
| object: Any extra state to store in the module's state_dict
|
| get_parameter(self, target: str) -> torch.nn.parameter.Parameter
| Return the parameter given by ``target`` if it exists, otherwise throw an error.
|
| See the docstring for ``get_submodule`` for a more detailed
| explanation of this method's functionality as well as how to
| correctly specify ``target``.
|
| Args:
| target: The fully-qualified string name of the Parameter
| to look for. (See ``get_submodule`` for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Parameter: The Parameter referenced by ``target``
|
| Raises:
| AttributeError: If the target string references an invalid
| path or resolves to something that is not an
| ``nn.Parameter``
|
| get_submodule(self, target: str) -> 'Module'
| Return the submodule given by ``target`` if it exists, otherwise throw an error.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(16, 33, kernel_size=(3, 3), stride=(2, 2))
| )
| (linear): Linear(in_features=100, out_features=200, bias=True)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` which has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To check whether or not we have the ``linear`` submodule, we
| would call ``get_submodule("net_b.linear")``. To check whether
| we have the ``conv`` submodule, we would call
| ``get_submodule("net_b.net_c.conv")``.
|
| The runtime of ``get_submodule`` is bounded by the degree
| of module nesting in ``target``. A query against
| ``named_modules`` achieves the same result, but it is O(N) in
| the number of transitive modules. So, for a simple check to see
| if some submodule exists, ``get_submodule`` should always be
| used.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
|
| Returns:
| torch.nn.Module: The submodule referenced by ``target``
|
| Raises:
| AttributeError: If at any point along the path resulting from
| the target string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| half(self) -> Self
| Casts all floating point parameters and buffers to ``half`` datatype.
|
| .. note::
| This method modifies the module in-place.
|
| Returns:
| Module: self
|
| ipu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the IPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on IPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| load_state_dict(self, state_dict: collections.abc.Mapping[str, typing.Any], strict: bool = True, assign: bool = False)
| Copy parameters and buffers from :attr:`state_dict` into this module and its descendants.
|
| If :attr:`strict` is ``True``, then
| the keys of :attr:`state_dict` must exactly match the keys returned
| by this module's :meth:`~torch.nn.Module.state_dict` function.
|
| .. warning::
| If :attr:`assign` is ``True`` the optimizer must be created after
| the call to :attr:`load_state_dict` unless
| :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| Args:
| state_dict (dict): a dict containing parameters and
| persistent buffers.
| strict (bool, optional): whether to strictly enforce that the keys
| in :attr:`state_dict` match the keys returned by this module's
| :meth:`~torch.nn.Module.state_dict` function. Default: ``True``
| assign (bool, optional): When set to ``False``, the properties of the tensors
| in the current module are preserved whereas setting it to ``True`` preserves
| properties of the Tensors in the state dict. The only
| exception is the ``requires_grad`` field of :class:`~torch.nn.Parameter`
| for which the value from the module is preserved. Default: ``False``
|
| Returns:
| ``NamedTuple`` with ``missing_keys`` and ``unexpected_keys`` fields:
| * ``missing_keys`` is a list of str containing any keys that are expected
| by this module but missing from the provided ``state_dict``.
| * ``unexpected_keys`` is a list of str containing the keys that are not
| expected by this module but present in the provided ``state_dict``.
|
| Note:
| If a parameter or buffer is registered as ``None`` and its corresponding key
| exists in :attr:`state_dict`, :meth:`load_state_dict` will raise a
| ``RuntimeError``.
|
| modules(self, remove_duplicate: bool = True) -> collections.abc.Iterator['Module']
| Return an iterator over all modules in the network.
|
| Args:
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not.
|
| Yields:
| Module: a module in the network
|
| Note:
| Duplicate modules are returned only once by default. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.modules()):
| ... print(idx, '->', m)
|
| 0 -> Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| )
| 1 -> Linear(in_features=2, out_features=2, bias=True)
|
| mtia(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the MTIA.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing the optimizer if the module will
| live on MTIA while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| named_buffers(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.Tensor]]
| Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
|
| Args:
| prefix (str): prefix to prepend to all buffer names.
| recurse (bool, optional): if True, then yields buffers of this module
| and all submodules. Otherwise, yields only buffers that
| are direct members of this module. Defaults to True.
| remove_duplicate (bool, optional): whether to remove the duplicated buffers in the result. Defaults to True.
|
| Yields:
| (str, torch.Tensor): Tuple containing the name and buffer
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, buf in self.named_buffers():
| >>> if name in ['running_var']:
| >>> print(buf.size())
|
| named_children(self) -> collections.abc.Iterator[tuple[str, 'Module']]
| Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
|
| Yields:
| (str, Module): Tuple containing a name and child module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, module in model.named_children():
| >>> if name in ['conv4', 'conv5']:
| >>> print(module)
|
| named_modules(self, memo: set['Module'] | None = None, prefix: str = '', remove_duplicate: bool = True)
| Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
|
| Args:
| memo: a memo to store the set of modules already added to the result
| prefix: a prefix that will be added to the name of the module
| remove_duplicate: whether to remove the duplicated module instances in the result
| or not
|
| Yields:
| (str, Module): Tuple of name and module
|
| Note:
| Duplicate modules are returned only once. In the following
| example, ``l`` will be returned only once.
|
| Example::
|
| >>> l = nn.Linear(2, 2)
| >>> net = nn.Sequential(l, l)
| >>> for idx, m in enumerate(net.named_modules()):
| ... print(idx, '->', m)
|
| 0 -> ('', Sequential(
| (0): Linear(in_features=2, out_features=2, bias=True)
| (1): Linear(in_features=2, out_features=2, bias=True)
| ))
| 1 -> ('0', Linear(in_features=2, out_features=2, bias=True))
|
| named_parameters(self, prefix: str = '', recurse: bool = True, remove_duplicate: bool = True) -> collections.abc.Iterator[tuple[str, torch.nn.parameter.Parameter]]
| Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
|
| Args:
| prefix (str): prefix to prepend to all parameter names.
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
| remove_duplicate (bool, optional): whether to remove the duplicated
| parameters in the result. Defaults to True.
|
| Yields:
| (str, Parameter): Tuple containing the name and parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for name, param in self.named_parameters():
| >>> if name in ['bias']:
| >>> print(param.size())
|
| parameters(self, recurse: bool = True) -> collections.abc.Iterator[torch.nn.parameter.Parameter]
| Return an iterator over module parameters.
|
| This is typically passed to an optimizer.
|
| Args:
| recurse (bool): if True, then yields parameters of this module
| and all submodules. Otherwise, yields only parameters that
| are direct members of this module.
|
| Yields:
| Parameter: module parameter
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> for param in model.parameters():
| >>> print(type(param), param.size())
| <class 'torch.Tensor'> (20L,)
| <class 'torch.Tensor'> (20L, 1L, 5L, 5L)
|
| register_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None]) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| This function is deprecated in favor of :meth:`~torch.nn.Module.register_full_backward_hook` and
| the behavior of this function will change in future versions.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_buffer(self, name: str, tensor: torch.Tensor | None, persistent: bool = True) -> None
| Add a buffer to the module.
|
| This is typically used to register a buffer that should not be
| considered a model parameter. For example, BatchNorm's ``running_mean``
| is not a parameter, but is part of the module's state. Buffers, by
| default, are persistent and will be saved alongside parameters. This
| behavior can be changed by setting :attr:`persistent` to ``False``. The
| only difference between a persistent buffer and a non-persistent buffer
| is that the latter will not be a part of this module's
| :attr:`state_dict`.
|
| Buffers can be accessed as attributes using given names.
|
| Args:
| name (str): name of the buffer. The buffer can be accessed
| from this module using the given name
| tensor (Tensor or None): buffer to be registered. If ``None``, then operations
| that run on buffers, such as :attr:`cuda`, are ignored. If ``None``,
| the buffer is **not** included in the module's :attr:`state_dict`.
| persistent (bool): whether the buffer is part of this module's
| :attr:`state_dict`.
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> self.register_buffer('running_mean', torch.zeros(num_features))
|
| register_forward_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...], typing.Any], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any], typing.Any], typing.Any | None], *, prepend: bool = False, with_kwargs: bool = False, always_call: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward hook on the module.
|
| The hook will be called every time after :func:`forward` has computed an output.
|
| If ``with_kwargs`` is ``False`` or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| output. It can modify the input inplace but it will not have effect on
| forward since this is called after :func:`forward` is called. The hook
| should have the following signature::
|
| hook(module, args, output) -> None or modified output
|
| If ``with_kwargs`` is ``True``, the forward hook will be passed the
| ``kwargs`` given to the forward function and be expected to return the
| output possibly modified. The hook should have the following signature::
|
| hook(module, args, kwargs, output) -> None or modified output
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If ``True``, the provided ``hook`` will be fired
| before all existing ``forward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``forward`` hooks registered with
| :func:`register_module_forward_hook` will fire before all hooks
| registered by this method.
| Default: ``False``
| with_kwargs (bool): If ``True``, the ``hook`` will be passed the
| kwargs given to the forward function.
| Default: ``False``
| always_call (bool): If ``True`` the ``hook`` will be run regardless of
| whether an exception is raised while calling the Module.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_forward_pre_hook(self, hook: collections.abc.Callable[[~T, tuple[typing.Any, ...]], typing.Any | None] | collections.abc.Callable[[~T, tuple[typing.Any, ...], dict[str, typing.Any]], tuple[typing.Any, dict[str, typing.Any]] | None], *, prepend: bool = False, with_kwargs: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a forward pre-hook on the module.
|
| The hook will be called every time before :func:`forward` is invoked.
|
|
| If ``with_kwargs`` is false or not specified, the input contains only
| the positional arguments given to the module. Keyword arguments won't be
| passed to the hooks and only to the ``forward``. The hook can modify the
| input. User can either return a tuple or a single modified value in the
| hook. We will wrap the value into a tuple if a single value is returned
| (unless that value is already a tuple). The hook should have the
| following signature::
|
| hook(module, args) -> None or modified input
|
| If ``with_kwargs`` is true, the forward pre-hook will be passed the
| kwargs given to the forward function. And if the hook modifies the
| input, both the args and kwargs should be returned. The hook should have
| the following signature::
|
| hook(module, args, kwargs) -> None or a tuple of modified input and kwargs
|
| Args:
| hook (Callable): The user defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``forward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``forward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``forward_pre`` hooks registered with
| :func:`register_module_forward_pre_hook` will fire before all
| hooks registered by this method.
| Default: ``False``
| with_kwargs (bool): If true, the ``hook`` will be passed the kwargs
| given to the forward function.
| Default: ``False``
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor, tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward hook on the module.
|
| The hook will be called every time the gradients with respect to a module are computed, and its firing rules are as follows:
|
| 1. Ordinarily, the hook fires when the gradients are computed with respect to the module inputs.
| 2. If none of the module inputs require gradients, the hook will fire when the gradients are computed
| with respect to module outputs.
| 3. If none of the module outputs require gradients, then the hooks will not fire.
|
| The hook should have the following signature::
|
| hook(module, grad_input, grad_output) -> tuple(Tensor) or None
|
| The :attr:`grad_input` and :attr:`grad_output` are tuples that contain the gradients
| with respect to the inputs and outputs respectively. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the input that will be used in place of :attr:`grad_input` in
| subsequent computations. :attr:`grad_input` will only correspond to the inputs given
| as positional arguments and all kwarg arguments are ignored. Entries
| in :attr:`grad_input` and :attr:`grad_output` will be ``None`` for all non-Tensor
| arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs or outputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward`` hooks on
| this :class:`torch.nn.Module`. Note that global
| ``backward`` hooks registered with
| :func:`register_module_full_backward_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_full_backward_pre_hook(self, hook: collections.abc.Callable[['Module', tuple[torch.Tensor, ...] | torch.Tensor], tuple[torch.Tensor, ...] | torch.Tensor | None], prepend: bool = False) -> torch.utils.hooks.RemovableHandle
| Register a backward pre-hook on the module.
|
| The hook will be called every time the gradients for the module are computed.
| The hook should have the following signature::
|
| hook(module, grad_output) -> tuple[Tensor, ...], Tensor or None
|
| The :attr:`grad_output` is a tuple. The hook should
| not modify its arguments, but it can optionally return a new gradient with
| respect to the output that will be used in place of :attr:`grad_output` in
| subsequent computations. Entries in :attr:`grad_output` will be ``None`` for
| all non-Tensor arguments.
|
| For technical reasons, when this hook is applied to a Module, its forward function will
| receive a view of each Tensor passed to the Module. Similarly the caller will receive a view
| of each Tensor returned by the Module's forward function.
|
| .. warning ::
| Modifying inputs inplace is not allowed when using backward hooks and
| will raise an error.
|
| Args:
| hook (Callable): The user-defined hook to be registered.
| prepend (bool): If true, the provided ``hook`` will be fired before
| all existing ``backward_pre`` hooks on this
| :class:`torch.nn.Module`. Otherwise, the provided
| ``hook`` will be fired after all existing ``backward_pre`` hooks
| on this :class:`torch.nn.Module`. Note that global
| ``backward_pre`` hooks registered with
| :func:`register_module_full_backward_pre_hook` will fire before
| all hooks registered by this method.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_post_hook(self, hook)
| Register a post-hook to be run after module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, incompatible_keys) -> None
|
| The ``module`` argument is the current module that this hook is registered
| on, and the ``incompatible_keys`` argument is a ``NamedTuple`` consisting
| of attributes ``missing_keys`` and ``unexpected_keys``. ``missing_keys``
| is a ``list`` of ``str`` containing the missing keys and
| ``unexpected_keys`` is a ``list`` of ``str`` containing the unexpected keys.
|
| The given incompatible_keys can be modified inplace if needed.
|
| Note that the checks performed when calling :func:`load_state_dict` with
| ``strict=True`` are affected by modifications the hook makes to
| ``missing_keys`` or ``unexpected_keys``, as expected. Additions to either
| set of keys will result in an error being thrown when ``strict=True``, and
| clearing out both missing and unexpected keys will avoid an error.
|
| Returns:
| :class:`torch.utils.hooks.RemovableHandle`:
| a handle that can be used to remove the added hook by calling
| ``handle.remove()``
|
| register_load_state_dict_pre_hook(self, hook)
| Register a pre-hook to be run before module's :meth:`~nn.Module.load_state_dict` is called.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) -> None # noqa: B950
|
| Arguments:
| hook (Callable): Callable hook that will be invoked before
| loading the state dict.
|
| register_module(self, name: str, module: Optional[ForwardRef('Module')]) -> None
| Alias for :func:`add_module`.
|
| register_parameter(self, name: str, param: torch.nn.parameter.Parameter | None) -> None
| Add a parameter to the module.
|
| The parameter can be accessed as an attribute using given name.
|
| Args:
| name (str): name of the parameter. The parameter can be accessed
| from this module using the given name
| param (Parameter or None): parameter to be added to the module. If
| ``None``, then operations that run on parameters, such as :attr:`cuda`,
| are ignored. If ``None``, the parameter is **not** included in the
| module's :attr:`state_dict`.
|
| register_state_dict_post_hook(self, hook)
| Register a post-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, state_dict, prefix, local_metadata) -> None
|
| The registered hooks can modify the ``state_dict`` inplace.
|
| register_state_dict_pre_hook(self, hook)
| Register a pre-hook for the :meth:`~torch.nn.Module.state_dict` method.
|
| It should have the following signature::
| hook(module, prefix, keep_vars) -> None
|
| The registered hooks can be used to perform pre-processing before the ``state_dict``
| call is made.
|
| requires_grad_(self, requires_grad: bool = True) -> Self
| Change if autograd should record operations on parameters in this module.
|
| This method sets the parameters' :attr:`requires_grad` attributes
| in-place.
|
| This method is helpful for freezing part of the module for finetuning
| or training parts of a model individually (e.g., GAN training).
|
| See :ref:`locally-disable-grad-doc` for a comparison between
| `.requires_grad_()` and several similar mechanisms that may be confused with it.
|
| Args:
| requires_grad (bool): whether autograd should record operations on
| parameters in this module. Default: ``True``.
|
| Returns:
| Module: self
|
| set_extra_state(self, state: Any) -> None
| Set extra state contained in the loaded `state_dict`.
|
| This function is called from :func:`load_state_dict` to handle any extra state
| found within the `state_dict`. Implement this function and a corresponding
| :func:`get_extra_state` for your module if you need to store extra state within its
| `state_dict`.
|
| Args:
| state (dict): Extra state from the `state_dict`
|
| set_submodule(self, target: str, module: 'Module', strict: bool = False) -> None
| Set the submodule given by ``target`` if it exists, otherwise throw an error.
|
| .. note::
| If ``strict`` is set to ``False`` (default), the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``strict`` is set to ``True``,
| the method will only attempt to replace an existing submodule and throw an error if
| the submodule does not exist.
|
| For example, let's say you have an ``nn.Module`` ``A`` that
| looks like this:
|
| .. code-block:: text
|
| A(
| (net_b): Module(
| (net_c): Module(
| (conv): Conv2d(3, 3, 3)
| )
| (linear): Linear(3, 3)
| )
| )
|
| (The diagram shows an ``nn.Module`` ``A``. ``A`` has a nested
| submodule ``net_b``, which itself has two submodules ``net_c``
| and ``linear``. ``net_c`` then has a submodule ``conv``.)
|
| To override the ``Conv2d`` with a new submodule ``Linear``, you
| could call ``set_submodule("net_b.net_c.conv", nn.Linear(1, 1))``
| where ``strict`` could be ``True`` or ``False``
|
| To add a new submodule ``Conv2d`` to the existing ``net_b`` module,
| you would call ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1))``.
|
| In the above if you set ``strict=True`` and call
| ``set_submodule("net_b.conv", nn.Conv2d(1, 1, 1), strict=True)``, an AttributeError
| will be raised because ``net_b`` does not have a submodule named ``conv``.
|
| Args:
| target: The fully-qualified string name of the submodule
| to look for. (See above example for how to specify a
| fully-qualified string.)
| module: The module to set the submodule to.
| strict: If ``False``, the method will replace an existing submodule
| or create a new submodule if the parent module exists. If ``True``,
| the method will only attempt to replace an existing submodule and throw an error
| if the submodule doesn't already exist.
|
| Raises:
| ValueError: If the ``target`` string is empty or if ``module`` is not an instance of ``nn.Module``.
| AttributeError: If at any point along the path resulting from
| the ``target`` string the (sub)path resolves to a non-existent
| attribute name or an object that is not an instance of ``nn.Module``.
|
| share_memory(self) -> Self
| See :meth:`torch.Tensor.share_memory_`.
|
| state_dict(self, *args, destination=None, prefix='', keep_vars=False)
| Return a dictionary containing references to the whole state of the module.
|
| Both parameters and persistent buffers (e.g. running averages) are
| included. Keys are corresponding parameter and buffer names.
| Parameters and buffers set to ``None`` are not included.
|
| .. note::
| The returned object is a shallow copy. It contains references
| to the module's parameters and buffers.
|
| .. warning::
| Currently ``state_dict()`` also accepts positional arguments for
| ``destination``, ``prefix`` and ``keep_vars`` in order. However,
| this is being deprecated and keyword arguments will be enforced in
| future releases.
|
| .. warning::
| Please avoid the use of argument ``destination`` as it is not
| designed for end-users.
|
| Args:
| destination (dict, optional): If provided, the state of module will
| be updated into the dict and the same object is returned.
| Otherwise, an ``OrderedDict`` will be created and returned.
| Default: ``None``.
| prefix (str, optional): a prefix added to parameter and buffer
| names to compose the keys in state_dict. Default: ``''``.
| keep_vars (bool, optional): by default the :class:`~torch.Tensor` s
| returned in the state dict are detached from autograd. If it's
| set to ``True``, detaching will not be performed.
| Default: ``False``.
|
| Returns:
| dict:
| a dictionary containing a whole state of the module
|
| Example::
|
| >>> # xdoctest: +SKIP("undefined vars")
| >>> module.state_dict().keys()
| ['bias', 'weight']
|
| to(self, *args, **kwargs)
| Move and/or cast the parameters and buffers.
|
| This can be called as
|
| .. function:: to(device=None, dtype=None, non_blocking=False)
| :noindex:
|
| .. function:: to(dtype, non_blocking=False)
| :noindex:
|
| .. function:: to(tensor, non_blocking=False)
| :noindex:
|
| .. function:: to(memory_format=torch.channels_last)
| :noindex:
|
| Its signature is similar to :meth:`torch.Tensor.to`, but only accepts
| floating point or complex :attr:`dtype`\ s. In addition, this method will
| only cast the floating point or complex parameters and buffers to :attr:`dtype`
| (if given). The integral parameters and buffers will be moved
| :attr:`device`, if that is given, but with dtypes unchanged. When
| :attr:`non_blocking` is set, it tries to convert/move asynchronously
| with respect to the host if possible, e.g., moving CPU Tensors with
| pinned memory to CUDA devices.
|
| See below for examples.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| device (:class:`torch.device`): the desired device of the parameters
| and buffers in this module
| dtype (:class:`torch.dtype`): the desired floating point or complex dtype of
| the parameters and buffers in this module
| tensor (torch.Tensor): Tensor whose dtype and device are the desired
| dtype and device for all parameters and buffers in this module
| memory_format (:class:`torch.memory_format`): the desired memory
| format for 4D parameters and buffers in this module (keyword
| only argument)
|
| Returns:
| Module: self
|
| Examples::
|
| >>> # xdoctest: +IGNORE_WANT("non-deterministic")
| >>> linear = nn.Linear(2, 2)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]])
| >>> linear.to(torch.double)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1913, -0.3420],
| [-0.5113, -0.2325]], dtype=torch.float64)
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA1)
| >>> gpu1 = torch.device("cuda:1")
| >>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
| >>> cpu = torch.device("cpu")
| >>> linear.to(cpu)
| Linear(in_features=2, out_features=2, bias=True)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.1914, -0.3420],
| [-0.5112, -0.2324]], dtype=torch.float16)
|
| >>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
| >>> linear.weight
| Parameter containing:
| tensor([[ 0.3741+0.j, 0.2382+0.j],
| [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
| >>> linear(torch.ones(3, 2, dtype=torch.cdouble))
| tensor([[0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j],
| [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
|
| to_empty(self, *, device: str | torch.device | int | None, recurse: bool = True) -> Self
| Move the parameters and buffers to the specified device without copying storage.
|
| Args:
| device (:class:`torch.device`): The desired device of the parameters
| and buffers in this module.
| recurse (bool): Whether parameters and buffers of submodules should
| be recursively moved to the specified device.
|
| Returns:
| Module: self
|
| train(self, mode: bool = True) -> Self
| Set the module in training mode.
|
| This has an effect only on certain modules. See the documentation of
| particular modules for details of their behaviors in training/evaluation
| mode, i.e., whether they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
| etc.
|
| Args:
| mode (bool): whether to set training mode (``True``) or evaluation
| mode (``False``). Default: ``True``.
|
| Returns:
| Module: self
|
| type(self, dst_type: torch.dtype | str) -> Self
| Casts all parameters and buffers to :attr:`dst_type`.
|
| .. note::
| This method modifies the module in-place.
|
| Args:
| dst_type (type or string): the desired type
|
| Returns:
| Module: self
|
| xpu(self, device: int | torch.device | None = None) -> Self
| Move all model parameters and buffers to the XPU.
|
| This also makes associated parameters and buffers different objects. So
| it should be called before constructing optimizer if the module will
| live on XPU while being optimized.
|
| .. note::
| This method modifies the module in-place.
|
| Arguments:
| device (int, optional): if specified, all parameters will be
| copied to that device
|
| Returns:
| Module: self
|
| zero_grad(self, set_to_none: bool = True) -> None
| Reset gradients of all model parameters.
|
| See similar function under :class:`torch.optim.Optimizer` for more context.
|
| Args:
| set_to_none (bool): instead of setting to zero, set the grads to None.
| See :meth:`torch.optim.Optimizer.zero_grad` for details.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.nn.modules.module.Module:
|
| T_destination = ~T_destination
|
| call_super_init = False
|
| dump_patches = False
FUNCTIONS
add_quant_dequant(module)
Wrap the leaf child module in QuantWrapper if it has a valid qconfig
Note that this function will modify the children of module inplace and it
can return a new module which wraps the input module as well.
Args:
module: input module with qconfig attributes for all the leaf modules
that we want to quantize
Return:
Either the inplace modified module with submodules wrapped in
`QuantWrapper` based on qconfig or a new `QuantWrapper` module which
wraps the input module, the latter case only happens when the input
module is a leaf module and we want to quantize it.
convert(module, mapping=None, inplace=False, remove_qconfig=True, is_reference=False, convert_custom_config_dict=None, use_precomputed_fake_quant=False)
Converts submodules in input module to a different module according to `mapping`
by calling `from_float` method on the target module class. And remove qconfig at the
end if remove_qconfig is set to True.
Args:
`module`: prepared and calibrated module
`mapping`: a dictionary that maps from source module type to target
module type, can be overwritten to allow swapping user defined
Modules
`inplace`: carry out model transformations in-place, the original module
is mutated
`convert_custom_config_dict`: custom configuration dictionary for convert function
`use_precomputed_fake_quant`: a flag to enable use of precomputed fake quant
.. code-block:: python
# Example of convert_custom_config_dict:
convert_custom_config_dict = {
# user will manually define the corresponding quantized
# module class which has a from_observed class method that converts
# observed custom module to quantized custom module
"observed_to_quantized_custom_module_class": {
ObservedCustomModule: QuantizedCustomModule
}
}
default_eval_fn(model, calib_data)
Default evaluation function takes a torch.utils.data.Dataset or a list of
input Tensors and run the model on the dataset
fuse_modules(model, modules_to_fuse, inplace=False, fuser_func=<function fuse_known_modules at 0x00000199ED1876A0>, fuse_custom_config_dict=None)
Fuse a list of modules into a single module.
Fuses only the following sequence of modules:
conv, bn
conv, bn, relu
conv, relu
linear, relu
bn, relu
All other sequences are left unchanged.
For these sequences, replaces the first item in the list
with the fused module, replacing the rest of the modules
with identity.
Args:
model: Model containing the modules to be fused
modules_to_fuse: list of list of module names to fuse. Can also be a list
of strings if there is only a single list of modules to fuse.
inplace: bool specifying if fusion happens in place on the model, by default
a new model is returned
fuser_func: Function that takes in a list of modules and outputs a list of fused modules
of the same length. For example,
fuser_func([convModule, BNModule]) returns the list [ConvBNModule, nn.Identity()]
Defaults to torch.ao.quantization.fuse_known_modules
`fuse_custom_config_dict`: custom configuration for fusion
.. code-block:: python
# Example of fuse_custom_config_dict
fuse_custom_config_dict = {
# Additional fuser_method mapping
"additional_fuser_method_mapping": {
(torch.nn.Conv2d, torch.nn.BatchNorm2d): fuse_conv_bn
},
}
Returns:
model with fused modules. A new copy is created if inplace=True.
Examples::
>>> # xdoctest: +SKIP
>>> m = M().eval()
>>> # m is a module containing the sub-modules below
>>> modules_to_fuse = [ ['conv1', 'bn1', 'relu1'], ['submodule.conv', 'submodule.relu']]
>>> fused_m = torch.ao.quantization.fuse_modules(m, modules_to_fuse)
>>> output = fused_m(input)
>>> m = M().eval()
>>> # Alternately provide a single list of modules to fuse
>>> modules_to_fuse = ['conv1', 'bn1', 'relu1']
>>> fused_m = torch.ao.quantization.fuse_modules(m, modules_to_fuse)
>>> output = fused_m(input)
get_default_compare_output_module_list() -> set[collections.abc.Callable]
Get list of module class types that we will record output
in numeric suite
get_default_dynamic_quant_module_mappings() -> dict[collections.abc.Callable, typing.Any]
Get module mapping for post training dynamic quantization
get_default_qat_module_mappings() -> dict[collections.abc.Callable, typing.Any]
Get default module mapping for quantization aware training
get_default_qconfig_propagation_list() -> set[collections.abc.Callable]
Get the default list of module types that we'll attach qconfig
attribute to in prepare
get_default_static_quant_module_mappings() -> dict[collections.abc.Callable, typing.Any]
Get module mapping for post training static quantization
get_fuser_method(op_list, additional_fuser_method_mapping=None)
Get fuser method for the given list of module types.
Get fuser method for the given list of module types,
return None if fuser method does not exist
get_quantized_operator(float_op: collections.abc.Callable | str) -> collections.abc.Callable
Get the quantized operator corresponding to the float operator
get_static_quant_module_class(float_module_class: collections.abc.Callable, additional_static_quant_mapping: dict[collections.abc.Callable, typing.Any] | None = None, is_reference: bool = False) -> Any
n Get the statically quantized module class corresponding to
the floating point module class
prepare(model, inplace=False, allow_list=None, observer_non_leaf_module_list=None, prepare_custom_config_dict=None)
Prepares a copy of the model for quantization calibration or quantization-aware training.
Quantization configuration should be assigned preemptively
to individual submodules in `.qconfig` attribute.
The model will be attached with observer or fake quant modules, and qconfig
will be propagated.
Args:
`model`: input model to be modified in-place
`inplace`: carry out model transformations in-place, the original module is mutated
`allow_list`: list of quantizable modules
`observer_non_leaf_module_list`: list of non-leaf modules we want to add observer
`prepare_custom_config_dict`: customization configuration dictionary for prepare function
.. code-block:: python
# Example of prepare_custom_config_dict:
prepare_custom_config_dict = {
# user will manually define the corresponding observed
# module class which has a from_float class method that converts
# float custom module to observed custom module
"float_to_observed_custom_module_class": {CustomModule: ObservedCustomModule}
}
prepare_qat(model, mapping=None, inplace=False)
Prepares a copy of the model for quantization calibration or
quantization-aware training and converts it to quantized version.
Quantization configuration should be assigned preemptively
to individual submodules in `.qconfig` attribute.
Args:
model: input model to be modified in-place
mapping: dictionary that maps float modules to quantized modules to be
replaced.
inplace: carry out model transformations in-place, the original module
is mutated
propagate_qconfig_(module, qconfig_dict=None, prepare_custom_config_dict=None)
Propagate qconfig through the module hierarchy and assign `qconfig`
attribute on each leaf module
Args:
module: input module
qconfig_dict: dictionary that maps from name or type of submodule to
quantization configuration, qconfig applies to all submodules of a
given module unless qconfig for the submodules are specified (when
the submodule already has qconfig attribute)
prepare_custom_config_dict: dictionary for custom handling of modules
see docs for :func:`~torch.ao.quantization.prepare_fx`
Return:
None, module is modified inplace with qconfig attached
quantize(model, run_fn, run_args, mapping=None, inplace=False)
Quantize the input float model with post training static quantization.
First it will prepare the model for calibration, then it calls
`run_fn` which will run the calibration step, after that we will
convert the model to a quantized model.
Args:
model: input float model
run_fn: a calibration function for calibrating the prepared model
run_args: positional arguments for `run_fn`
inplace: carry out model transformations in-place, the original module is mutated
mapping: correspondence between original module types and quantized counterparts
Return:
Quantized model.
quantize_dynamic(model, qconfig_spec=None, dtype=torch.qint8, mapping=None, inplace=False)
Converts a float model to dynamic (i.e. weights-only) quantized model.
Replaces specified modules with dynamic weight-only quantized versions and output the quantized model.
For simplest usage provide `dtype` argument that can be float16 or qint8. Weight-only quantization
by default is performed for layers with large weights size - i.e. Linear and RNN variants.
Fine grained control is possible with `qconfig` and `mapping` that act similarly to `quantize()`.
If `qconfig` is provided, the `dtype` argument is ignored.
Args:
model: input model
qconfig_spec: Either:
- A dictionary that maps from name or type of submodule to quantization
configuration, qconfig applies to all submodules of a given
module unless qconfig for the submodules are specified (when the
submodule already has qconfig attribute). Entries in the dictionary
need to be QConfig instances.
- A set of types and/or submodule names to apply dynamic quantization to,
in which case the `dtype` argument is used to specify the bit-width
inplace: carry out model transformations in-place, the original module is mutated
mapping: maps type of a submodule to a type of corresponding dynamically quantized version
with which the submodule needs to be replaced
quantize_dynamic_jit(model, qconfig_dict, inplace=False, debug=False)
Quantize the input float TorchScript model with
post training dynamic quantization.
Currently only qint8 quantization of torch.nn.Linear is supported.
Args:
`model`: input float TorchScript model
`qconfig_dict`: qconfig_dict is a dictionary with names of sub modules as key and
qconfig for that module as value, please see detailed
descriptions in :func:`~torch.ao.quantization.quantize_jit`
`inplace`: carry out model transformations in-place, the original module is
mutated
`debug`: flag for producing a debug friendly model (preserve weight attribute)
Return:
Quantized TorchScript model.
Example:
```python
import torch
from torch.ao.quantization import per_channel_dynamic_qconfig
from torch.ao.quantization import quantize_dynamic_jit
ts_model = torch.jit.script(
float_model.eval()
) # or torch.jit.trace(float_model, input)
qconfig = get_default_qconfig("fbgemm")
def calibrate(model, data_loader):
model.eval()
with torch.no_grad():
for image, target in data_loader:
model(image)
quantized_model = quantize_dynamic_jit(
ts_model, {"": qconfig}, calibrate, [data_loader_test]
)
```
quantize_jit(model, qconfig_dict, run_fn, run_args, inplace=False, debug=False)
Quantize the input float TorchScript model with
post training static quantization.
First it will prepare the model for calibration, then it calls
`run_fn` which will run the calibration step, after that we will
convert the model to a quantized model.
Args:
`model`: input float TorchScript model
`qconfig_dict`: qconfig_dict is a dictionary with names of sub modules as key and
qconfig for that module as value, empty key means the qconfig will be applied
to whole model unless it's overwritten by more specific configurations, the
qconfig for each module is either found in the dictionary or fallback to
the qconfig of parent module.
Right now qconfig_dict is the only way to configure how the model is quantized,
and it is done in the granularity of module, that is, we only support one type
of qconfig for each torch.nn.Module, and the qconfig for sub module will
override the qconfig for parent module, empty string means global configuration.
`run_fn`: a calibration function for calibrating the prepared model
`run_args`: positional arguments for `run_fn`
`inplace`: carry out model transformations in-place, the original module is
mutated
`debug`: flag for producing a debug friendly model (preserve weight attribute)
Return:
Quantized TorchScript model.
Example:
```python
import torch
from torch.ao.quantization import get_default_qconfig
from torch.ao.quantization import quantize_jit
ts_model = torch.jit.script(
float_model.eval()
) # or torch.jit.trace(float_model, input)
qconfig = get_default_qconfig("fbgemm")
def calibrate(model, data_loader):
model.eval()
with torch.no_grad():
for image, target in data_loader:
model(image)
quantized_model = quantize_jit(
ts_model, {"": qconfig}, calibrate, [data_loader_test]
)
```
quantize_qat(model, run_fn, run_args, inplace=False)
Do quantization aware training and output a quantized model
Args:
model: input model
run_fn: a function for evaluating the prepared model, can be a
function that simply runs the prepared model or a training
loop
run_args: positional arguments for `run_fn`
Return:
Quantized model.
swap_module(mod, mapping, custom_module_class_mapping, use_precomputed_fake_quant=False)
Swaps the module if it has a quantized counterpart and it has an
`observer` attached.
Args:
mod: input module
mapping: a dictionary that maps from nn module to nnq module
Return:
The corresponding quantized module of `mod`
DATA
__all__ = ['QuantWrapper', 'QuantStub', 'DeQuantStub', 'quantize', 'qu...
default_dynamic_qconfig = QConfig(activation=functools.partial(<class ...
default_fake_quant = functools.partial(<class 'torch.ao.quantization.....
default_fixed_qparams_range_0to1_fake_quant = functools.partial(<class...
default_fixed_qparams_range_neg1to1_fake_quant = functools.partial(<cl...
default_histogram_fake_quant = functools.partial(<class 'torch.ao.quan...
default_observer = functools.partial(<class 'torch.ao.quantization.......
default_per_channel_weight_fake_quant = functools.partial(<class 'torc...
default_per_channel_weight_observer = functools.partial(<class 'torch....
default_qat_qconfig = QConfig(activation=functools.partial(<class 'tor...
default_qconfig = QConfig(activation=functools.partial(<class 'tor...r...
default_weight_fake_quant = functools.partial(<class 'torch.ao.quantiz...
default_weight_observer = functools.partial(<class 'torch.ao.quantizat...
float16_dynamic_qconfig = QConfig(activation=functools.partial(<class ...
float_qparams_weight_only_qconfig = QConfig(activation=<class 'torch.a...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\quantization\__init__.py
torch.quantize_per_channel
Python Library Documentation: built-in function quantize_per_channel in module torch
quantize_per_channel(...)
quantize_per_channel(input, scales, zero_points, axis, dtype) -> Tensor
Converts a float tensor to a per-channel quantized tensor with given scales and zero points.
Arguments:
input (Tensor): float tensor to quantize
scales (Tensor): float 1D tensor of scales to use, size should match ``input.size(axis)``
zero_points (int): integer 1D tensor of offset to use, size should match ``input.size(axis)``
axis (int): dimension on which apply per-channel quantization
dtype (:class:`torch.dtype`): the desired data type of returned tensor.
Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
Returns:
Tensor: A newly quantized tensor
Example::
>>> x = torch.tensor([[-1.0, 0.0], [1.0, 2.0]])
>>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8)
tensor([[-1., 0.],
[ 1., 2.]], size=(2, 2), dtype=torch.quint8,
quantization_scheme=torch.per_channel_affine,
scale=tensor([0.1000, 0.0100], dtype=torch.float64),
zero_point=tensor([10, 0]), axis=0)
>>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8).int_repr()
tensor([[ 0, 10],
[100, 200]], dtype=torch.uint8)
torch.quantize_per_tensor
Python Library Documentation: built-in function quantize_per_tensor in module torch
quantize_per_tensor(...)
quantize_per_tensor(input, scale, zero_point, dtype) -> Tensor
Converts a float tensor to a quantized tensor with given scale and zero point.
Arguments:
input (Tensor): float tensor or list of tensors to quantize
scale (float or Tensor): scale to apply in quantization formula
zero_point (int or Tensor): offset in integer value that maps to float zero
dtype (:class:`torch.dtype`): the desired data type of returned tensor.
Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
Returns:
Tensor: A newly quantized tensor or list of quantized tensors.
Example::
>>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8)
tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10)
>>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr()
tensor([ 0, 10, 20, 30], dtype=torch.uint8)
>>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])],
>>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8)
(tensor([-1., 0.], size=(2,), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10),
tensor([-2., 2.], size=(2,), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20))
>>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8)
tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)
torch.quantize_per_tensor_dynamic
Python Library Documentation: built-in function quantize_per_tensor_dynamic in module torch
quantize_per_tensor_dynamic(...)
quantize_per_tensor_dynamic(input, dtype, reduce_range) -> Tensor
Converts a float tensor to a quantized tensor with scale and zero_point calculated
dynamically based on the input.
Arguments:
input (Tensor): float tensor or list of tensors to quantize
dtype (:class:`torch.dtype`): the desired data type of returned tensor.
Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``
reduce_range (bool): a flag to indicate whether to reduce the range of quantized
data by 1 bit, it's required to avoid instruction overflow for some hardwares
Returns:
Tensor: A newly (dynamically) quantized tensor
Example::
>>> t = torch.quantize_per_tensor_dynamic(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.quint8, False)
>>> print(t)
tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.011764705882352941,
zero_point=85)
>>> t.int_repr()
tensor([ 0, 85, 170, 255], dtype=torch.uint8)
torch.quantized_batch_norm
Python Library Documentation: built-in function quantized_batch_norm in module torch
quantized_batch_norm(...)
quantized_batch_norm(input, weight=None, bias=None, mean, var, eps, output_scale, output_zero_point) -> Tensor
Applies batch normalization on a 4D (NCHW) quantized tensor.
.. math::
y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
Arguments:
input (Tensor): quantized tensor
weight (Tensor): float tensor that corresponds to the gamma, size C
bias (Tensor): float tensor that corresponds to the beta, size C
mean (Tensor): float mean value in batch normalization, size C
var (Tensor): float tensor for variance, size C
eps (float): a value added to the denominator for numerical stability.
output_scale (float): output quantized tensor scale
output_zero_point (int): output quantized tensor zero_point
Returns:
Tensor: A quantized tensor with batch normalization applied.
Example::
>>> qx = torch.quantize_per_tensor(torch.rand(2, 2, 2, 2), 1.5, 3, torch.quint8)
>>> torch.quantized_batch_norm(qx, torch.ones(2), torch.zeros(2), torch.rand(2), torch.rand(2), 0.00001, 0.2, 2)
tensor([[[[-0.2000, -0.2000],
[ 1.6000, -0.2000]],
[[-0.4000, -0.4000],
[-0.4000, 0.6000]]],
[[[-0.2000, -0.2000],
[-0.2000, -0.2000]],
[[ 0.6000, -0.4000],
[ 0.6000, -0.4000]]]], size=(2, 2, 2, 2), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=2)
torch.quantized_gru
Python Library Documentation: OpOverloadPacket object
quantized_gru = class OpOverloadPacket(typing.Generic)
| quantized_gru(qualified_op_name: str, op_name: str, op: collections.abc.Callable[~_P, ~_T], overload_names: list[str]) -> None
|
| # OpOverloadPacket class contains pointer to a base unresolved operator that doesn't correspond to a specific operator
| # You can obtain an OpOverload object through attribute query.
|
| Method resolution order:
| OpOverloadPacket
| typing.Generic
| builtins.object
|
| Methods defined here:
|
| __call__(self, /, *args: _P.args, **kwargs: _P.kwargs) -> ~_T
| Call self as a function.
|
| __deepcopy__(self, memo=None)
| # it's a no-op since OpOverloadPacket object is immutable and must be unique for a given op.
|
| __getattr__(self, key: str) -> torch._ops.OpOverload[~_P, ~_T]
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, qualified_op_name: str, op_name: str, op: collections.abc.Callable[~_P, ~_T], overload_names: list[str]) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self) -> collections.abc.Iterator[str]
|
| __repr__(self)
| Return repr(self).
|
| __str__(self)
| Return str(self).
|
| op_overloads(self)
|
| overloads(self)
| # TODO: use this to make a __dir__
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| op
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__file__': typing.ClassVar[str]}
|
| __orig_bases__ = (typing.Generic[~_P, ~_T],)
|
| __parameters__ = (~_P, ~_T)
|
| ----------------------------------------------------------------------
| Class methods inherited from typing.Generic:
|
| __class_getitem__(...)
| Parameterizes a generic class.
|
| At least, parameterizing a generic class is the *main* thing this
| method does. For example, for some generic class `Foo`, this is called
| when we do `Foo[int]` - there, with `cls=Foo` and `params=int`.
|
| However, note that this method is also called when defining generic
| classes in the first place with `class Foo[T]: ...`.
|
| __init_subclass__(...)
| Function to initialize subclasses.
torch.quantized_gru_cell
Python Library Documentation: built-in function quantized_gru_cell in module torch quantized_gru_cell(...)
torch.quantized_lstm
Python Library Documentation: OpOverloadPacket object
quantized_lstm = class OpOverloadPacket(typing.Generic)
| quantized_lstm(qualified_op_name: str, op_name: str, op: collections.abc.Callable[~_P, ~_T], overload_names: list[str]) -> None
|
| # OpOverloadPacket class contains pointer to a base unresolved operator that doesn't correspond to a specific operator
| # You can obtain an OpOverload object through attribute query.
|
| Method resolution order:
| OpOverloadPacket
| typing.Generic
| builtins.object
|
| Methods defined here:
|
| __call__(self, /, *args: _P.args, **kwargs: _P.kwargs) -> ~_T
| Call self as a function.
|
| __deepcopy__(self, memo=None)
| # it's a no-op since OpOverloadPacket object is immutable and must be unique for a given op.
|
| __getattr__(self, key: str) -> torch._ops.OpOverload[~_P, ~_T]
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, qualified_op_name: str, op_name: str, op: collections.abc.Callable[~_P, ~_T], overload_names: list[str]) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self) -> collections.abc.Iterator[str]
|
| __repr__(self)
| Return repr(self).
|
| __str__(self)
| Return str(self).
|
| op_overloads(self)
|
| overloads(self)
| # TODO: use this to make a __dir__
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| op
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__file__': typing.ClassVar[str]}
|
| __orig_bases__ = (typing.Generic[~_P, ~_T],)
|
| __parameters__ = (~_P, ~_T)
|
| ----------------------------------------------------------------------
| Class methods inherited from typing.Generic:
|
| __class_getitem__(...)
| Parameterizes a generic class.
|
| At least, parameterizing a generic class is the *main* thing this
| method does. For example, for some generic class `Foo`, this is called
| when we do `Foo[int]` - there, with `cls=Foo` and `params=int`.
|
| However, note that this method is also called when defining generic
| classes in the first place with `class Foo[T]: ...`.
|
| __init_subclass__(...)
| Function to initialize subclasses.
torch.quantized_lstm_cell
Python Library Documentation: built-in function quantized_lstm_cell in module torch quantized_lstm_cell(...)
torch.quantized_max_pool1d
Python Library Documentation: built-in function quantized_max_pool1d in module torch
quantized_max_pool1d(...)
quantized_max_pool1d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) -> Tensor
Applies a 1D max pooling over an input quantized tensor composed of several input planes.
Arguments:
input (Tensor): quantized tensor
kernel_size (list of int): the size of the sliding window
stride (``list of int``, optional): the stride of the sliding window
padding (``list of int``, optional): padding to be added on both sides, must be >= 0 and <= kernel_size / 2
dilation (``list of int``, optional): The stride between elements within a sliding window, must be > 0. Default 1
ceil_mode (bool, optional): If True, will use ceil instead of floor to compute the output shape.
Defaults to False.
Returns:
Tensor: A quantized tensor with max_pool1d applied.
Example::
>>> qx = torch.quantize_per_tensor(torch.rand(2, 2), 1.5, 3, torch.quint8)
>>> torch.quantized_max_pool1d(qx, [2])
tensor([[0.0000],
[1.5000]], size=(2, 1), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=1.5, zero_point=3)
torch.quantized_max_pool2d
Python Library Documentation: built-in function quantized_max_pool2d in module torch
quantized_max_pool2d(...)
quantized_max_pool2d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) -> Tensor
Applies a 2D max pooling over an input quantized tensor composed of several input planes.
Arguments:
input (Tensor): quantized tensor
kernel_size (``list of int``): the size of the sliding window
stride (``list of int``, optional): the stride of the sliding window
padding (``list of int``, optional): padding to be added on both sides, must be >= 0 and <= kernel_size / 2
dilation (``list of int``, optional): The stride between elements within a sliding window, must be > 0. Default 1
ceil_mode (bool, optional): If True, will use ceil instead of floor to compute the output shape.
Defaults to False.
Returns:
Tensor: A quantized tensor with max_pool2d applied.
Example::
>>> qx = torch.quantize_per_tensor(torch.rand(2, 2, 2, 2), 1.5, 3, torch.quint8)
>>> torch.quantized_max_pool2d(qx, [2,2])
tensor([[[[1.5000]],
[[1.5000]]],
[[[0.0000]],
[[0.0000]]]], size=(2, 2, 1, 1), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=1.5, zero_point=3)
torch.quantized_max_pool3d
Python Library Documentation: built-in function quantized_max_pool3d in module torch quantized_max_pool3d(...)
torch.quantized_rnn_relu_cell
Python Library Documentation: built-in function quantized_rnn_relu_cell in module torch quantized_rnn_relu_cell(...)
torch.quantized_rnn_tanh_cell
Python Library Documentation: built-in function quantized_rnn_tanh_cell in module torch quantized_rnn_tanh_cell(...)
torch.quasirandom
Python Library Documentation: module torch.quasirandom in torch
NAME
torch.quasirandom - # mypy: allow-untyped-defs
CLASSES
builtins.object
SobolEngine
class SobolEngine(builtins.object)
| SobolEngine(dimension, scramble=False, seed=None)
|
| The :class:`torch.quasirandom.SobolEngine` is an engine for generating
| (scrambled) Sobol sequences. Sobol sequences are an example of low
| discrepancy quasi-random sequences.
|
| This implementation of an engine for Sobol sequences is capable of
| sampling sequences up to a maximum dimension of 21201. It uses direction
| numbers from https://web.maths.unsw.edu.au/~fkuo/sobol/ obtained using the
| search criterion D(6) up to the dimension 21201. This is the recommended
| choice by the authors.
|
| References:
| - Art B. Owen. Scrambling Sobol and Niederreiter-Xing points.
| Journal of Complexity, 14(4):466-489, December 1998.
|
| - I. M. Sobol. The distribution of points in a cube and the accurate
| evaluation of integrals.
| Zh. Vychisl. Mat. i Mat. Phys., 7:784-802, 1967.
|
| Args:
| dimension (Int): The dimensionality of the sequence to be drawn
| scramble (bool, optional): Setting this to ``True`` will produce
| scrambled Sobol sequences. Scrambling is
| capable of producing better Sobol
| sequences. Default: ``False``.
| seed (Int, optional): This is the seed for the scrambling. The seed
| of the random number generator is set to this,
| if specified. Otherwise, it uses a random seed.
| Default: ``None``
|
| Examples::
|
| >>> # xdoctest: +SKIP("unseeded random state")
| >>> soboleng = torch.quasirandom.SobolEngine(dimension=5)
| >>> soboleng.draw(3)
| tensor([[0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
| [0.5000, 0.5000, 0.5000, 0.5000, 0.5000],
| [0.7500, 0.2500, 0.2500, 0.2500, 0.7500]])
|
| Methods defined here:
|
| __init__(self, dimension, scramble=False, seed=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| draw(self, n: int = 1, out: torch.Tensor | None = None, dtype: torch.dtype | None = None) -> torch.Tensor
| Function to draw a sequence of :attr:`n` points from a Sobol sequence.
| Note that the samples are dependent on the previous samples. The size
| of the result is :math:`(n, dimension)`.
|
| Args:
| n (Int, optional): The length of sequence of points to draw.
| Default: 1
| out (Tensor, optional): The output tensor
| dtype (:class:`torch.dtype`, optional): the desired data type of the
| returned tensor.
| Default: ``None``
|
| draw_base2(self, m: int, out: torch.Tensor | None = None, dtype: torch.dtype | None = None) -> torch.Tensor
| Function to draw a sequence of :attr:`2**m` points from a Sobol sequence.
| Note that the samples are dependent on the previous samples. The size
| of the result is :math:`(2**m, dimension)`.
|
| Args:
| m (Int): The (base2) exponent of the number of points to draw.
| out (Tensor, optional): The output tensor
| dtype (:class:`torch.dtype`, optional): the desired data type of the
| returned tensor.
| Default: ``None``
|
| fast_forward(self, n)
| Function to fast-forward the state of the ``SobolEngine`` by
| :attr:`n` steps. This is equivalent to drawing :attr:`n` samples
| without using the samples.
|
| Args:
| n (Int): The number of steps to fast-forward by.
|
| reset(self)
| Function to reset the ``SobolEngine`` to base state.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| MAXBIT = 30
|
| MAXDIM = 21201
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\quasirandom.py
torch.quint2x4
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.quint4x2
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.quint8
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.rad2deg
Python Library Documentation: built-in function rad2deg in module torch
rad2deg(...)
rad2deg(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with each of the elements of :attr:`input`
converted from angles in radians to degrees.
Args:
input (Tensor): the input tensor.
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([[3.142, -3.142], [6.283, -6.283], [1.570, -1.570]])
>>> torch.rad2deg(a)
tensor([[ 180.0233, -180.0233],
[ 359.9894, -359.9894],
[ 89.9544, -89.9544]])
torch.rad2deg_
Python Library Documentation: built-in function rad2deg_ in module torch rad2deg_(...)
torch.rand
Python Library Documentation: built-in function rand in module torch
rand(...)
rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
Returns a tensor filled with random numbers from a uniform distribution
on the interval :math:`[0, 1)`
The shape of the tensor is defined by the variable argument :attr:`size`.
Args:
size (int...): a sequence of integers defining the shape of the output tensor.
Can be a variable number of arguments or a collection like a list or tuple.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> torch.rand(4)
tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
>>> torch.rand(2, 3)
tensor([[ 0.8237, 0.5781, 0.6879],
[ 0.3816, 0.7249, 0.0998]])
torch.rand_like
Python Library Documentation: built-in function rand_like in module torch
rand_like(...)
rand_like(input, *, generator=None, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns a tensor with the same size as :attr:`input` that is filled with
random numbers from a uniform distribution on the interval :math:`[0, 1)`.
``torch.rand_like(input)`` is equivalent to
``torch.rand(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
torch.randint
Python Library Documentation: built-in function randint in module torch
randint(...)
randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a tensor filled with random integers generated uniformly
between :attr:`low` (inclusive) and :attr:`high` (exclusive).
The shape of the tensor is defined by the variable argument :attr:`size`.
.. note::
With the global dtype default (``torch.float32``), this function returns
a tensor with dtype ``torch.int64``.
Args:
low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
high (int): One above the highest integer to be drawn from the distribution.
size (tuple): a tuple defining the shape of the output tensor.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
this function returns a tensor with dtype ``torch.int64``.
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.randint(3, 5, (3,))
tensor([4, 3, 4])
>>> torch.randint(10, (2, 2))
tensor([[0, 2],
[5, 5]])
>>> torch.randint(3, 10, (2, 2))
tensor([[4, 5],
[6, 7]])
torch.randint_like
Python Library Documentation: built-in function randint_like in module torch
randint_like(...)
randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns a tensor with the same shape as Tensor :attr:`input` filled with
random integers generated uniformly between :attr:`low` (inclusive) and
:attr:`high` (exclusive).
.. note:
With the global dtype default (``torch.float32``), this function returns
a tensor with dtype ``torch.int64``.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
high (int): One above the highest integer to be drawn from the distribution.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
torch.randn
Python Library Documentation: built-in function randn in module torch
randn(...)
randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
Returns a tensor filled with random numbers from a normal distribution
with mean `0` and variance `1` (also called the standard normal
distribution).
.. math::
\text{out}_{i} \sim \mathcal{N}(0, 1)
For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
unit variance as
.. math::
\text{out}_{i} \sim \mathcal{CN}(0, 1)
This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
:math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
.. math::
\operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
\operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
The shape of the tensor is defined by the variable argument :attr:`size`.
Args:
size (int...): a sequence of integers defining the shape of the output tensor.
Can be a variable number of arguments or a collection like a list or tuple.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> torch.randn(4)
tensor([-2.1436, 0.9966, 2.3426, -0.6366])
>>> torch.randn(2, 3)
tensor([[ 1.5954, 2.8929, -1.0923],
[ 1.1719, -0.4709, -0.1996]])
.. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
torch.randn_like
Python Library Documentation: built-in function randn_like in module torch
randn_like(...)
randn_like(input, *, generator=None, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns a tensor with the same size as :attr:`input` that is filled with
random numbers from a normal distribution with mean 0 and variance 1. Please refer to :func:`torch.randn` for the
sampling process of complex dtypes. ``torch.randn_like(input)`` is equivalent to
``torch.randn(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
torch.random
Python Library Documentation: module torch.random in torch
NAME
torch.random - # mypy: allow-untyped-defs
FUNCTIONS
fork_rng(devices=None, enabled=True, _caller='fork_rng', _devices_kw='devices', device_type=None) -> collections.abc.Generator
Forks the RNG, so that when you return, the RNG is reset
to the state that it was previously in.
Args:
devices (iterable of Device IDs): devices for which to fork
the RNG. CPU RNG state is always forked. By default, :meth:`fork_rng` operates
on all devices, but will emit a warning if your machine has a lot
of devices, since this function will run very slowly in that case.
If you explicitly specify devices, this warning will be suppressed
enabled (bool): if ``False``, the RNG is not forked. This is a convenience
argument for easily disabling the context manager without having
to delete it and unindent your Python code under it.
device_type (str): device type str, default is ``None``, in which case the type
is taken from :func:`torch.accelerator.current_accelerator`, falling back
to ``"cuda"`` when the type cannot be determined. As for supported devices,
see details in :ref:`accelerator<accelerators>`
get_rng_state() -> torch.Tensor
Returns the random number generator state as a `torch.ByteTensor`.
.. note:: The returned state is for the default generator on CPU only.
See also: :func:`torch.random.fork_rng`.
initial_seed() -> int
Returns the initial seed for generating random numbers as a
Python `long`.
.. note:: The returned seed is for the default generator on CPU only.
manual_seed(seed) -> torch._C.Generator
Sets the seed for generating random numbers on all devices. Returns a
`torch.Generator` object.
Args:
seed (int): The desired seed. Value must be within the inclusive range
`[-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]`. Otherwise, a RuntimeError
is raised. Negative inputs are remapped to positive values with the formula
`0xffff_ffff_ffff_ffff + seed`.
seed() -> int
Sets the seed for generating random numbers to a non-deterministic
random number on all devices. Returns a 64 bit number used to seed the RNG.
set_rng_state(new_state: torch.Tensor) -> None
Sets the random number generator state.
.. note:: This function only works for CPU. For CUDA, please use
:func:`torch.manual_seed`, which works for both CPU and CUDA.
Args:
new_state (torch.ByteTensor): The desired state
thread_safe_generator() -> torch._C.Generator | None
Returns a thread-safe random number generator for use in DataLoader workers.
This function provides a convenient way for transforms and user code to use
thread-safe random number generation without manually checking worker context.
When called in a DataLoader thread worker, returns the worker's thread-local
:class:`torch.Generator`. When called in the main process or process workers,
returns ``None`` (which causes PyTorch functions to use the default global RNG).
Returns:
Optional[torch.Generator]: Thread-local generator in thread workers, None otherwise.
Example::
>>> from torch.random import thread_safe_generator
>>> generator = thread_safe_generator()
>>> torch.randint(0, 10, (5,), generator=generator)
Example with transforms::
>>> from torch.random import thread_safe_generator
>>> class MyRandomTransform:
... def __call__(self, img):
... generator = thread_safe_generator()
... offset = torch.randint(0, 10, (2,), generator=generator)
... return img[..., offset[0]:, offset[1]:]
DATA
__all__ = ['set_rng_state', 'get_rng_state', 'manual_seed', 'seed', 'i...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\random.py
torch.randperm
Python Library Documentation: built-in function randperm in module torch
randperm(...)
randperm(n, *, generator=None, out=None, dtype=torch.int64,layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
Returns a random permutation of integers from ``0`` to ``n - 1``.
Args:
n (int): the upper bound (exclusive)
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: ``torch.int64``.
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> torch.randperm(4)
tensor([2, 1, 0, 3])
torch.range
Python Library Documentation: built-in function range in module torch
range(...)
range(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a 1-D tensor of size :math:`\left\lfloor \frac{\text{end} - \text{start}}{\text{step}} \right\rfloor + 1`
with values from :attr:`start` to :attr:`end` with step :attr:`step`. Step is
the gap between two values in the tensor.
.. math::
\text{out}_{i+1} = \text{out}_i + \text{step}.
.. warning::
This function is deprecated and will be removed in a future release because its behavior is inconsistent with
Python's range builtin. Instead, use :func:`torch.arange`, which produces values in [start, end).
Args:
start (float, optional): the starting value for the set of points. Default: ``0``.
end (float): the ending value for the set of points
step (float, optional): the gap between each pair of adjacent points. Default: ``1``.
Keyword args:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). If `dtype` is not given, infer the data type from the other input
arguments. If any of `start`, `end`, or `step` are floating-point, the
`dtype` is inferred to be the default dtype, see
:meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
be `torch.int64`.
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.range(1, 4)
tensor([ 1., 2., 3., 4.])
>>> torch.range(1, 4, 0.5)
tensor([ 1.0000, 1.5000, 2.0000, 2.5000, 3.0000, 3.5000, 4.0000])
torch.ravel
Python Library Documentation: built-in function ravel in module torch
ravel(...)
ravel(input) -> Tensor
Return a contiguous flattened tensor. A copy is made only if needed.
Args:
input (Tensor): the input tensor.
Example::
>>> t = torch.tensor([[[1, 2],
... [3, 4]],
... [[5, 6],
... [7, 8]]])
>>> torch.ravel(t)
tensor([1, 2, 3, 4, 5, 6, 7, 8])
torch.real
Python Library Documentation: built-in function real in module torch
real(...)
real(input) -> Tensor
Returns a new tensor containing real values of the :attr:`self` tensor.
The returned tensor and :attr:`self` share the same underlying storage.
Args:
input (Tensor): the input tensor.
Example::
>>> x=torch.randn(4, dtype=torch.cfloat)
>>> x
tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
>>> x.real
tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
torch.reciprocal
Python Library Documentation: built-in function reciprocal in module torch
reciprocal(...)
reciprocal(input, *, out=None) -> Tensor
Returns a new tensor with the reciprocal of the elements of :attr:`input`
.. math::
\text{out}_{i} = \frac{1}{\text{input}_{i}}
.. note::
Unlike NumPy's reciprocal, torch.reciprocal supports integral inputs. Integral
inputs to reciprocal are automatically :ref:`promoted <type-promotion-doc>` to
the default scalar type.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-0.4595, -2.1219, -1.4314, 0.7298])
>>> torch.reciprocal(a)
tensor([-2.1763, -0.4713, -0.6986, 1.3702])
torch.reciprocal_
Python Library Documentation: built-in function reciprocal_ in module torch reciprocal_(...)
torch.relu
Python Library Documentation: built-in function relu in module torch relu(...)
torch.relu_
Python Library Documentation: built-in function relu_ in module torch
relu_(...)
relu_(input) -> Tensor
In-place version of :func:`~relu`.
torch.remainder
Python Library Documentation: built-in function remainder in module torch
remainder(...)
remainder(input, other, *, out=None) -> Tensor
Computes
`Python's modulus operation <https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations>`_
entrywise. The result has the same sign as the divisor :attr:`other` and its absolute value
is less than that of :attr:`other`.
It may also be defined in terms of :func:`torch.div` as
.. code:: python
torch.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
.. note::
Complex inputs are not supported. In some cases, it is not mathematically
possible to satisfy the definition of a modulo operation with complex numbers.
See :func:`torch.fmod` for how division by zero is handled.
.. seealso::
:func:`torch.fmod` which implements C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_.
This one is defined in terms of division rounding towards zero.
Args:
input (Tensor or Scalar): the dividend
other (Tensor or Scalar): the divisor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
tensor([ 1., 0., 1., 1., 0., 1.])
>>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), -1.5)
tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])
torch.renorm
Python Library Documentation: built-in function renorm in module torch
renorm(...)
renorm(input, p, dim, maxnorm, *, out=None) -> Tensor
Returns a tensor where each sub-tensor of :attr:`input` along dimension
:attr:`dim` is normalized such that the `p`-norm of the sub-tensor is lower
than the value :attr:`maxnorm`
.. note:: If the norm of a row is lower than `maxnorm`, the row is unchanged
Args:
input (Tensor): the input tensor.
p (float): the power for the norm computation
dim (int): the dimension to slice over to get the sub-tensors
maxnorm (float): the maximum norm to keep each sub-tensor under
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.ones(3, 3)
>>> x[1].fill_(2)
tensor([ 2., 2., 2.])
>>> x[2].fill_(3)
tensor([ 3., 3., 3.])
>>> x
tensor([[ 1., 1., 1.],
[ 2., 2., 2.],
[ 3., 3., 3.]])
>>> torch.renorm(x, 1, 0, 5)
tensor([[ 1.0000, 1.0000, 1.0000],
[ 1.6667, 1.6667, 1.6667],
[ 1.6667, 1.6667, 1.6667]])
torch.repeat_interleave
Python Library Documentation: built-in function repeat_interleave in module torch
repeat_interleave(...)
repeat_interleave(input, repeats, dim=None, *, output_size=None) -> Tensor
Repeat elements of a tensor.
.. warning::
This is different from :meth:`torch.Tensor.repeat` but similar to ``numpy.repeat``.
Args:
input (Tensor): the input tensor.
repeats (Tensor or int): The number of repetitions for each element.
repeats is broadcasted to fit the shape of the given axis.
dim (int, optional): The dimension along which to repeat values.
By default, use the flattened input array, and return a flat output
array.
Keyword args:
output_size (int, optional): Total output size for the given axis
( e.g. sum of repeats). If given, it will avoid stream synchronization
needed to calculate output shape of the tensor.
Returns:
Tensor: Repeated tensor which has the same shape as input, except along the given axis.
Example::
>>> x = torch.tensor([1, 2, 3])
>>> x.repeat_interleave(2)
tensor([1, 1, 2, 2, 3, 3])
>>> y = torch.tensor([[1, 2], [3, 4]])
>>> torch.repeat_interleave(y, 2)
tensor([1, 1, 2, 2, 3, 3, 4, 4])
>>> torch.repeat_interleave(y, 3, dim=1)
tensor([[1, 1, 1, 2, 2, 2],
[3, 3, 3, 4, 4, 4]])
>>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
tensor([[1, 2],
[3, 4],
[3, 4]])
>>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0, output_size=3)
tensor([[1, 2],
[3, 4],
[3, 4]])
If the `repeats` is `tensor([n1, n2, n3, ...])`, then the output will be
`tensor([0, 0, ..., 1, 1, ..., 2, 2, ..., ...])` where `0` appears `n1` times,
`1` appears `n2` times, `2` appears `n3` times, etc.
.. function:: repeat_interleave(repeats, *) -> Tensor
:noindex:
Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc.
Args:
repeats (Tensor): The number of repetitions for each element.
Returns:
Tensor: Repeated tensor of size `sum(repeats)`.
Example::
>>> torch.repeat_interleave(torch.tensor([1, 2, 3]))
tensor([0, 1, 1, 2, 2, 2])
torch.reshape
Python Library Documentation: built-in function reshape in module torch
reshape(...)
reshape(input, shape) -> Tensor
Returns a tensor with the same data and number of elements as :attr:`input`,
but with the specified shape. When possible, the returned tensor will be a view
of :attr:`input`. Otherwise, it will be a copy. Contiguous inputs and inputs
with compatible strides can be reshaped without copying, but you should not
depend on the copying vs. viewing behavior.
See :meth:`torch.Tensor.view` on when it is possible to return a view.
A single dimension may be -1, in which case it's inferred from the remaining
dimensions and the number of elements in :attr:`input`.
Args:
input (Tensor): the tensor to be reshaped
shape (tuple of int): the new shape
Example::
>>> a = torch.arange(4.)
>>> torch.reshape(a, (2, 2))
tensor([[ 0., 1.],
[ 2., 3.]])
>>> b = torch.tensor([[0, 1], [2, 3]])
>>> torch.reshape(b, (-1,))
tensor([ 0, 1, 2, 3])
torch.resize_as_
Python Library Documentation: built-in function resize_as_ in module torch resize_as_(...)
torch.resize_as_sparse_
Python Library Documentation: built-in function resize_as_sparse_ in module torch resize_as_sparse_(...)
torch.resolve_conj
Python Library Documentation: built-in function resolve_conj in module torch
resolve_conj(...)
resolve_conj(input) -> Tensor
Returns a new tensor with materialized conjugation if :attr:`input`'s conjugate bit is set to `True`,
else returns :attr:`input`. The output tensor will always have its conjugate bit set to `False`.
Args:
input (Tensor): the input tensor.
Example::
>>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
>>> y = x.conj()
>>> y.is_conj()
True
>>> z = y.resolve_conj()
>>> z
tensor([-1 - 1j, -2 - 2j, 3 + 3j])
>>> z.is_conj()
False
torch.resolve_neg
Python Library Documentation: built-in function resolve_neg in module torch
resolve_neg(...)
resolve_neg(input) -> Tensor
Returns a new tensor with materialized negation if :attr:`input`'s negative bit is set to `True`,
else returns :attr:`input`. The output tensor will always have its negative bit set to `False`.
Args:
input (Tensor): the input tensor.
Example::
>>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
>>> y = x.conj()
>>> z = y.imag
>>> z.is_neg()
True
>>> out = z.resolve_neg()
>>> out
tensor([-1., -2., 3.])
>>> out.is_neg()
False
torch.result_type
Python Library Documentation: built-in function result_type in module torch
result_type(...)
result_type(tensor1, tensor2) -> dtype
Returns the :class:`torch.dtype` that would result from performing an arithmetic
operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
for more information on the type promotion logic.
Args:
tensor1 (Tensor or Number): an input tensor or number
tensor2 (Tensor or Number): an input tensor or number
Example::
>>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
torch.float32
>>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
torch.uint8
torch.return_types
Python Library Documentation: module torch.return_types in torch
NAME
torch.return_types
CLASSES
builtins.tuple(builtins.object)
aminmax
aminmax_out
cummax
cummax_out
cummin
cummin_out
frexp
frexp_out
geqrf
geqrf_out
histogram
histogram_out
histogramdd
kthvalue
kthvalue_out
linalg_cholesky_ex
linalg_cholesky_ex_out
linalg_eig
linalg_eig_out
linalg_eigh
linalg_eigh_out
linalg_inv_ex
linalg_inv_ex_out
linalg_ldl_factor
linalg_ldl_factor_ex
linalg_ldl_factor_ex_out
linalg_ldl_factor_out
linalg_lstsq
linalg_lstsq_out
linalg_lu
linalg_lu_factor
linalg_lu_factor_ex
linalg_lu_factor_ex_out
linalg_lu_factor_out
linalg_lu_out
linalg_qr
linalg_qr_out
linalg_slogdet
linalg_slogdet_out
linalg_solve_ex
linalg_solve_ex_out
linalg_svd
linalg_svd_out
lu_unpack
lu_unpack_out
max
max_out
median
median_out
min
min_out
mode
mode_out
nanmedian
nanmedian_out
qr
qr_out
slogdet
slogdet_out
sort
sort_out
svd
svd_out
topk
topk_out
triangular_solve
triangular_solve_out
class aminmax(builtins.tuple)
| aminmax(iterable=(), /)
|
| Method resolution order:
| aminmax
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| max
|
| min
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('min', 'max')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class aminmax_out(builtins.tuple)
| aminmax_out(iterable=(), /)
|
| Method resolution order:
| aminmax_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| max
|
| min
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('min', 'max')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class cummax(builtins.tuple)
| cummax(iterable=(), /)
|
| Method resolution order:
| cummax
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class cummax_out(builtins.tuple)
| cummax_out(iterable=(), /)
|
| Method resolution order:
| cummax_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class cummin(builtins.tuple)
| cummin(iterable=(), /)
|
| Method resolution order:
| cummin
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class cummin_out(builtins.tuple)
| cummin_out(iterable=(), /)
|
| Method resolution order:
| cummin_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class frexp(builtins.tuple)
| frexp(iterable=(), /)
|
| Method resolution order:
| frexp
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| exponent
|
| mantissa
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('mantissa', 'exponent')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class frexp_out(builtins.tuple)
| frexp_out(iterable=(), /)
|
| Method resolution order:
| frexp_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| exponent
|
| mantissa
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('mantissa', 'exponent')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class geqrf(builtins.tuple)
| geqrf(iterable=(), /)
|
| Method resolution order:
| geqrf
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| a
|
| tau
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('a', 'tau')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class geqrf_out(builtins.tuple)
| geqrf_out(iterable=(), /)
|
| Method resolution order:
| geqrf_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| a
|
| tau
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('a', 'tau')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class histogram(builtins.tuple)
| histogram(iterable=(), /)
|
| Method resolution order:
| histogram
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| bin_edges
|
| hist
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('hist', 'bin_edges')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class histogram_out(builtins.tuple)
| histogram_out(iterable=(), /)
|
| Method resolution order:
| histogram_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| bin_edges
|
| hist
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('hist', 'bin_edges')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class histogramdd(builtins.tuple)
| histogramdd(iterable=(), /)
|
| Method resolution order:
| histogramdd
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| bin_edges
|
| hist
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('hist', 'bin_edges')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class kthvalue(builtins.tuple)
| kthvalue(iterable=(), /)
|
| Method resolution order:
| kthvalue
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class kthvalue_out(builtins.tuple)
| kthvalue_out(iterable=(), /)
|
| Method resolution order:
| kthvalue_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_cholesky_ex(builtins.tuple)
| linalg_cholesky_ex(iterable=(), /)
|
| Method resolution order:
| linalg_cholesky_ex
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| L
|
| info
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('L', 'info')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_cholesky_ex_out(builtins.tuple)
| linalg_cholesky_ex_out(iterable=(), /)
|
| Method resolution order:
| linalg_cholesky_ex_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| L
|
| info
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('L', 'info')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_eig(builtins.tuple)
| linalg_eig(iterable=(), /)
|
| Method resolution order:
| linalg_eig
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| eigenvalues
|
| eigenvectors
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('eigenvalues', 'eigenvectors')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_eig_out(builtins.tuple)
| linalg_eig_out(iterable=(), /)
|
| Method resolution order:
| linalg_eig_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| eigenvalues
|
| eigenvectors
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('eigenvalues', 'eigenvectors')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_eigh(builtins.tuple)
| linalg_eigh(iterable=(), /)
|
| Method resolution order:
| linalg_eigh
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| eigenvalues
|
| eigenvectors
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('eigenvalues', 'eigenvectors')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_eigh_out(builtins.tuple)
| linalg_eigh_out(iterable=(), /)
|
| Method resolution order:
| linalg_eigh_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| eigenvalues
|
| eigenvectors
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('eigenvalues', 'eigenvectors')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_inv_ex(builtins.tuple)
| linalg_inv_ex(iterable=(), /)
|
| Method resolution order:
| linalg_inv_ex
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| info
|
| inverse
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('inverse', 'info')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_inv_ex_out(builtins.tuple)
| linalg_inv_ex_out(iterable=(), /)
|
| Method resolution order:
| linalg_inv_ex_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| info
|
| inverse
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('inverse', 'info')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_ldl_factor(builtins.tuple)
| linalg_ldl_factor(iterable=(), /)
|
| Method resolution order:
| linalg_ldl_factor
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| LD
|
| pivots
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('LD', 'pivots')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_ldl_factor_ex(builtins.tuple)
| linalg_ldl_factor_ex(iterable=(), /)
|
| Method resolution order:
| linalg_ldl_factor_ex
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| LD
|
| info
|
| pivots
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('LD', 'pivots', 'info')
|
| n_fields = 3
|
| n_sequence_fields = 3
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_ldl_factor_ex_out(builtins.tuple)
| linalg_ldl_factor_ex_out(iterable=(), /)
|
| Method resolution order:
| linalg_ldl_factor_ex_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| LD
|
| info
|
| pivots
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('LD', 'pivots', 'info')
|
| n_fields = 3
|
| n_sequence_fields = 3
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_ldl_factor_out(builtins.tuple)
| linalg_ldl_factor_out(iterable=(), /)
|
| Method resolution order:
| linalg_ldl_factor_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| LD
|
| pivots
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('LD', 'pivots')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_lstsq(builtins.tuple)
| linalg_lstsq(iterable=(), /)
|
| Method resolution order:
| linalg_lstsq
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| rank
|
| residuals
|
| singular_values
|
| solution
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('solution', 'residuals', 'rank', 'singular_values')
|
| n_fields = 4
|
| n_sequence_fields = 4
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_lstsq_out(builtins.tuple)
| linalg_lstsq_out(iterable=(), /)
|
| Method resolution order:
| linalg_lstsq_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| rank
|
| residuals
|
| singular_values
|
| solution
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('solution', 'residuals', 'rank', 'singular_values')
|
| n_fields = 4
|
| n_sequence_fields = 4
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_lu(builtins.tuple)
| linalg_lu(iterable=(), /)
|
| Method resolution order:
| linalg_lu
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| L
|
| P
|
| U
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('P', 'L', 'U')
|
| n_fields = 3
|
| n_sequence_fields = 3
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_lu_factor(builtins.tuple)
| linalg_lu_factor(iterable=(), /)
|
| Method resolution order:
| linalg_lu_factor
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| LU
|
| pivots
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('LU', 'pivots')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_lu_factor_ex(builtins.tuple)
| linalg_lu_factor_ex(iterable=(), /)
|
| Method resolution order:
| linalg_lu_factor_ex
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| LU
|
| info
|
| pivots
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('LU', 'pivots', 'info')
|
| n_fields = 3
|
| n_sequence_fields = 3
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_lu_factor_ex_out(builtins.tuple)
| linalg_lu_factor_ex_out(iterable=(), /)
|
| Method resolution order:
| linalg_lu_factor_ex_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| LU
|
| info
|
| pivots
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('LU', 'pivots', 'info')
|
| n_fields = 3
|
| n_sequence_fields = 3
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_lu_factor_out(builtins.tuple)
| linalg_lu_factor_out(iterable=(), /)
|
| Method resolution order:
| linalg_lu_factor_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| LU
|
| pivots
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('LU', 'pivots')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_lu_out(builtins.tuple)
| linalg_lu_out(iterable=(), /)
|
| Method resolution order:
| linalg_lu_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| L
|
| P
|
| U
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('P', 'L', 'U')
|
| n_fields = 3
|
| n_sequence_fields = 3
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_qr(builtins.tuple)
| linalg_qr(iterable=(), /)
|
| Method resolution order:
| linalg_qr
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| Q
|
| R
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('Q', 'R')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_qr_out(builtins.tuple)
| linalg_qr_out(iterable=(), /)
|
| Method resolution order:
| linalg_qr_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| Q
|
| R
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('Q', 'R')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_slogdet(builtins.tuple)
| linalg_slogdet(iterable=(), /)
|
| Method resolution order:
| linalg_slogdet
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| logabsdet
|
| sign
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('sign', 'logabsdet')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_slogdet_out(builtins.tuple)
| linalg_slogdet_out(iterable=(), /)
|
| Method resolution order:
| linalg_slogdet_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| logabsdet
|
| sign
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('sign', 'logabsdet')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_solve_ex(builtins.tuple)
| linalg_solve_ex(iterable=(), /)
|
| Method resolution order:
| linalg_solve_ex
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| info
|
| result
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('result', 'info')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_solve_ex_out(builtins.tuple)
| linalg_solve_ex_out(iterable=(), /)
|
| Method resolution order:
| linalg_solve_ex_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| info
|
| result
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('result', 'info')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_svd(builtins.tuple)
| linalg_svd(iterable=(), /)
|
| Method resolution order:
| linalg_svd
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| S
|
| U
|
| Vh
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('U', 'S', 'Vh')
|
| n_fields = 3
|
| n_sequence_fields = 3
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class linalg_svd_out(builtins.tuple)
| linalg_svd_out(iterable=(), /)
|
| Method resolution order:
| linalg_svd_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| S
|
| U
|
| Vh
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('U', 'S', 'Vh')
|
| n_fields = 3
|
| n_sequence_fields = 3
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class lu_unpack(builtins.tuple)
| lu_unpack(iterable=(), /)
|
| Method resolution order:
| lu_unpack
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| L
|
| P
|
| U
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('P', 'L', 'U')
|
| n_fields = 3
|
| n_sequence_fields = 3
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class lu_unpack_out(builtins.tuple)
| lu_unpack_out(iterable=(), /)
|
| Method resolution order:
| lu_unpack_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| L
|
| P
|
| U
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('P', 'L', 'U')
|
| n_fields = 3
|
| n_sequence_fields = 3
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class max(builtins.tuple)
| max(iterable=(), /)
|
| Method resolution order:
| max
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class max_out(builtins.tuple)
| max_out(iterable=(), /)
|
| Method resolution order:
| max_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class median(builtins.tuple)
| median(iterable=(), /)
|
| Method resolution order:
| median
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class median_out(builtins.tuple)
| median_out(iterable=(), /)
|
| Method resolution order:
| median_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class min(builtins.tuple)
| min(iterable=(), /)
|
| Method resolution order:
| min
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class min_out(builtins.tuple)
| min_out(iterable=(), /)
|
| Method resolution order:
| min_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class mode(builtins.tuple)
| mode(iterable=(), /)
|
| Method resolution order:
| mode
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class mode_out(builtins.tuple)
| mode_out(iterable=(), /)
|
| Method resolution order:
| mode_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class nanmedian(builtins.tuple)
| nanmedian(iterable=(), /)
|
| Method resolution order:
| nanmedian
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class nanmedian_out(builtins.tuple)
| nanmedian_out(iterable=(), /)
|
| Method resolution order:
| nanmedian_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class qr(builtins.tuple)
| qr(iterable=(), /)
|
| Method resolution order:
| qr
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| Q
|
| R
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('Q', 'R')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class qr_out(builtins.tuple)
| qr_out(iterable=(), /)
|
| Method resolution order:
| qr_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| Q
|
| R
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('Q', 'R')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class slogdet(builtins.tuple)
| slogdet(iterable=(), /)
|
| Method resolution order:
| slogdet
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| logabsdet
|
| sign
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('sign', 'logabsdet')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class slogdet_out(builtins.tuple)
| slogdet_out(iterable=(), /)
|
| Method resolution order:
| slogdet_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| logabsdet
|
| sign
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('sign', 'logabsdet')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class sort(builtins.tuple)
| sort(iterable=(), /)
|
| Method resolution order:
| sort
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class sort_out(builtins.tuple)
| sort_out(iterable=(), /)
|
| Method resolution order:
| sort_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class svd(builtins.tuple)
| svd(iterable=(), /)
|
| Method resolution order:
| svd
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| S
|
| U
|
| V
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('U', 'S', 'V')
|
| n_fields = 3
|
| n_sequence_fields = 3
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class svd_out(builtins.tuple)
| svd_out(iterable=(), /)
|
| Method resolution order:
| svd_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| S
|
| U
|
| V
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('U', 'S', 'V')
|
| n_fields = 3
|
| n_sequence_fields = 3
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class topk(builtins.tuple)
| topk(iterable=(), /)
|
| Method resolution order:
| topk
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class topk_out(builtins.tuple)
| topk_out(iterable=(), /)
|
| Method resolution order:
| topk_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| indices
|
| values
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('values', 'indices')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class triangular_solve(builtins.tuple)
| triangular_solve(iterable=(), /)
|
| Method resolution order:
| triangular_solve
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| cloned_coefficient
|
| solution
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('solution', 'cloned_coefficient')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class triangular_solve_out(builtins.tuple)
| triangular_solve_out(iterable=(), /)
|
| Method resolution order:
| triangular_solve_out
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| cloned_coefficient
|
| solution
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('solution', 'cloned_coefficient')
|
| n_fields = 2
|
| n_sequence_fields = 2
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
FUNCTIONS
pytree_register_structseq(cls)
DATA
__all__ = ['pytree_register_structseq', 'all_return_types', 'aminmax',...
all_return_types = [<class 'torch.return_types.aminmax'>, <class 'torc...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\return_types.py
torch.rms_norm
Python Library Documentation: built-in function rms_norm in module torch rms_norm(...)
torch.rnn_relu
Python Library Documentation: built-in function rnn_relu in module torch rnn_relu(...)
torch.rnn_relu_cell
Python Library Documentation: built-in function rnn_relu_cell in module torch rnn_relu_cell(...)
torch.rnn_tanh
Python Library Documentation: built-in function rnn_tanh in module torch rnn_tanh(...)
torch.rnn_tanh_cell
Python Library Documentation: built-in function rnn_tanh_cell in module torch rnn_tanh_cell(...)
torch.roll
Python Library Documentation: built-in function roll in module torch
roll(...)
roll(input, shifts, dims=None) -> Tensor
Roll the tensor :attr:`input` along the given dimension(s). Elements that are
shifted beyond the last position are re-introduced at the first position. If
:attr:`dims` is `None`, the tensor will be flattened before rolling and then
restored to the original shape.
Args:
input (Tensor): the input tensor.
shifts (int or tuple of ints): The number of places by which the elements
of the tensor are shifted. If shifts is a tuple, dims must be a tuple of
the same size, and each dimension will be rolled by the corresponding
value
dims (int or tuple of ints): Axis along which to roll
Example::
>>> x = torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]).view(4, 2)
>>> x
tensor([[1, 2],
[3, 4],
[5, 6],
[7, 8]])
>>> torch.roll(x, 1)
tensor([[8, 1],
[2, 3],
[4, 5],
[6, 7]])
>>> torch.roll(x, 1, 0)
tensor([[7, 8],
[1, 2],
[3, 4],
[5, 6]])
>>> torch.roll(x, -1, 0)
tensor([[3, 4],
[5, 6],
[7, 8],
[1, 2]])
>>> torch.roll(x, shifts=(2, 1), dims=(0, 1))
tensor([[6, 5],
[8, 7],
[2, 1],
[4, 3]])
torch.rot90
Python Library Documentation: built-in function rot90 in module torch
rot90(...)
rot90(input, k=1, dims=(0, 1)) -> Tensor
Rotate an n-D tensor by 90 degrees in the plane specified by dims axis.
Rotation direction is from the first towards the second axis if k > 0, and from the second towards the first for k < 0.
Args:
input (Tensor): the input tensor.
k (int): number of times to rotate. Default value is 1
dims (a list or tuple): axis to rotate. Default value is [0, 1]
Example::
>>> x = torch.arange(4).view(2, 2)
>>> x
tensor([[0, 1],
[2, 3]])
>>> torch.rot90(x, 1, [0, 1])
tensor([[1, 3],
[0, 2]])
>>> x = torch.arange(8).view(2, 2, 2)
>>> x
tensor([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
>>> torch.rot90(x, 1, [1, 2])
tensor([[[1, 3],
[0, 2]],
[[5, 7],
[4, 6]]])
torch.round
Python Library Documentation: built-in function round in module torch
round(...)
round(input, *, decimals=0, out=None) -> Tensor
Rounds elements of :attr:`input` to the nearest integer.
For integer inputs, follows the array-api convention of returning a
copy of the input tensor.
The return type of output is same as that of input's dtype.
.. note::
This function implements the "round half to even" to
break ties when a number is equidistant from two
integers (e.g. `round(2.5)` is 2).
When the :attr:\`decimals\` argument is specified the
algorithm used is similar to NumPy's `around`. This
algorithm is fast but inexact and it can easily
overflow for low precision dtypes.
Eg. `round(tensor([10000], dtype=torch.float16), decimals=3)` is `inf`.
.. seealso::
:func:`torch.ceil`, which rounds up.
:func:`torch.floor`, which rounds down.
:func:`torch.trunc`, which rounds towards zero.
Args:
input (Tensor): the input tensor.
decimals (int): Number of decimal places to round to (default: 0).
If decimals is negative, it specifies the number of positions
to the left of the decimal point.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.round(torch.tensor((4.7, -2.3, 9.1, -7.7)))
tensor([ 5., -2., 9., -8.])
>>> # Values equidistant from two integers are rounded towards the
>>> # the nearest even value (zero is treated as even)
>>> torch.round(torch.tensor([-0.5, 0.5, 1.5, 2.5]))
tensor([-0., 0., 2., 2.])
>>> # A positive decimals argument rounds to the to that decimal place
>>> torch.round(torch.tensor([0.1234567]), decimals=3)
tensor([0.1230])
>>> # A negative decimals argument rounds to the left of the decimal
>>> torch.round(torch.tensor([1200.1234567]), decimals=-3)
tensor([1000.])
torch.round_
Python Library Documentation: built-in function round_ in module torch round_(...)
torch.row_indices_copy
Python Library Documentation: built-in function row_indices_copy in module torch row_indices_copy(...)
torch.row_stack
Python Library Documentation: built-in function row_stack in module torch
row_stack(...)
row_stack(tensors, *, out=None) -> Tensor
Alias of :func:`torch.vstack`.
torch.rrelu
Python Library Documentation: built-in function rrelu in module torch rrelu(...)
torch.rrelu_
Python Library Documentation: built-in function rrelu_ in module torch
rrelu_(...)
rrelu_(input, lower=1./8, upper=1./3, training=False) -> Tensor
In-place version of :func:`~rrelu`.
torch.rsqrt
Python Library Documentation: built-in function rsqrt in module torch
rsqrt(...)
rsqrt(input, *, out=None) -> Tensor
Returns a new tensor with the reciprocal of the square-root of each of
the elements of :attr:`input`.
.. math::
\text{out}_{i} = \frac{1}{\sqrt{\text{input}_{i}}}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-0.0370, 0.2970, 1.5420, -0.9105])
>>> torch.rsqrt(a)
tensor([ nan, 1.8351, 0.8053, nan])
torch.rsqrt_
Python Library Documentation: built-in function rsqrt_ in module torch rsqrt_(...)
torch.rsub
Python Library Documentation: built-in function rsub in module torch rsub(...)
torch.saddmm
Python Library Documentation: built-in function saddmm in module torch saddmm(...)
torch.save
Python Library Documentation: function save in module torch.serialization
save(obj: object, f: Union[str, os.PathLike[str], IO[bytes]], pickle_module: Any = <module 'pickle' from 'C:\\Users\\Youse\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\pickle.py'>, pickle_protocol: int = 2, _use_new_zipfile_serialization: bool = True, _disable_byteorder_record: bool = False) -> None
save(obj, f, pickle_module=pickle, pickle_protocol=2, _use_new_zipfile_serialization=True)
Saves an object to a disk file.
See also: :ref:`saving-loading-tensors`
See :ref:`layout-control` for more advanced tools to manipulate a checkpoint.
Args:
obj: saved object
f: a file-like object (has to implement write and flush) or a string or
os.PathLike object containing a file name
pickle_module: module used for pickling metadata and objects
pickle_protocol: can be specified to override the default protocol
.. note::
A common PyTorch convention is to save tensors using .pt file extension.
.. note::
PyTorch preserves storage sharing across serialization. See
:ref:`preserve-storage-sharing` for more details.
.. note::
The 1.6 release of PyTorch switched ``torch.save`` to use a new
zipfile-based file format. ``torch.load`` still retains the ability to
load files in the old format. If for any reason you want ``torch.save``
to use the old format, pass the kwarg ``_use_new_zipfile_serialization=False``.
Example:
>>> # xdoctest: +SKIP("makes cwd dirty")
>>> # Save to file
>>> x = torch.tensor([0, 1, 2, 3, 4])
>>> torch.save(x, "tensor.pt")
>>> # Save to io.BytesIO buffer
>>> buffer = io.BytesIO()
>>> torch.save(x, buffer)
torch.scalar_tensor
Python Library Documentation: built-in function scalar_tensor in module torch scalar_tensor(...)
torch.scatter
Python Library Documentation: built-in function scatter in module torch
scatter(...)
scatter(input, dim, index, src) -> Tensor
Out-of-place version of :meth:`torch.Tensor.scatter_`
torch.scatter_add
Python Library Documentation: built-in function scatter_add in module torch
scatter_add(...)
scatter_add(input, dim, index, src) -> Tensor
Out-of-place version of :meth:`torch.Tensor.scatter_add_`
torch.scatter_reduce
Python Library Documentation: built-in function scatter_reduce in module torch
scatter_reduce(...)
scatter_reduce(input, dim, index, src, reduce, *, include_self=True) -> Tensor
Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
torch.searchsorted
Python Library Documentation: built-in function searchsorted in module torch
searchsorted(...)
searchsorted(sorted_sequence, values, *, out_int32=False, right=False, side=None, out=None, sorter=None) -> Tensor
Find the indices from the *innermost* dimension of :attr:`sorted_sequence` such that, if the
corresponding values in :attr:`values` were inserted before the indices, when sorted, the order
of the corresponding *innermost* dimension within :attr:`sorted_sequence` would be preserved.
Return a new tensor with the same size as :attr:`values`. More formally,
the returned index satisfies the following rules:
.. list-table::
:widths: 12 10 78
:header-rows: 1
* - :attr:`sorted_sequence`
- :attr:`right`
- *returned index satisfies*
* - 1-D
- False
- ``sorted_sequence[i-1] < values[m][n]...[l][x] <= sorted_sequence[i]``
* - 1-D
- True
- ``sorted_sequence[i-1] <= values[m][n]...[l][x] < sorted_sequence[i]``
* - N-D
- False
- ``sorted_sequence[m][n]...[l][i-1] < values[m][n]...[l][x] <= sorted_sequence[m][n]...[l][i]``
* - N-D
- True
- ``sorted_sequence[m][n]...[l][i-1] <= values[m][n]...[l][x] < sorted_sequence[m][n]...[l][i]``
Args:
sorted_sequence (Tensor): N-D or 1-D tensor, containing monotonically increasing sequence on the *innermost*
dimension unless :attr:`sorter` is provided, in which case the sequence does not
need to be sorted
values (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
Keyword args:
out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
Default value is False, i.e. default output data type is torch.int64.
right (bool, optional): if False, return the first suitable location that is found. If True, return the
last such index. If no suitable index found, return 0 for non-numerical value
(eg. nan, inf) or the size of *innermost* dimension within :attr:`sorted_sequence`
(one pass the last index of the *innermost* dimension). In other words, if False,
gets the lower bound index for each value in :attr:`values` on the corresponding
*innermost* dimension of the :attr:`sorted_sequence`. If True, gets the upper
bound index instead. Default value is False. :attr:`side` does the same and is
preferred. It will error if :attr:`side` is set to "left" while this is True.
side (str, optional): the same as :attr:`right` but preferred. "left" corresponds to False for :attr:`right`
and "right" corresponds to True for :attr:`right`. It will error if this is set to
"left" while :attr:`right` is True. Default value is None.
out (Tensor, optional): the output tensor, must be the same size as :attr:`values` if provided.
sorter (LongTensor, optional): if provided, a tensor matching the shape of the unsorted
:attr:`sorted_sequence` containing a sequence of indices that sort it in the
ascending order on the innermost dimension
Example::
>>> sorted_sequence = torch.tensor([[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]])
>>> sorted_sequence
tensor([[ 1, 3, 5, 7, 9],
[ 2, 4, 6, 8, 10]])
>>> values = torch.tensor([[3, 6, 9], [3, 6, 9]])
>>> values
tensor([[3, 6, 9],
[3, 6, 9]])
>>> torch.searchsorted(sorted_sequence, values)
tensor([[1, 3, 4],
[1, 2, 4]])
>>> torch.searchsorted(sorted_sequence, values, side='right')
tensor([[2, 3, 5],
[1, 3, 4]])
>>> sorted_sequence_1d = torch.tensor([1, 3, 5, 7, 9])
>>> sorted_sequence_1d
tensor([1, 3, 5, 7, 9])
>>> torch.searchsorted(sorted_sequence_1d, values)
tensor([[1, 3, 4],
[1, 3, 4]])
torch.seed
Python Library Documentation: function seed in module torch.random
seed() -> int
Sets the seed for generating random numbers to a non-deterministic
random number on all devices. Returns a 64 bit number used to seed the RNG.
torch.segment_reduce
Python Library Documentation: built-in function segment_reduce in module torch
segment_reduce(...)
segment_reduce(data: Tensor, reduce: str, *, lengths: Tensor | None = None, indices: Tensor | None = None, offsets: Tensor | None = None, axis: _int = 0, unsafe: _bool = False, initial: Number | _complex | None = None) -> Tensor # noqa: B950
Perform a segment reduction operation on the input tensor along the specified axis.
Args:
data (Tensor): The input tensor on which the segment reduction operation will be performed.
reduce (str): The type of reduction operation. Supported values are ``sum``, ``mean``, ``max``, ``min``, ``prod``.
Keyword args:
lengths (Tensor, optional): Length of each segment. Default: ``None``.
offsets (Tensor, optional): Offset of each segment. Default: ``None``.
axis (int, optional): The axis perform reduction. Default: ``0``.
unsafe (bool, optional): Skip validation If `True`. Default: ``False``.
initial (Number, optional): The initial value for the reduction operation. Default: ``None``.
Example::
>>> data = torch.tensor([[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12]], dtype=torch.float32, device='cuda')
>>> lengths = torch.tensor([2, 1], device='cuda')
>>> torch.segment_reduce(data, 'max', lengths=lengths)
tensor([[ 5., 6., 7., 8.],
[ 9., 10., 11., 12.]], device='cuda:0')
torch.select
Python Library Documentation: built-in function select in module torch
select(...)
select(input, dim, index) -> Tensor
Slices the :attr:`input` tensor along the selected dimension at the given index.
This function returns a view of the original tensor with the given dimension removed.
.. note:: If :attr:`input` is a sparse tensor and returning a view of
the tensor is not possible, a RuntimeError exception is
raised. In this is the case, consider using
:func:`torch.select_copy` function.
Args:
input (Tensor): the input tensor.
dim (int): the dimension to slice
index (int): the index to select with
.. note::
:meth:`select` is equivalent to slicing. For example,
``tensor.select(0, index)`` is equivalent to ``tensor[index]`` and
``tensor.select(2, index)`` is equivalent to ``tensor[:,:,index]``.
torch.select_copy
Python Library Documentation: built-in function select_copy in module torch
select_copy(...)
Performs the same operation as :func:`torch.select`, but all output tensors
are freshly created instead of aliasing the input.
torch.select_scatter
Python Library Documentation: built-in function select_scatter in module torch
select_scatter(...)
select_scatter(input, src, dim, index) -> Tensor
Embeds the values of the :attr:`src` tensor into :attr:`input` at the given index.
This function returns a tensor with fresh storage; it does not create a view.
Args:
input (Tensor): the input tensor.
src (Tensor): The tensor to embed into :attr:`input`
dim (int): the dimension to insert the slice into.
index (int): the index to select with
.. note::
:attr:`src` must be of the proper size in order to be embedded
into :attr:`input`. Specifically, it should have the same shape as
``torch.select(input, dim, index)``
Example::
>>> a = torch.zeros(2, 2)
>>> b = torch.ones(2)
>>> a.select_scatter(b, 0, 0)
tensor([[1., 1.],
[0., 0.]])
torch.selu
Python Library Documentation: built-in function selu in module torch selu(...)
torch.selu_
Python Library Documentation: built-in function selu_ in module torch
selu_(...)
selu_(input) -> Tensor
In-place version of :func:`~selu`.
torch.serialization
Python Library Documentation: module torch.serialization in torch
NAME
torch.serialization - # mypy: allow-untyped-defs
CLASSES
builtins.Warning(builtins.Exception)
SourceChangeWarning
builtins.object
StorageType
set_default_mmap_options
skip_data
enum.Enum(builtins.object)
LoadEndianness
torch._weights_only_unpickler._safe_globals(builtins.object)
safe_globals
class LoadEndianness(enum.Enum)
| LoadEndianness(*values)
|
| Method resolution order:
| LoadEndianness
| enum.Enum
| builtins.object
|
| Data and other attributes defined here:
|
| BIG = <LoadEndianness.BIG: 3>
|
| LITTLE = <LoadEndianness.LITTLE: 2>
|
| NATIVE = <LoadEndianness.NATIVE: 1>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Static methods inherited from enum.EnumType:
|
| __contains__(value)
| Return True if `value` is in `cls`.
|
| `value` is in `cls` if:
| 1) `value` is a member of `cls`, or
| 2) `value` is the value of one of the `cls`'s members.
|
| __getitem__(name)
| Return the member matching `name`.
|
| __iter__()
| Return members in definition order.
|
| __len__()
| Return the number of members (no aliases)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class SourceChangeWarning(builtins.Warning)
| Method resolution order:
| SourceChangeWarning
| builtins.Warning
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Warning:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Warning:
|
| __new__(*args, **kwargs) class method of builtins.Warning
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class StorageType(builtins.object)
| StorageType(name)
|
| Methods defined here:
|
| __init__(self, name)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| dtype
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class safe_globals(torch._weights_only_unpickler._safe_globals)
| safe_globals(safe_globals: list[collections.abc.Callable | tuple[collections.abc.Callable, str]])
|
| Context-manager that adds certain globals as safe for ``weights_only`` load.
|
| Args:
| safe_globals: List of globals for weights_only load.
|
| Example:
| >>> # xdoctest: +SKIP("Can't torch.save(t, ...) as doctest thinks MyTensor is defined on torch.serialization")
| >>> import tempfile
| >>> class MyTensor(torch.Tensor):
| ... pass
| >>> t = MyTensor(torch.randn(2, 3))
| >>> with tempfile.NamedTemporaryFile() as f:
| ... torch.save(t, f.name)
| # Running `torch.load(f.name, weights_only=True)` will fail with
| # Unsupported global: GLOBAL __main__.MyTensor was not an allowed global by default.
| # Check the code and make sure MyTensor is safe to be used when loaded from an arbitrary checkpoint.
| ... with torch.serialization.safe_globals([MyTensor]):
| ... torch.load(f.name, weights_only=True)
| # MyTensor([[-0.5024, -1.8152, -0.5455],
| # [-0.8234, 2.0500, -0.3657]])
| >>> assert torch.serialization.get_safe_globals() == []
|
| Method resolution order:
| safe_globals
| torch._weights_only_unpickler._safe_globals
| builtins.object
|
| Methods inherited from torch._weights_only_unpickler._safe_globals:
|
| __enter__(self)
|
| __exit__(self, type, value, tb)
|
| __init__(self, safe_globals: list[collections.abc.Callable | tuple[collections.abc.Callable, str]])
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._weights_only_unpickler._safe_globals:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class set_default_mmap_options(builtins.object)
| set_default_mmap_options(flags: int) -> None
|
| Context manager or function to set default mmap options for :func:`torch.load` with ``mmap=True`` to flags.
|
| For now, only either ``mmap.MAP_PRIVATE`` or ``mmap.MAP_SHARED`` are supported.
| Please open an issue if you need any other option to be added here.
|
| .. note::
| This feature is currently not supported for Windows.
|
| Args:
| flags: ``mmap.MAP_PRIVATE`` or ``mmap.MAP_SHARED``
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None
|
| __init__(self, flags: int) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class skip_data(builtins.object)
| skip_data(materialize_fake_tensors: bool = False)
|
| Context-manager that skips writing/reading storage bytes for ``torch.save`` / ``torch.load`` calls.
|
| For the save path, storages will still be saved, but the space that their bytes would usually be written to
| will be empty space. The storage bytes can then be populated in a separate pass.
|
| For the load path, tensors will be loaded per the checkpoint but their storages will not be populated with data.
|
| .. warning::
| The ``skip_data`` context manager is an early prototype and is subject to change.
|
| Args:
| materialize_fake_tensors: Whether to materialize FakeTensors during save. This is a no-op for the load path.
|
| Example:
| >>> # xdoctest: +SKIP("NamedTemporaryFile on Windows")
| >>> import tempfile
| >>> t = torch.randn(2, 3)
| >>> with tempfile.NamedTemporaryFile() as f:
| ... with torch.serialization.skip_data():
| ... torch.save(t, f.name)
| ... torch.load(f.name, weights_only=True)
| tensor([[0., 0., 0.],
| [0., 0., 0.]])
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, type, value, tb)
|
| __init__(self, materialize_fake_tensors: bool = False)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
add_safe_globals(safe_globals: list[collections.abc.Callable | tuple[collections.abc.Callable, str]]) -> None
Marks the given globals as safe for ``weights_only`` load. For example, functions
added to this list can be called during unpickling, classes could be instantiated
and have state set.
Each item in the list can either be a function/class or a tuple of the form
(function/class, string) where string is the full path of the function/class.
Within the serialized format, each function is identified with its full
path as ``{__module__}.{__qualname__}``. When calling this API, you can provide this
full path that should match the one in the checkpoint otherwise the default
``{fn.__module__}.{fn.__qualname__}`` will be used.
Args:
safe_globals (List[Union[Callable, Tuple[Callable, str]]]): list of globals to mark as safe
Example:
>>> # xdoctest: +SKIP("Can't torch.save(t, ...) as doctest thinks MyTensor is defined on torch.serialization")
>>> import tempfile
>>> class MyTensor(torch.Tensor):
... pass
>>> t = MyTensor(torch.randn(2, 3))
>>> with tempfile.NamedTemporaryFile() as f:
... torch.save(t, f.name)
# Running `torch.load(f.name, weights_only=True)` will fail with
# Unsupported global: GLOBAL __main__.MyTensor was not an allowed global by default.
# Check the code and make sure MyTensor is safe to be used when loaded from an arbitrary checkpoint.
... torch.serialization.add_safe_globals([MyTensor])
... torch.load(f.name, weights_only=True)
# MyTensor([[-0.5024, -1.8152, -0.5455],
# [-0.8234, 2.0500, -0.3657]])
check_module_version_greater_or_equal(module, req_version_tuple, error_if_malformed=True)
Check if a module's version satisfies requirements
Usually, a module's version string will be like 'x.y.z', which would be represented
as a tuple (x, y, z), but sometimes it could be an unexpected format. If the version
string does not match the given tuple's format up to the length of the tuple, then
error and exit or emit a warning.
Args:
module: the module to check the version of
req_version_tuple: tuple (usually of ints) representing the required version
error_if_malformed: whether we should exit if module version string is malformed
Returns:
requirement_is_met: bool
clear_safe_globals() -> None
Clears the list of globals that are safe for ``weights_only`` load.
default_restore_location(storage, location)
Restores `storage` using a deserializer function registered for the `location`.
This function looks in the registry for deserializer functions that match the `location`.
If found, it attempts to use them, in priority order, to restore `storage` until one
returns a not `None` result. If no deserializer can be found in the registry, or all found fail
to bear a result, it raises a `RuntimeError`.
Args:
storage (STORAGE): the storage object to restore
location (str): the location tag associated with the storage object
Returns:
storage: Optional[STORAGE]
Raises:
RuntimeError: If no deserializer matching `location` is found in the registry or if
all matching ones return `None`.
get_crc32_options() -> bool
Get whether :func:`torch.save` computes and writes crc32 for each record.
Defaults to ``True``.
get_default_load_endianness() -> torch.serialization.LoadEndianness | None
Get fallback byte order for loading files
If byteorder mark is not present in saved checkpoint,
this byte order is used as fallback.
By default, it's "native" byte order.
Returns:
default_load_endian: Optional[LoadEndianness]
get_default_mmap_options() -> int | None
Get default mmap options for :func:`torch.load` with ``mmap=True``.
Defaults to ``mmap.MAP_PRIVATE``.
Returns:
default_mmap_options: int
get_safe_globals() -> list[collections.abc.Callable | tuple[collections.abc.Callable, str]]
Returns the list of user-added globals that are safe for ``weights_only`` load.
get_unsafe_globals_in_checkpoint(f: Union[str, os.PathLike[str], IO[bytes]]) -> list[str]
Returns a list of strings of functions/classes in a ``torch.save`` object that are not safe for ``weights_only``.
For a given function or class ``f``, the corresponding string will be of the form
``{f.__module__}.{f.__name__}``.
This function will return any GLOBALs in the checkpoint that are not in the set marked safe
for ``weights_only`` (either via :func:`add_safe_globals` or :class:`safe_globals` context or
allowlisted by ``torch`` by default).
.. note::
This function will statically disassemble the pickle file in the checkpoint.
The implication is any classes dynamically pushed onto the stack during unpickling
will not be included in the output.
Args:
f: File-like object or string containing the checkpoint object saved via ``torch.save``
Returns:
A list of strings of pickle GLOBALs in the checkpoint that are not allowlisted for ``weights_only``.
load(f: Union[str, os.PathLike[str], IO[bytes]], map_location: collections.abc.Callable[[torch.types.Storage, str], torch.types.Storage] | torch.device | str | dict[str, str] | None = None, pickle_module: Any = None, *, weights_only: bool | None = None, mmap: bool | None = None, **pickle_load_args: Any) -> Any
load(f, map_location=None, pickle_module=pickle, *, weights_only=True, mmap=None, **pickle_load_args)
Loads an object saved with :func:`torch.save` from a file.
.. warning::
:func:`torch.load()` uses an unpickler under the hood. **Never load data from an untrusted source.**
See :ref:`weights-only-security` for more details.
:func:`torch.load` uses Python's unpickling facilities but treats storages,
which underlie tensors, specially. They are first deserialized on the
CPU and are then moved to the device they were saved from. If this fails
(e.g. because the run time system doesn't have certain devices), an exception
is raised. However, storages can be dynamically remapped to an alternative
set of devices using the :attr:`map_location` argument.
If :attr:`map_location` is a callable, it will be called once for each serialized
storage with two arguments: storage and location. The storage argument
will be the initial deserialization of the storage, residing on the CPU.
Each serialized storage has a location tag associated with it which
identifies the device it was saved from, and this tag is the second
argument passed to :attr:`map_location`. The builtin location tags are ``'cpu'``
for CPU tensors and ``'cuda:device_id'`` (e.g. ``'cuda:2'``) for CUDA tensors.
:attr:`map_location` should return either ``None`` or a storage. If
:attr:`map_location` returns a storage, it will be used as the final deserialized
object, already moved to the right device. Otherwise, :func:`torch.load` will
fall back to the default behavior, as if :attr:`map_location` wasn't specified.
If :attr:`map_location` is a :class:`torch.device` object or a string containing
a device tag, it indicates the location where all tensors should be loaded.
Otherwise, if :attr:`map_location` is a dict, it will be used to remap location tags
appearing in the file (keys), to ones that specify where to put the
storages (values).
User extensions can register their own location tags and tagging and
deserialization methods using :func:`torch.serialization.register_package`.
See :ref:`layout-control` for more advanced tools to manipulate a checkpoint.
Args:
f: a file-like object (has to implement :meth:`read`, :meth:`readline`, :meth:`tell`, and :meth:`seek`),
or a string or os.PathLike object containing a file name
map_location: a function, :class:`torch.device`, string or a dict specifying how to remap storage
locations
pickle_module: module used for unpickling metadata and objects (has to
match the :attr:`pickle_module` used to serialize file)
weights_only: Indicates whether unpickler should be restricted to
loading only tensors, primitive types, dictionaries
and any types added via :func:`torch.serialization.add_safe_globals`.
See :ref:`weights-only` for more details.
mmap: Indicates whether the file should be mapped rather than loading all the storages into memory.
Typically, tensor storages in the file will first be moved from disk to CPU memory, after which they
are moved to the location that they were tagged with when saving, or specified by ``map_location``. This
second step is a no-op if the final location is CPU. When the ``mmap`` flag is set, instead of copying the
tensor storages from disk to CPU memory in the first step, ``f`` is mapped, which means tensor storages
will be lazily loaded when their data is accessed.
pickle_load_args: optional keyword arguments passed over to
:func:`pickle_module.load` and :func:`pickle_module.Unpickler`,
only works if :attr:`weights_only=False`, e.g., :attr:`errors=...`.
.. note::
When you call :func:`torch.load()` on a file which contains GPU tensors, those tensors
will be loaded to GPU by default. You can call ``torch.load(.., map_location='cpu')``
and then :meth:`load_state_dict` to avoid GPU RAM surge when loading a model checkpoint.
.. note::
By default, we decode byte strings as ``utf-8``. This is to avoid a common error
case ``UnicodeDecodeError: 'ascii' codec can't decode byte 0x...``
when loading files saved by Python 2 in Python 3. If this default
is incorrect, you may use an extra :attr:`encoding` keyword argument to specify how
these objects should be loaded, e.g., :attr:`encoding='latin1'` decodes them
to strings using ``latin1`` encoding, and :attr:`encoding='bytes'` keeps them
as byte arrays which can be decoded later with ``byte_array.decode(...)``.
Example:
>>> # xdoctest: +SKIP("undefined filepaths")
>>> torch.load("tensors.pt", weights_only=True)
# Load all tensors onto the CPU
>>> torch.load(
... "tensors.pt",
... map_location=torch.device("cpu"),
... weights_only=True,
... )
# Load all tensors onto the CPU, using a function
>>> torch.load(
... "tensors.pt",
... map_location=lambda storage, loc: storage,
... weights_only=True,
... )
# Load all tensors onto GPU 1
>>> torch.load(
... "tensors.pt",
... map_location=lambda storage, loc: storage.cuda(1), # type: ignore[attr-defined]
... weights_only=True,
... ) # type: ignore[attr-defined]
# Map tensors from GPU 1 to GPU 0
>>> torch.load(
... "tensors.pt",
... map_location={"cuda:1": "cuda:0"},
... weights_only=True,
... )
# Load tensor from io.BytesIO object
# Loading from a buffer setting weights_only=False, warning this can be unsafe
>>> with open("tensor.pt", "rb") as f:
... buffer = io.BytesIO(f.read())
>>> torch.load(buffer, weights_only=False)
# Load a module with 'ascii' encoding for unpickling
# Loading from a module setting weights_only=False, warning this can be unsafe
>>> torch.load("module.pt", encoding="ascii", weights_only=False)
location_tag(storage: torch.types.Storage | torch.storage.TypedStorage | torch.storage.UntypedStorage)
mkdtemp()
normalize_storage_type(storage_type)
register_package(priority: int, tagger: collections.abc.Callable[[torch.types.Storage | torch.storage.TypedStorage | torch.storage.UntypedStorage], str | None], deserializer: collections.abc.Callable[[torch.types.Storage | torch.storage.TypedStorage | torch.storage.UntypedStorage, str], torch.types.Storage | torch.storage.TypedStorage | torch.storage.UntypedStorage | None])
Registers callables for tagging and deserializing storage objects with an associated priority.
Tagging associates a device with a storage object at save time while deserializing moves a
storage object to an appropriate device at load time. :attr:`tagger` and :attr:`deserializer`
are run in the order given by their :attr:`priority` until a tagger/deserializer returns a
value that is not `None`.
To override the deserialization behavior for a device in the global registry, one can register a
tagger with a higher priority than the existing tagger.
This function can also be used to register a tagger and deserializer for new devices.
Args:
priority: Indicates the priority associated with the tagger and deserializer, where a lower
value indicates higher priority.
tagger: Callable that takes in a storage object and returns its tagged device as a string
or None.
deserializer: Callable that takes in storage object and a device string and returns a storage
object on the appropriate device or None.
Returns:
`None`
Example:
>>> def ipu_tag(obj):
>>> if obj.device.type == 'ipu':
>>> return 'ipu'
>>> def ipu_deserialize(obj, location):
>>> if location.startswith('ipu'):
>>> ipu = getattr(torch, "ipu", None)
>>> assert ipu is not None, "IPU device module is not loaded"
>>> assert torch.ipu.is_available(), "ipu is not available"
>>> return obj.ipu(location)
>>> torch.serialization.register_package(11, ipu_tag, ipu_deserialize)
save(obj: object, f: Union[str, os.PathLike[str], IO[bytes]], pickle_module: Any = <module 'pickle' from 'C:\\Users\\Youse\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\pickle.py'>, pickle_protocol: int = 2, _use_new_zipfile_serialization: bool = True, _disable_byteorder_record: bool = False) -> None
save(obj, f, pickle_module=pickle, pickle_protocol=2, _use_new_zipfile_serialization=True)
Saves an object to a disk file.
See also: :ref:`saving-loading-tensors`
See :ref:`layout-control` for more advanced tools to manipulate a checkpoint.
Args:
obj: saved object
f: a file-like object (has to implement write and flush) or a string or
os.PathLike object containing a file name
pickle_module: module used for pickling metadata and objects
pickle_protocol: can be specified to override the default protocol
.. note::
A common PyTorch convention is to save tensors using .pt file extension.
.. note::
PyTorch preserves storage sharing across serialization. See
:ref:`preserve-storage-sharing` for more details.
.. note::
The 1.6 release of PyTorch switched ``torch.save`` to use a new
zipfile-based file format. ``torch.load`` still retains the ability to
load files in the old format. If for any reason you want ``torch.save``
to use the old format, pass the kwarg ``_use_new_zipfile_serialization=False``.
Example:
>>> # xdoctest: +SKIP("makes cwd dirty")
>>> # Save to file
>>> x = torch.tensor([0, 1, 2, 3, 4])
>>> torch.save(x, "tensor.pt")
>>> # Save to io.BytesIO buffer
>>> buffer = io.BytesIO()
>>> torch.save(x, buffer)
set_crc32_options(compute_crc32: bool)
Set whether :func:`torch.save` computes and writes crc32 for each record.
.. note::
Setting this to ``False`` may make unzipping of the ``torch.save`` output
fail or warn due to corrupted CRC32. However ``torch.load`` will be
able to load the file.
Args:
compute_crc32 (bool): set crc32 computation flag
set_default_load_endianness(endianness)
Set fallback byte order for loading files
If byteorder mark is not present in saved checkpoint,
this byte order is used as fallback.
By default, it's "native" byte order.
Args:
endianness: the new fallback byte order
storage_to_tensor_type(storage)
validate_cuda_device(location)
validate_hpu_device(location)
DATA
__all__ = ['SourceChangeWarning', 'mkdtemp', 'register_package', 'chec...
__annotations__ = {'MAP_LOCATION': typing.TypeAlias, 'STORAGE': typing...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\serialization.py
torch.set_anomaly_enabled
Python Library Documentation: built-in function set_anomaly_enabled in module torch set_anomaly_enabled(...)
torch.set_autocast_cache_enabled
Python Library Documentation: built-in function set_autocast_cache_enabled in module torch set_autocast_cache_enabled(...)
torch.set_autocast_cpu_dtype
Python Library Documentation: built-in function set_autocast_cpu_dtype in module torch set_autocast_cpu_dtype(...)
torch.set_autocast_cpu_enabled
Python Library Documentation: built-in function set_autocast_cpu_enabled in module torch set_autocast_cpu_enabled(...)
torch.set_autocast_dtype
Python Library Documentation: built-in function set_autocast_dtype in module torch set_autocast_dtype(...)
torch.set_autocast_enabled
Python Library Documentation: built-in function set_autocast_enabled in module torch set_autocast_enabled(...)
torch.set_autocast_gpu_dtype
Python Library Documentation: built-in function set_autocast_gpu_dtype in module torch set_autocast_gpu_dtype(...)
torch.set_autocast_ipu_dtype
Python Library Documentation: built-in function set_autocast_ipu_dtype in module torch set_autocast_ipu_dtype(...)
torch.set_autocast_ipu_enabled
Python Library Documentation: built-in function set_autocast_ipu_enabled in module torch set_autocast_ipu_enabled(...)
torch.set_autocast_xla_dtype
Python Library Documentation: built-in function set_autocast_xla_dtype in module torch set_autocast_xla_dtype(...)
torch.set_autocast_xla_enabled
Python Library Documentation: built-in function set_autocast_xla_enabled in module torch set_autocast_xla_enabled(...)
torch.set_default_device
Python Library Documentation: function set_default_device in module torch
set_default_device(device: 'Device') -> None
Sets the default ``torch.Tensor`` to be allocated on ``device``. This
does not affect factory function calls which are called with an explicit
``device`` argument. Factory calls will be performed as if they
were passed ``device`` as an argument.
To only temporarily change the default device instead of setting it
globally, use ``with torch.device(device):`` instead.
The default device is initially ``cpu``. If you set the default tensor
device to another device (e.g., ``cuda``) without a device index, tensors
will be allocated on whatever the current device for the device type,
even after :func:`torch.cuda.set_device` is called.
.. warning::
This function imposes a slight performance cost on every Python
call to the torch API (not just factory functions). If this
is causing problems for you, please comment on
https://github.com/pytorch/pytorch/issues/92701
.. note::
This doesn't affect functions that create tensors that share the same memory as the input, like:
:func:`torch.from_numpy` and :func:`torch.frombuffer`
Args:
device (device or string): the device to set as default
Example::
>>> # xdoctest: +SKIP("requires cuda, changes global state")
>>> torch.get_default_device()
device(type='cpu')
>>> torch.set_default_device('cuda') # current device is 0
>>> torch.get_default_device()
device(type='cuda', index=0)
>>> torch.set_default_device('cuda')
>>> torch.cuda.set_device('cuda:1') # current device is 1
>>> torch.get_default_device()
device(type='cuda', index=1)
>>> torch.set_default_device('cuda:1')
>>> torch.get_default_device()
device(type='cuda', index=1)
torch.set_default_dtype
Python Library Documentation: function set_default_dtype in module torch
set_default_dtype(d: 'torch.dtype', /) -> None
Sets the default floating point dtype to :attr:`d`. Supports floating point dtype
as inputs. Other dtypes will cause torch to raise an exception.
When PyTorch is initialized its default floating point dtype is torch.float32,
and the intent of set_default_dtype(torch.float64) is to facilitate NumPy-like
type inference. The default floating point dtype is used to:
1. Implicitly determine the default complex dtype. When the default floating type is float16,
the default complex dtype is complex32. For float32, the default complex dtype is complex64.
For float64, it is complex128. For bfloat16, an exception will be raised because
there is no corresponding complex type for bfloat16.
2. Infer the dtype for tensors constructed using Python floats or complex Python
numbers. See examples below.
3. Determine the result of type promotion between bool and integer tensors and
Python floats and complex Python numbers.
Args:
d (:class:`torch.dtype`): the floating point dtype to make the default.
Example:
>>> # xdoctest: +SKIP("Other tests may have changed the default type. Can we reset it?")
>>> # initial default for floating point is torch.float32
>>> # Python floats are interpreted as float32
>>> torch.tensor([1.2, 3]).dtype
torch.float32
>>> # initial default for floating point is torch.complex64
>>> # Complex Python numbers are interpreted as complex64
>>> torch.tensor([1.2, 3j]).dtype
torch.complex64
>>> torch.set_default_dtype(torch.float64)
>>> # Python floats are now interpreted as float64
>>> torch.tensor([1.2, 3]).dtype # a new floating point tensor
torch.float64
>>> # Complex Python numbers are now interpreted as complex128
>>> torch.tensor([1.2, 3j]).dtype # a new complex tensor
torch.complex128
>>> torch.set_default_dtype(torch.float16)
>>> # Python floats are now interpreted as float16
>>> torch.tensor([1.2, 3]).dtype # a new floating point tensor
torch.float16
>>> # Complex Python numbers are now interpreted as complex128
>>> torch.tensor([1.2, 3j]).dtype # a new complex tensor
torch.complex32
torch.set_default_tensor_type
Python Library Documentation: function set_default_tensor_type in module torch
set_default_tensor_type(t: type['torch.Tensor'] | str, /) -> None
.. warning::
This function is deprecated as of PyTorch 2.1, please use :func:`torch.set_default_dtype()` and
:func:`torch.set_default_device()` as alternatives.
Sets the default ``torch.Tensor`` type to floating point tensor type
``t``. This type will also be used as default floating point type for
type inference in :func:`torch.tensor`.
The default floating point tensor type is initially ``torch.FloatTensor``.
Args:
t (type or string): the floating point tensor type or its name
Example::
>>> # xdoctest: +SKIP("Other tests may have changed the default type. Can we reset it?")
>>> torch.tensor([1.2, 3]).dtype # initial default for floating point is torch.float32
torch.float32
>>> torch.set_default_tensor_type(torch.DoubleTensor)
>>> torch.tensor([1.2, 3]).dtype # a new floating point tensor
torch.float64
torch.set_deterministic_debug_mode
Python Library Documentation: function set_deterministic_debug_mode in module torch
set_deterministic_debug_mode(debug_mode: int | str) -> None
Sets the debug mode for deterministic operations.
.. note:: This is an alternative interface for
:func:`torch.use_deterministic_algorithms`. Refer to that function's
documentation for details about affected operations.
Args:
debug_mode(str or int): If "default" or 0, don't error or warn on
nondeterministic operations. If "warn" or 1, warn on
nondeterministic operations. If "error" or 2, error on
nondeterministic operations.
torch.set_float32_matmul_precision
Python Library Documentation: function set_float32_matmul_precision in module torch
set_float32_matmul_precision(precision: str) -> None
Sets the internal precision of float32 matrix multiplications.
Running float32 matrix multiplications in lower precision may significantly increase
performance, and in some programs the loss of precision has a negligible impact.
Supports three settings:
* "highest", float32 matrix multiplications use the float32 datatype (24 mantissa
bits with 23 bits explicitly stored) for internal computations.
* "high", float32 matrix multiplications either use the TensorFloat32 datatype (10
mantissa bits explicitly stored) or treat each float32 number as the sum of two bfloat16 numbers
(approximately 16 mantissa bits with 14 bits explicitly stored), if the appropriate fast matrix multiplication
algorithms are available. Otherwise float32 matrix multiplications are computed
as if the precision is "highest". See below for more information on the bfloat16
approach.
* "medium", float32 matrix multiplications use the bfloat16 datatype (8 mantissa
bits with 7 bits explicitly stored) for internal computations, if a fast matrix multiplication algorithm
using that datatype internally is available. Otherwise float32
matrix multiplications are computed as if the precision is "high".
When using "high" precision, float32 multiplications may use a bfloat16-based algorithm
that is more complicated than simply truncating to some smaller number mantissa bits
(e.g. 10 for TensorFloat32, 7 for bfloat16 explicitly stored). Refer to [Henry2019]_ for a complete
description of this algorithm. To briefly explain here, the first step is to realize
that we can perfectly encode a single float32 number as the sum of three bfloat16
numbers (because float32 has 23 mantissa bits while bfloat16 has 7 explicitly stored, and both have the
same number of exponent bits). This means that the product of two float32 numbers can
be exactly given by the sum of nine products of bfloat16 numbers. We can then trade
accuracy for speed by dropping some of these products. The "high" precision algorithm
specifically keeps only the three most significant products, which conveniently excludes
all of the products involving the last 8 mantissa bits of either input. This means that
we can represent our inputs as the sum of two bfloat16 numbers rather than three.
Because bfloat16 fused-multiply-add (FMA) instructions are typically >10x faster than
float32 ones, it's faster to do three multiplications and 2 additions with bfloat16
precision than it is to do a single multiplication with float32 precision.
.. [Henry2019] http://arxiv.org/abs/1904.06376
.. note::
This does not change the output dtype of float32 matrix multiplications,
it controls how the internal computation of the matrix multiplication is performed.
.. note::
This does not change the precision of convolution operations. Other flags,
like `torch.backends.cudnn.allow_tf32`, may control the precision of convolution
operations.
.. note::
This flag currently only affects one native device type: CUDA.
If "high" or "medium" are set then the TensorFloat32 datatype will be used
when computing float32 matrix multiplications, equivalent to setting
`torch.backends.cuda.matmul.allow_tf32 = True`. When "highest" (the default)
is set then the float32 datatype is used for internal computations, equivalent
to setting `torch.backends.cuda.matmul.allow_tf32 = False`.
Args:
precision(str): can be set to "highest" (default), "high", or "medium" (see above).
torch.set_flush_denormal
Python Library Documentation: built-in function set_flush_denormal in module torch
set_flush_denormal(...)
set_flush_denormal(mode) -> bool
Disables denormal floating numbers on CPU.
Returns ``True`` if your system supports flushing denormal numbers and it
successfully configures flush denormal mode. :meth:`~torch.set_flush_denormal`
is supported on x86 architectures supporting SSE3 and AArch64 architecture.
Args:
mode (bool): Controls whether to enable flush denormal mode or not
Example::
>>> torch.set_flush_denormal(True)
True
>>> torch.tensor([1e-323], dtype=torch.float64)
tensor([ 0.], dtype=torch.float64)
>>> torch.set_flush_denormal(False)
True
>>> torch.tensor([1e-323], dtype=torch.float64)
tensor(9.88131e-324 *
[ 1.0000], dtype=torch.float64)
torch.set_grad_enabled
Python Library Documentation: class set_grad_enabled in module torch.autograd.grad_mode class set_grad_enabled(torch.utils._contextlib._DecoratorContextManager) | set_grad_enabled(mode: bool) -> None | | Context-manager that sets gradient calculation on or off. | | ``set_grad_enabled`` will enable or disable grads based on its argument :attr:`mode`. | It can be used as a context-manager or as a function. | | This context manager is thread local; it will not affect computation | in other threads. | | Args: | mode (bool): Flag whether to enable grad (``True``), or disable | (``False``). This can be used to conditionally enable | gradients. | | .. note:: | set_grad_enabled is one of several mechanisms that can enable or | disable gradients locally see :ref:`locally-disable-grad-doc` for | more information on how they compare. | | .. note:: | This API does not apply to :ref:`forward-mode AD <forward-mode-ad>`. | | Example:: | >>> # xdoctest: +SKIP | >>> x = torch.tensor([1.], requires_grad=True) | >>> is_train = False | >>> with torch.set_grad_enabled(is_train): | ... y = x * 2 | >>> y.requires_grad | False | >>> _ = torch.set_grad_enabled(True) | >>> y = x * 2 | >>> y.requires_grad | True | >>> _ = torch.set_grad_enabled(False) | >>> y = x * 2 | >>> y.requires_grad | False | | Method resolution order: | set_grad_enabled | torch.utils._contextlib._DecoratorContextManager | builtins.object | | Methods defined here: | | __call__(self, orig_func: ~F) -> ~F | Call self as a function. | | __enter__(self) -> None | | __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None | | __init__(self, mode: bool) -> None | Initialize self. See help(type(self)) for accurate signature. | | __repr__(self) -> str | Return repr(self). | | __str__(self) -> str | Return str(self). | | clone(self) -> 'set_grad_enabled' | Create a copy of this class | | ---------------------------------------------------------------------- | Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager: | | __dict__ | dictionary for instance variables | | __weakref__ | list of weak references to the object
torch.set_num_interop_threads
Python Library Documentation: built-in function set_num_interop_threads in module torch
set_num_interop_threads(...)
set_num_interop_threads(int)
Sets the number of threads used for interop parallelism
(e.g. in JIT interpreter) on CPU.
.. warning::
Can only be called once and before any inter-op parallel work
is started (e.g. JIT execution).
torch.set_num_threads
Python Library Documentation: built-in function set_num_threads in module torch
set_num_threads(...)
set_num_threads(int)
Sets the number of threads used for intraop parallelism on CPU.
.. warning::
To ensure that the correct number of threads is used, set_num_threads
must be called before running eager, JIT or autograd code.
torch.set_printoptions
Python Library Documentation: function set_printoptions in module torch._tensor_str
set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, profile=None, sci_mode=None)
Set options for printing. Items shamelessly taken from NumPy
Args:
precision: Number of digits of precision for floating point output
(default = 4).
threshold: Total number of array elements which trigger summarization
rather than full `repr` (default = 1000).
edgeitems: Number of array items in summary at beginning and end of
each dimension (default = 3).
linewidth: The number of characters per line for the purpose of
inserting line breaks (default = 80). Thresholded matrices will
ignore this parameter.
profile: Sane defaults for pretty printing. Can override with any of
the above options. (any one of `default`, `short`, `full`)
sci_mode: Enable (True) or disable (False) scientific notation. If
None (default) is specified, the value is defined by
`torch._tensor_str._Formatter`. This value is automatically chosen
by the framework.
Example::
>>> # Limit the precision of elements
>>> torch.set_printoptions(precision=2)
>>> torch.tensor([1.12345])
tensor([1.12])
>>> # Limit the number of elements shown
>>> torch.set_printoptions(threshold=5)
>>> torch.arange(10)
tensor([0, 1, 2, ..., 7, 8, 9])
>>> # Restore defaults
>>> torch.set_printoptions(profile='default')
>>> torch.tensor([1.12345])
tensor([1.1235])
>>> torch.arange(10)
tensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
torch.set_rng_state
Python Library Documentation: function set_rng_state in module torch.random
set_rng_state(new_state: torch.Tensor) -> None
Sets the random number generator state.
.. note:: This function only works for CPU. For CUDA, please use
:func:`torch.manual_seed`, which works for both CPU and CUDA.
Args:
new_state (torch.ByteTensor): The desired state
torch.set_warn_always
Python Library Documentation: function set_warn_always in module torch
set_warn_always(b: bool, /) -> None
When this flag is False (default) then some PyTorch warnings may only
appear once per process. This helps avoid excessive warning information.
Setting it to True causes these warnings to always appear, which may be
helpful when debugging.
Args:
b (:class:`bool`): If True, force warnings to always be emitted
If False, set to the default behaviour
torch.sgn
Python Library Documentation: built-in function sgn in module torch
sgn(...)
sgn(input, *, out=None) -> Tensor
This function is an extension of torch.sign() to complex tensors.
It computes a new tensor whose elements have
the same angles as the corresponding elements of :attr:`input` and
absolute values (i.e. magnitudes) of one for complex tensors and
is equivalent to torch.sign() for non-complex tensors.
.. math::
\text{out}_{i} = \begin{cases}
0 & |\text{{input}}_i| == 0 \\
\frac{{\text{{input}}_i}}{|{\text{{input}}_i}|} & \text{otherwise}
\end{cases}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.tensor([3+4j, 7-24j, 0, 1+2j])
>>> t.sgn()
tensor([0.6000+0.8000j, 0.2800-0.9600j, 0.0000+0.0000j, 0.4472+0.8944j])
torch.short
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.sigmoid
Python Library Documentation: built-in function sigmoid in module torch
sigmoid(...)
sigmoid(input, *, out=None) -> Tensor
Alias for :func:`torch.special.expit`.
torch.sigmoid_
Python Library Documentation: built-in function sigmoid_ in module torch sigmoid_(...)
torch.sign
Python Library Documentation: built-in function sign in module torch
sign(...)
sign(input, *, out=None) -> Tensor
Returns a new tensor with the signs of the elements of :attr:`input`.
.. math::
\text{out}_{i} = \operatorname{sgn}(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([0.7, -1.2, 0., 2.3])
>>> a
tensor([ 0.7000, -1.2000, 0.0000, 2.3000])
>>> torch.sign(a)
tensor([ 1., -1., 0., 1.])
torch.signal
Python Library Documentation: package torch.signal in torch
NAME
torch.signal
PACKAGE CONTENTS
windows (package)
DATA
__all__ = ['windows']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\signal\__init__.py
torch.signbit
Python Library Documentation: built-in function signbit in module torch
signbit(...)
signbit(input, *, out=None) -> Tensor
Tests if each element of :attr:`input` has its sign bit set or not.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([0.7, -1.2, 0., 2.3])
>>> torch.signbit(a)
tensor([ False, True, False, False])
>>> a = torch.tensor([-0.0, 0.0])
>>> torch.signbit(a)
tensor([ True, False])
.. note::
signbit handles signed zeros, so negative zero (-0) returns True.
torch.sin
Python Library Documentation: built-in function sin in module torch
sin(...)
sin(input, *, out=None) -> Tensor
Returns a new tensor with the sine of the elements in the :attr:`input` tensor,
where each value in this input tensor is in radians.
.. math::
\text{out}_{i} = \sin(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-0.5461, 0.1347, -2.7266, -0.2746])
>>> torch.sin(a)
tensor([-0.5194, 0.1343, -0.4032, -0.2711])
torch.sin_
Python Library Documentation: built-in function sin_ in module torch sin_(...)
torch.sinc
Python Library Documentation: built-in function sinc in module torch
sinc(...)
sinc(input, *, out=None) -> Tensor
Alias for :func:`torch.special.sinc`.
torch.sinc_
Python Library Documentation: built-in function sinc_ in module torch sinc_(...)
torch.sinh
Python Library Documentation: built-in function sinh in module torch
sinh(...)
sinh(input, *, out=None) -> Tensor
Returns a new tensor with the hyperbolic sine of the elements of
:attr:`input`.
.. math::
\text{out}_{i} = \sinh(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.5380, -0.8632, -0.1265, 0.9399])
>>> torch.sinh(a)
tensor([ 0.5644, -0.9744, -0.1268, 1.0845])
.. note::
When :attr:`input` is on the CPU, the implementation of torch.sinh may use
the Sleef library, which rounds very large results to infinity or negative
infinity. See `here <https://sleef.org/purec.xhtml>`_ for details.
torch.sinh_
Python Library Documentation: built-in function sinh_ in module torch sinh_(...)
torch.slice_copy
Python Library Documentation: built-in function slice_copy in module torch
slice_copy(...)
Performs the same operation as :func:`torch.slice`, but all output tensors
are freshly created instead of aliasing the input.
torch.slice_inverse
Python Library Documentation: built-in function slice_inverse in module torch slice_inverse(...)
torch.slice_scatter
Python Library Documentation: built-in function slice_scatter in module torch
slice_scatter(...)
slice_scatter(input, src, dim=0, start=None, end=None, step=1) -> Tensor
Embeds the values of the :attr:`src` tensor into :attr:`input` at the given
dimension.
This function returns a tensor with fresh storage; it does not create a view.
Args:
input (Tensor): the input tensor.
src (Tensor): The tensor to embed into :attr:`input`
dim (int): the dimension to insert the slice into
start (Optional[int]): the start index of where to insert the slice
end (Optional[int]): the end index of where to insert the slice
step (int): the how many elements to skip in
Example::
>>> a = torch.zeros(8, 8)
>>> b = torch.ones(2, 8)
>>> a.slice_scatter(b, start=6)
tensor([[0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0.],
[1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1.]])
>>> b = torch.ones(8, 2)
>>> a.slice_scatter(b, dim=1, start=2, end=6, step=2)
tensor([[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.]])
torch.slogdet
Python Library Documentation: built-in function slogdet in module torch
slogdet(...)
slogdet(input) -> (Tensor, Tensor)
Alias for :func:`torch.linalg.slogdet`
torch.smm
Python Library Documentation: built-in function smm in module torch
smm(...)
smm(input, mat) -> Tensor
Performs a matrix multiplication of the sparse matrix :attr:`input`
with the dense matrix :attr:`mat`.
Args:
input (Tensor): a sparse matrix to be matrix multiplied
mat (Tensor): a dense matrix to be matrix multiplied
torch.softmax
Python Library Documentation: built-in function softmax in module torch
softmax(...)
softmax(input, dim, *, dtype=None) -> Tensor
Alias for :func:`torch.nn.functional.softmax`.
torch.solve
Python Library Documentation: function solve in module torch._linalg_utils solve(input: torch.Tensor, A: torch.Tensor, *, out=None) -> tuple[torch.Tensor, torch.Tensor]
torch.sort
Python Library Documentation: built-in function sort in module torch
sort(...)
sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
Sorts the elements of the :attr:`input` tensor along a given dimension
in ascending order by value.
If :attr:`dim` is not given, the last dimension of the `input` is chosen.
If :attr:`descending` is ``True`` then the elements are sorted in descending
order by value.
If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
the order of equivalent elements.
A namedtuple of (values, indices) is returned, where the `values` are the
sorted values and `indices` are the indices of the elements in the original
`input` tensor.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to sort along
descending (bool, optional): controls the sorting order (ascending or descending)
Keyword args:
stable (bool, optional): makes the sorting routine stable, which guarantees that the order
of equivalent elements is preserved.
out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
be optionally given to be used as output buffers
Example::
>>> x = torch.randn(3, 4)
>>> sorted, indices = torch.sort(x)
>>> sorted
tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
[-0.5793, 0.0061, 0.6058, 0.9497],
[-0.5071, 0.3343, 0.9553, 1.0960]])
>>> indices
tensor([[ 1, 0, 2, 3],
[ 3, 1, 0, 2],
[ 0, 3, 1, 2]])
>>> sorted, indices = torch.sort(x, 0)
>>> sorted
tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
[ 0.0608, 0.0061, 0.9497, 0.3343],
[ 0.6058, 0.9553, 1.0960, 2.3332]])
>>> indices
tensor([[ 2, 0, 0, 1],
[ 0, 1, 1, 2],
[ 1, 2, 2, 0]])
>>> x = torch.tensor([0, 1] * 9)
>>> x.sort()
torch.return_types.sort(
values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
>>> x.sort(stable=True)
torch.return_types.sort(
values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
torch.sparse
Python Library Documentation: package torch.sparse in torch
NAME
torch.sparse
DESCRIPTION
# mypy: allow-untyped-defs
# The Tensor classes are added to this module by python_tensor.cpp
# A workaround to support both TorchScript and MyPy:
PACKAGE CONTENTS
_semi_structured_conversions
_semi_structured_ops
_triton_ops
_triton_ops_meta
semi_structured
CLASSES
builtins.object
check_sparse_tensor_invariants
torch.Tensor(torch._C.TensorBase)
torch.sparse.semi_structured.SparseSemiStructuredTensor
torch.sparse.semi_structured.SparseSemiStructuredTensorCUSPARSELT
torch.sparse.semi_structured.SparseSemiStructuredTensorCUTLASS
class SparseSemiStructuredTensor(torch.Tensor)
| SparseSemiStructuredTensor(shape: torch.Size, packed: torch.Tensor | None, meta: torch.Tensor | None, packed_t: torch.Tensor | None, meta_t: torch.Tensor | None, compressed_swizzled_bitmask: torch.Tensor | None, fuse_transpose_cusparselt: bool = False, alg_id_cusparselt: int = 0, requires_grad: bool = False)
|
| This class implements semi-structured sparsity as a Tensor subclass.
|
| Semi-structured sparsity describes a sparsity pattern where n in every 2n elements are sparse,
| depending on the datatype. It is also referred to as 2:4 sparsity or fine-grained
| structured sparsity.
|
| There are two backends available for semi_structred sparsity, either cuSPARSELt or CUTLASS.
| This class is meant to serve as a base class for both implementations. SparseSemiStructuredCUTLASS
| and SparseSemiStructuredCUSPARSELT both inherit from this class and define three backend-specific items.
| Note that as such, this class cannot be instantiated directly.
|
| -`_DTYPE_SHAPE_CONSTRAINTS` - A dictionary holding backend specific dense/sparse min shape constraints
| - `def from_dense()` - backend specific compression routines
| - `def _mm()` - backend specific mm op (either torch._cslt_sparse_mm or torch._sparse_semi_structured_(mm|addmm))
|
| Method resolution order:
| SparseSemiStructuredTensor
| torch.Tensor
| torch._C.TensorBase
| builtins.object
|
| Methods defined here:
|
| __repr__(self) -> str
| Return repr(self).
|
| __tensor_flatten__(self) -> tuple[list[str], tuple[torch.Size, bool, int, bool]]
|
| to_dense(self)
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __tensor_unflatten__(inner_tensors, tensor_meta: tuple[torch.Size, bool, int, bool], outer_size, outer_stride) -> torch.Tensor
|
| __torch_dispatch__(func, types, args, kwargs) -> Any
|
| from_dense(original_tensor: torch.Tensor, alg_id: int = 0) -> 'SparseSemiStructuredTensor'
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, shape: torch.Size, packed: torch.Tensor | None, meta: torch.Tensor | None, packed_t: torch.Tensor | None, meta_t: torch.Tensor | None, compressed_swizzled_bitmask: torch.Tensor | None, fuse_transpose_cusparselt: bool = False, alg_id_cusparselt: int = 0, requires_grad: bool = False)
| Create a new instance of the tensor subclass from the compressed sparse representation.
|
| We have the option to create the subclass with the compressed representations of both X and X', for training.
| For inference, we only need a single representation (either X or X'), while the corresponding other set will be None.
|
| Depending on the backend selected, certain fields will be set to None. (CUSPARSELT vs CUTLASS)
|
| Args:
| shape: The shape of the original dense tensor
| packed: The compressed representation of the original dense tensor
| meta: The metadata of the original dense tensor, if it is stored separately
| packed_t: The compressed representation of the transposed original dense tensor
| meta_t: The metadata of the transposed original dense tensor, if it is stored separately
| compressed_swizzled_bitmask: The masks used by the CUTLASS backend to determine which threads should
| participate in the computation. Used for pointwise ops.
| fuse_transpose_cusparselt: When running with cuSPARSELt, we have the option to fuse a transposition
| with a matmul, which is useful in the case of 2:4 sparse training.
| alg_id_cusparselt: The algorithm id to use when using cuSPARSELT, will have effect on performance
|
| Returns:
| torch.Tensor: A torch.Tensor wrapper subclass.
|
| Raises:
| ValueError: If all of the tensor arguments are None.
|
| __torch_function__ = _disabled_torch_function_impl(...)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| compressed_swizzled_bitmask
|
| meta
|
| meta_t
|
| packed
|
| packed_t
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'BACKEND': <class 'str'>, 'SPARSE_DISPATCH': dict[c...
|
| ----------------------------------------------------------------------
| Methods inherited from torch.Tensor:
|
| __abs__ = abs(...)
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __neg__ = neg(...)
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| solve(self, other) from torch._tensor.Tensor
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.Tensor:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.Tensor:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.Tensor:
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C.TensorBase:
|
| __add__(...)
|
| __and__(...)
|
| __bool__(...)
|
| __complex__(...)
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __div__(...)
|
| __eq__(...)
| Return self==value.
|
| __float__(...)
|
| __ge__(...)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(...)
| Return self>value.
|
| __iadd__(...)
|
| __iand__(...)
|
| __idiv__(...)
|
| __ifloordiv__(...)
|
| __ilshift__(...)
|
| __imod__(...)
|
| __imul__(...)
|
| __index__(...)
|
| __int__(...)
|
| __invert__(...)
|
| __ior__(...)
|
| __irshift__(...)
|
| __isub__(...)
|
| __ixor__(...)
|
| __le__(...)
| Return self<=value.
|
| __long__(...)
|
| __lshift__(...)
|
| __lt__(...)
| Return self<value.
|
| __matmul__(...)
|
| __mod__(...)
|
| __mul__(...)
|
| __ne__(...)
| Return self!=value.
|
| __nonzero__(...)
|
| __or__(...)
| Return self|value.
|
| __radd__(...)
|
| __rand__(...)
|
| __rmul__(...)
|
| __ror__(...)
| Return value|self.
|
| __rshift__(...)
|
| __rxor__(...)
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sub__(...)
|
| __truediv__(...)
|
| __xor__(...)
|
| abs(...)
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...)
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...)
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...)
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...)
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...)
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...)
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...)
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...)
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...)
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...)
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...)
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...)
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...)
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...)
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...)
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...)
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...)
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...)
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...)
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...)
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...)
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...)
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...)
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...)
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...)
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...)
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...)
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...)
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...)
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...)
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...)
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...)
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...)
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...)
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...)
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...)
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...)
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...)
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...)
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...)
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...)
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...)
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...)
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...)
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...)
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...)
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...)
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...)
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...)
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...)
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...)
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...)
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...)
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...)
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...)
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...)
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...)
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...)
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| baddbmm(...)
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...)
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...)
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...)
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...)
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...)
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...)
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...)
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...)
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...)
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...)
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...)
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...)
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...)
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...)
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...)
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...)
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...)
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...)
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...)
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...)
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...)
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...)
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...)
|
| cdouble(...)
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...)
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...)
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...)
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...)
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...)
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...)
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...)
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...)
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...)
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...)
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...)
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...)
|
| clamp_max_(...)
|
| clamp_min(...)
|
| clamp_min_(...)
|
| clip(...)
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...)
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...)
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...)
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...)
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...)
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...)
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...)
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...)
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...)
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...)
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...)
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...)
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...)
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...)
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...)
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...)
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...)
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...)
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...)
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...)
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...)
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...)
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...)
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...)
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...)
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...)
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...)
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...)
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...)
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...)
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...)
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...)
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...)
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...)
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...)
| det() -> Tensor
|
| See :func:`torch.det`
|
| diag(...)
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...)
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...)
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...)
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...)
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...)
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...)
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...)
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...)
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dist(...)
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...)
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...)
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...)
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...)
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...)
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...)
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...)
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| element_size(...)
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...)
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...)
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...)
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...)
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...)
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...)
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...)
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...)
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...)
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...)
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...)
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...)
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...)
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...)
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...)
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...)
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...)
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...)
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...)
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...)
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...)
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...)
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...)
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...)
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...)
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...)
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...)
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...)
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...)
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...)
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...)
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...)
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...)
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...)
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...)
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...)
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...)
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...)
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...)
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...)
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...)
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...)
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...)
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...)
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...)
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...)
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...)
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...)
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...)
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...)
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...)
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...)
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...)
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...)
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...)
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...)
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...)
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...)
|
| heaviside(...)
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...)
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...)
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...)
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...)
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...)
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...)
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...)
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...)
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...)
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...)
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...)
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...)
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index_add(...)
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...)
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...)
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...)
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...)
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...)
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...)
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...)
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...)
|
| index_reduce_(...)
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...)
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...)
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...)
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...)
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...)
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...)
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...)
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...)
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...)
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...)
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...)
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...)
|
| is_floating_point(...)
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...)
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...)
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...)
|
| is_pinned(...)
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...)
|
| is_set_to(...)
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_signed(...)
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...)
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...)
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...)
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...)
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...)
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...)
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...)
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| item(...)
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...)
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...)
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...)
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...)
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...)
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...)
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...)
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...)
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...)
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...)
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...)
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...)
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...)
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...)
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...)
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...)
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...)
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...)
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...)
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...)
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...)
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...)
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...)
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...)
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...)
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...)
|
| logaddexp(...)
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...)
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...)
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...)
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...)
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...)
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...)
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...)
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...)
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...)
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...)
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...)
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...)
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...)
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...)
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...)
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lt(...)
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...)
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu_solve(...)
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...)
|
| map_(...)
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...)
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...)
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...)
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...)
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...)
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...)
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...)
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...)
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...)
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...)
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...)
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...)
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...)
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...)
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...)
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...)
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| moveaxis(...)
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...)
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...)
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...)
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...)
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...)
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...)
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...)
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...)
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...)
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...)
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...)
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...)
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...)
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...)
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...)
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...)
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...)
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...)
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...)
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...)
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...)
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...)
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...)
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...)
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...)
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...)
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...)
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...)
|
| new_empty(...)
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...)
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...)
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...)
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...)
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...)
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...)
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...)
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...)
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...)
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| normal_(...)
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...)
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...)
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...)
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...)
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...)
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...)
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...)
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...)
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...)
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...)
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...)
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...)
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...)
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...)
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...)
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...)
|
| prod(...)
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...)
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...)
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...)
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...)
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...)
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...)
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...)
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...)
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...)
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...)
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...)
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...)
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...)
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...)
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...)
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...)
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...)
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| relu(...)
|
| relu_(...)
|
| remainder(...)
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...)
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...)
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...)
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...)
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...)
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...)
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...)
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...)
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize_(...)
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as_(...)
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...)
|
| resolve_conj(...)
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...)
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...)
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...)
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...)
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...)
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...)
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...)
|
| rsqrt(...)
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...)
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...)
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...)
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...)
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...)
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...)
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...)
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...)
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...)
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...)
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...)
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...)
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| short(...)
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...)
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...)
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...)
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...)
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...)
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...)
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...)
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...)
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...)
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...)
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...)
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...)
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...)
|
| slice_scatter(...)
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...)
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...)
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...)
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| sort(...)
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...)
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...)
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...)
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...)
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split_with_sizes(...)
|
| sqrt(...)
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...)
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...)
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...)
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...)
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...)
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...)
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...)
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| storage_offset(...)
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| stride(...)
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...)
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...)
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...)
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...)
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...)
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...)
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...)
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...)
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...)
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...)
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...)
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| t(...)
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...)
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...)
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...)
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...)
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...)
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...)
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...)
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...)
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...)
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...)
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_mkldnn(...)
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...)
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...)
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...)
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...)
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_csc(...)
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...)
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...)
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...)
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...)
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...)
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...)
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...)
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...)
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...)
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...)
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...)
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...)
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...)
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...)
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...)
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...)
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...)
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...)
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unfold(...)
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...)
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unsafe_chunk(...)
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...)
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...)
|
| unsqueeze(...)
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...)
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...)
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...)
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...)
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...)
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...)
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...)
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...)
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...)
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...)
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...)
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...)
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...)
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C.TensorBase:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| dtype
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_cuda
| Is ``True`` if the Tensor is stored on the GPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_sparse
| Is ``True`` if the Tensor uses sparse COO storage layout, ``False`` otherwise.
|
| is_sparse_csr
| Is ``True`` if the Tensor uses sparse CSR storage layout, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| is_xpu
| Is ``True`` if the Tensor is stored on the XPU, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| layout
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
class SparseSemiStructuredTensorCUSPARSELT(SparseSemiStructuredTensor)
| SparseSemiStructuredTensorCUSPARSELT(shape: torch.Size, packed: torch.Tensor | None, meta: torch.Tensor | None, packed_t: torch.Tensor | None, meta_t: torch.Tensor | None, compressed_swizzled_bitmask: torch.Tensor | None, fuse_transpose_cusparselt: bool = False, alg_id_cusparselt: int = 0, requires_grad: bool = False)
|
| The cuSPARSELt backend expects the specified elements and the metadata to be stored in a single tensor:
| packed = [ specified elements of original tensor | metadata ]
| For an original tensor of size (m, k) we expect the first m * k // 2 elements to be the kept elements
| The rest of the tensor is metadata. Since there is only one tensor, we only use the packed and packed_t
| attributes respectively.
|
| cuSPARSELt also supports transposition fusion, which is necessary for performant 2:4 sparse training, as well
| as specifying alg_id, a config that affects the performance of the matmul depending on matmul sizes.
|
| Method resolution order:
| SparseSemiStructuredTensorCUSPARSELT
| SparseSemiStructuredTensor
| torch.Tensor
| torch._C.TensorBase
| builtins.object
|
| Class methods defined here:
|
| from_dense(original_tensor: torch.Tensor, alg_id: int = 0) -> 'SparseSemiStructuredTensorCUSPARSELT'
|
| prune_dense_static_sort(original_tensor: torch.Tensor, algorithm='') -> 'SparseSemiStructuredTensor'
| This function does the same thing as described in SparseSemiStructuredCUTLASS, but uses the cuSPARSELt metadata
| layout and sparse matmul.
|
| The only functional difference is that cuSPARSELt stores `metadata` and `packed` together into a single tensor.
|
| ::
|
| [9 1 7 4] [9 0 7 0]
| [1 2 3 0] [0 2 0 0]
| [8 3 5 4] -> prune 4x4 tile -> [8 0 0 4] -> pack to cuSPARSELT semi-structured -> packed
| [1 2 6 2] [0 0 6 2]
|
| -> pack to transposed cuSPARSELt -> packed_t
| semi-structured representation
|
| -> compute swizzled bitmask -> compressed_swizzled_bitmask
|
| The equivalent PyTorch code to create the same three outputs from the dense tensor can be found below::
|
| from torch.sparse import SparseSemiStructuredTensorCUSPARSELT
| from torch.sparse._semi_structured_conversions import (
| _sparse_semi_structured_tile,
| _compute_compressed_swizzled_bitmask,
| )
|
| pruned = _sparse_semi_structured_tile(dense)
| packed_cusparselt = torch._cslt_compress(pruned)
| packed_t_cusparselt = torch._cslt_compress(pruned.t().contiguous())
| bitmask = _compute_compressed_swizzled_bitmask(pruned)
|
| SparseSemiStructuredTensorCUSPARSELT(
| dense.shape, packed_cutlass, None, packed_t_cutlass, None, bitmask
| )
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| BACKEND = 'cusparselt'
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from SparseSemiStructuredTensor:
|
| __repr__(self) -> str
| Return repr(self).
|
| __tensor_flatten__(self) -> tuple[list[str], tuple[torch.Size, bool, int, bool]]
|
| to_dense(self)
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| ----------------------------------------------------------------------
| Class methods inherited from SparseSemiStructuredTensor:
|
| __tensor_unflatten__(inner_tensors, tensor_meta: tuple[torch.Size, bool, int, bool], outer_size, outer_stride) -> torch.Tensor
|
| __torch_dispatch__(func, types, args, kwargs) -> Any
|
| ----------------------------------------------------------------------
| Static methods inherited from SparseSemiStructuredTensor:
|
| __new__(cls, shape: torch.Size, packed: torch.Tensor | None, meta: torch.Tensor | None, packed_t: torch.Tensor | None, meta_t: torch.Tensor | None, compressed_swizzled_bitmask: torch.Tensor | None, fuse_transpose_cusparselt: bool = False, alg_id_cusparselt: int = 0, requires_grad: bool = False)
| Create a new instance of the tensor subclass from the compressed sparse representation.
|
| We have the option to create the subclass with the compressed representations of both X and X', for training.
| For inference, we only need a single representation (either X or X'), while the corresponding other set will be None.
|
| Depending on the backend selected, certain fields will be set to None. (CUSPARSELT vs CUTLASS)
|
| Args:
| shape: The shape of the original dense tensor
| packed: The compressed representation of the original dense tensor
| meta: The metadata of the original dense tensor, if it is stored separately
| packed_t: The compressed representation of the transposed original dense tensor
| meta_t: The metadata of the transposed original dense tensor, if it is stored separately
| compressed_swizzled_bitmask: The masks used by the CUTLASS backend to determine which threads should
| participate in the computation. Used for pointwise ops.
| fuse_transpose_cusparselt: When running with cuSPARSELt, we have the option to fuse a transposition
| with a matmul, which is useful in the case of 2:4 sparse training.
| alg_id_cusparselt: The algorithm id to use when using cuSPARSELT, will have effect on performance
|
| Returns:
| torch.Tensor: A torch.Tensor wrapper subclass.
|
| Raises:
| ValueError: If all of the tensor arguments are None.
|
| __torch_function__ = _disabled_torch_function_impl(...)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from SparseSemiStructuredTensor:
|
| compressed_swizzled_bitmask
|
| meta
|
| meta_t
|
| packed
|
| packed_t
|
| ----------------------------------------------------------------------
| Methods inherited from torch.Tensor:
|
| __abs__ = abs(...)
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __neg__ = neg(...)
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| solve(self, other) from torch._tensor.Tensor
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.Tensor:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.Tensor:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.Tensor:
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C.TensorBase:
|
| __add__(...)
|
| __and__(...)
|
| __bool__(...)
|
| __complex__(...)
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __div__(...)
|
| __eq__(...)
| Return self==value.
|
| __float__(...)
|
| __ge__(...)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(...)
| Return self>value.
|
| __iadd__(...)
|
| __iand__(...)
|
| __idiv__(...)
|
| __ifloordiv__(...)
|
| __ilshift__(...)
|
| __imod__(...)
|
| __imul__(...)
|
| __index__(...)
|
| __int__(...)
|
| __invert__(...)
|
| __ior__(...)
|
| __irshift__(...)
|
| __isub__(...)
|
| __ixor__(...)
|
| __le__(...)
| Return self<=value.
|
| __long__(...)
|
| __lshift__(...)
|
| __lt__(...)
| Return self<value.
|
| __matmul__(...)
|
| __mod__(...)
|
| __mul__(...)
|
| __ne__(...)
| Return self!=value.
|
| __nonzero__(...)
|
| __or__(...)
| Return self|value.
|
| __radd__(...)
|
| __rand__(...)
|
| __rmul__(...)
|
| __ror__(...)
| Return value|self.
|
| __rshift__(...)
|
| __rxor__(...)
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sub__(...)
|
| __truediv__(...)
|
| __xor__(...)
|
| abs(...)
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...)
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...)
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...)
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...)
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...)
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...)
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...)
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...)
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...)
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...)
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...)
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...)
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...)
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...)
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...)
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...)
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...)
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...)
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...)
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...)
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...)
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...)
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...)
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...)
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...)
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...)
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...)
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...)
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...)
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...)
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...)
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...)
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...)
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...)
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...)
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...)
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...)
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...)
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...)
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...)
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...)
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...)
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...)
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...)
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...)
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...)
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...)
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...)
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...)
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...)
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...)
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...)
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...)
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...)
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...)
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...)
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...)
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...)
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| baddbmm(...)
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...)
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...)
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...)
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...)
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...)
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...)
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...)
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...)
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...)
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...)
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...)
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...)
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...)
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...)
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...)
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...)
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...)
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...)
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...)
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...)
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...)
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...)
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...)
|
| cdouble(...)
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...)
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...)
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...)
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...)
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...)
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...)
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...)
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...)
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...)
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...)
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...)
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...)
|
| clamp_max_(...)
|
| clamp_min(...)
|
| clamp_min_(...)
|
| clip(...)
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...)
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...)
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...)
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...)
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...)
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...)
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...)
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...)
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...)
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...)
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...)
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...)
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...)
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...)
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...)
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...)
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...)
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...)
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...)
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...)
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...)
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...)
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...)
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...)
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...)
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...)
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...)
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...)
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...)
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...)
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...)
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...)
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...)
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...)
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...)
| det() -> Tensor
|
| See :func:`torch.det`
|
| diag(...)
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...)
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...)
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...)
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...)
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...)
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...)
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...)
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...)
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dist(...)
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...)
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...)
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...)
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...)
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...)
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...)
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...)
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| element_size(...)
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...)
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...)
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...)
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...)
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...)
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...)
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...)
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...)
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...)
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...)
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...)
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...)
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...)
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...)
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...)
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...)
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...)
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...)
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...)
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...)
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...)
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...)
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...)
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...)
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...)
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...)
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...)
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...)
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...)
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...)
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...)
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...)
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...)
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...)
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...)
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...)
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...)
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...)
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...)
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...)
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...)
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...)
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...)
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...)
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...)
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...)
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...)
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...)
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...)
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...)
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...)
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...)
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...)
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...)
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...)
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...)
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...)
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...)
|
| heaviside(...)
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...)
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...)
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...)
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...)
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...)
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...)
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...)
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...)
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...)
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...)
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...)
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...)
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index_add(...)
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...)
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...)
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...)
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...)
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...)
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...)
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...)
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...)
|
| index_reduce_(...)
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...)
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...)
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...)
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...)
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...)
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...)
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...)
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...)
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...)
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...)
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...)
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...)
|
| is_floating_point(...)
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...)
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...)
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...)
|
| is_pinned(...)
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...)
|
| is_set_to(...)
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_signed(...)
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...)
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...)
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...)
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...)
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...)
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...)
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...)
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| item(...)
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...)
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...)
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...)
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...)
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...)
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...)
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...)
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...)
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...)
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...)
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...)
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...)
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...)
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...)
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...)
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...)
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...)
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...)
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...)
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...)
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...)
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...)
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...)
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...)
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...)
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...)
|
| logaddexp(...)
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...)
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...)
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...)
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...)
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...)
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...)
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...)
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...)
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...)
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...)
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...)
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...)
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...)
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...)
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...)
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lt(...)
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...)
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu_solve(...)
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...)
|
| map_(...)
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...)
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...)
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...)
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...)
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...)
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...)
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...)
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...)
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...)
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...)
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...)
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...)
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...)
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...)
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...)
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...)
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| moveaxis(...)
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...)
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...)
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...)
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...)
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...)
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...)
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...)
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...)
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...)
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...)
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...)
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...)
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...)
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...)
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...)
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...)
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...)
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...)
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...)
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...)
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...)
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...)
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...)
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...)
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...)
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...)
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...)
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...)
|
| new_empty(...)
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...)
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...)
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...)
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...)
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...)
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...)
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...)
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...)
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...)
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| normal_(...)
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...)
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...)
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...)
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...)
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...)
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...)
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...)
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...)
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...)
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...)
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...)
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...)
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...)
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...)
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...)
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...)
|
| prod(...)
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...)
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...)
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...)
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...)
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...)
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...)
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...)
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...)
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...)
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...)
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...)
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...)
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...)
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...)
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...)
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...)
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...)
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| relu(...)
|
| relu_(...)
|
| remainder(...)
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...)
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...)
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...)
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...)
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...)
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...)
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...)
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...)
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize_(...)
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as_(...)
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...)
|
| resolve_conj(...)
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...)
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...)
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...)
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...)
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...)
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...)
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...)
|
| rsqrt(...)
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...)
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...)
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...)
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...)
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...)
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...)
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...)
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...)
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...)
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...)
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...)
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...)
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| short(...)
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...)
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...)
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...)
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...)
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...)
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...)
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...)
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...)
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...)
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...)
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...)
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...)
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...)
|
| slice_scatter(...)
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...)
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...)
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...)
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| sort(...)
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...)
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...)
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...)
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...)
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split_with_sizes(...)
|
| sqrt(...)
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...)
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...)
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...)
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...)
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...)
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...)
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...)
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| storage_offset(...)
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| stride(...)
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...)
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...)
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...)
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...)
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...)
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...)
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...)
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...)
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...)
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...)
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...)
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| t(...)
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...)
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...)
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...)
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...)
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...)
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...)
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...)
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...)
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...)
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...)
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_mkldnn(...)
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...)
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...)
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...)
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...)
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_csc(...)
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...)
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...)
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...)
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...)
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...)
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...)
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...)
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...)
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...)
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...)
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...)
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...)
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...)
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...)
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...)
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...)
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...)
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...)
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unfold(...)
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...)
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unsafe_chunk(...)
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...)
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...)
|
| unsqueeze(...)
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...)
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...)
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...)
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...)
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...)
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...)
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...)
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...)
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...)
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...)
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...)
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...)
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...)
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C.TensorBase:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| dtype
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_cuda
| Is ``True`` if the Tensor is stored on the GPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_sparse
| Is ``True`` if the Tensor uses sparse COO storage layout, ``False`` otherwise.
|
| is_sparse_csr
| Is ``True`` if the Tensor uses sparse CSR storage layout, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| is_xpu
| Is ``True`` if the Tensor is stored on the XPU, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| layout
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
class SparseSemiStructuredTensorCUTLASS(SparseSemiStructuredTensor)
| SparseSemiStructuredTensorCUTLASS(shape: torch.Size, packed: torch.Tensor | None, meta: torch.Tensor | None, packed_t: torch.Tensor | None, meta_t: torch.Tensor | None, compressed_swizzled_bitmask: torch.Tensor | None, fuse_transpose_cusparselt: bool = False, alg_id_cusparselt: int = 0, requires_grad: bool = False)
|
| This class implements semi-structured sparsity for the CUTLASS backend.
|
|
| In this implementation, the specified elements and metadata are stored separately,
| in packed and meta respectively.
|
| When _FORCE_CUTLASS is set, or when cuSPARSELt is not available, this subclass calls into _sparse_semi_structured_(mm|addmm) and
| sparse_semi_structured_from_dense for conversion to the compressed format.
|
| Method resolution order:
| SparseSemiStructuredTensorCUTLASS
| SparseSemiStructuredTensor
| torch.Tensor
| torch._C.TensorBase
| builtins.object
|
| Methods defined here:
|
| to_dense(self)
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_dense(original_tensor: torch.Tensor, alg_id: int = 0) -> 'SparseSemiStructuredTensorCUTLASS'
|
| prune_dense_static_sort(original_tensor: torch.Tensor, algorithm='') -> 'SparseSemiStructuredTensor'
| This function takes in a unpruned dense tensor and runs a (branchless) static sort across a 4x4 tile.
|
| It greedily picks the largest values in the tile, upholding the 2:4 sparsity constraint across both rows and columns.
| The algorithm used to prune the matrix is implemented in `_sparse_semi_structured_tile`.
|
| Then it creates the packed and meta tensors for the compressed sparse representation of the pruned dense tensor.
| It also calculates the packed_t and meta_t tensors for the compressed sparse representation of the transposed
| pruned dense tensor.
| Since we cannot transpose the compressed representations, we store both for the fw/bw pass respectively.
|
| Finally, this function also computes a compressed swizzled bitmask that encodes the sparsity pattern.
| This can be used in the backward pass to mask the gradients.
|
| ::
|
| [9 1 7 4] [9 0 7 0]
| [1 2 3 0] [0 2 0 0]
| [8 3 5 4] -> prune 4x4 tile -> [8 0 0 4] -> pack to CUTLASS semi-structured -> packed
| [1 2 6 2] [0 0 6 2] -> metadata
|
| -> pack to transposed CUTLASS -> packed_t
| semi-structured representation -> metadata_t
|
| -> compute swizzled bitmask -> compressed_swizzled_bitmask
|
| The equivalent PyTorch code to create the same five outputs from the dense tensor can be found below::
|
| from torch.sparse import SparseSemiStructuredTensorCUTLASS
| from torch.sparse._semi_structured_conversions import (
| _sparse_semi_structured_tile,
| _compute_compressed_swizzled_bitmask,
| )
|
| pruned = _sparse_semi_structured_tile(dense)
| packed_cutlass, meta_cutlass = sparse_semi_structured_from_dense_cutlass(
| pruned
| )
| packed_t_cutlass, meta_t_cutlass = (
| sparse_semi_structured_from_dense_cutlass(pruned.t().contiguous())
| )
| bitmask = _compute_compressed_swizzled_bitmask(pruned)
|
| SparseSemiStructuredTensorCUTLASS(
| dense.shape,
| packed_cutlass,
| meta_cutlass,
| packed_t_cutlass,
| meta_t_cutlass,
| bitmask,
| )
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| BACKEND = 'cutlass'
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from SparseSemiStructuredTensor:
|
| __repr__(self) -> str
| Return repr(self).
|
| __tensor_flatten__(self) -> tuple[list[str], tuple[torch.Size, bool, int, bool]]
|
| ----------------------------------------------------------------------
| Class methods inherited from SparseSemiStructuredTensor:
|
| __tensor_unflatten__(inner_tensors, tensor_meta: tuple[torch.Size, bool, int, bool], outer_size, outer_stride) -> torch.Tensor
|
| __torch_dispatch__(func, types, args, kwargs) -> Any
|
| ----------------------------------------------------------------------
| Static methods inherited from SparseSemiStructuredTensor:
|
| __new__(cls, shape: torch.Size, packed: torch.Tensor | None, meta: torch.Tensor | None, packed_t: torch.Tensor | None, meta_t: torch.Tensor | None, compressed_swizzled_bitmask: torch.Tensor | None, fuse_transpose_cusparselt: bool = False, alg_id_cusparselt: int = 0, requires_grad: bool = False)
| Create a new instance of the tensor subclass from the compressed sparse representation.
|
| We have the option to create the subclass with the compressed representations of both X and X', for training.
| For inference, we only need a single representation (either X or X'), while the corresponding other set will be None.
|
| Depending on the backend selected, certain fields will be set to None. (CUSPARSELT vs CUTLASS)
|
| Args:
| shape: The shape of the original dense tensor
| packed: The compressed representation of the original dense tensor
| meta: The metadata of the original dense tensor, if it is stored separately
| packed_t: The compressed representation of the transposed original dense tensor
| meta_t: The metadata of the transposed original dense tensor, if it is stored separately
| compressed_swizzled_bitmask: The masks used by the CUTLASS backend to determine which threads should
| participate in the computation. Used for pointwise ops.
| fuse_transpose_cusparselt: When running with cuSPARSELt, we have the option to fuse a transposition
| with a matmul, which is useful in the case of 2:4 sparse training.
| alg_id_cusparselt: The algorithm id to use when using cuSPARSELT, will have effect on performance
|
| Returns:
| torch.Tensor: A torch.Tensor wrapper subclass.
|
| Raises:
| ValueError: If all of the tensor arguments are None.
|
| __torch_function__ = _disabled_torch_function_impl(...)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from SparseSemiStructuredTensor:
|
| compressed_swizzled_bitmask
|
| meta
|
| meta_t
|
| packed
|
| packed_t
|
| ----------------------------------------------------------------------
| Methods inherited from torch.Tensor:
|
| __abs__ = abs(...)
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __neg__ = neg(...)
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| solve(self, other) from torch._tensor.Tensor
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.Tensor:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.Tensor:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.Tensor:
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C.TensorBase:
|
| __add__(...)
|
| __and__(...)
|
| __bool__(...)
|
| __complex__(...)
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __div__(...)
|
| __eq__(...)
| Return self==value.
|
| __float__(...)
|
| __ge__(...)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(...)
| Return self>value.
|
| __iadd__(...)
|
| __iand__(...)
|
| __idiv__(...)
|
| __ifloordiv__(...)
|
| __ilshift__(...)
|
| __imod__(...)
|
| __imul__(...)
|
| __index__(...)
|
| __int__(...)
|
| __invert__(...)
|
| __ior__(...)
|
| __irshift__(...)
|
| __isub__(...)
|
| __ixor__(...)
|
| __le__(...)
| Return self<=value.
|
| __long__(...)
|
| __lshift__(...)
|
| __lt__(...)
| Return self<value.
|
| __matmul__(...)
|
| __mod__(...)
|
| __mul__(...)
|
| __ne__(...)
| Return self!=value.
|
| __nonzero__(...)
|
| __or__(...)
| Return self|value.
|
| __radd__(...)
|
| __rand__(...)
|
| __rmul__(...)
|
| __ror__(...)
| Return value|self.
|
| __rshift__(...)
|
| __rxor__(...)
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sub__(...)
|
| __truediv__(...)
|
| __xor__(...)
|
| abs(...)
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...)
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...)
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...)
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...)
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...)
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...)
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...)
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...)
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...)
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...)
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...)
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...)
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...)
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...)
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...)
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...)
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...)
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...)
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...)
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...)
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...)
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...)
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...)
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...)
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...)
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...)
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...)
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...)
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...)
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...)
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...)
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...)
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...)
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...)
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...)
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...)
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...)
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...)
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...)
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...)
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...)
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...)
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...)
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...)
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...)
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...)
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...)
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...)
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...)
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...)
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...)
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...)
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...)
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...)
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...)
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...)
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...)
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...)
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| baddbmm(...)
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...)
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...)
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...)
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...)
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...)
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...)
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...)
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...)
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...)
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...)
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...)
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...)
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...)
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...)
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...)
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...)
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...)
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...)
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...)
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...)
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...)
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...)
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...)
|
| cdouble(...)
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...)
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...)
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...)
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...)
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...)
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...)
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...)
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...)
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...)
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...)
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...)
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...)
|
| clamp_max_(...)
|
| clamp_min(...)
|
| clamp_min_(...)
|
| clip(...)
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...)
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...)
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...)
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...)
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...)
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...)
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...)
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...)
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...)
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...)
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...)
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...)
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...)
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...)
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...)
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...)
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...)
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...)
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...)
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...)
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...)
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...)
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...)
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...)
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...)
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...)
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...)
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...)
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...)
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...)
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...)
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...)
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...)
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...)
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...)
| det() -> Tensor
|
| See :func:`torch.det`
|
| diag(...)
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...)
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...)
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...)
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...)
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...)
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...)
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...)
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...)
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dist(...)
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...)
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...)
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...)
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...)
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...)
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...)
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...)
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| element_size(...)
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...)
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...)
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...)
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...)
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...)
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...)
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...)
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...)
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...)
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...)
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...)
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...)
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...)
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...)
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...)
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...)
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...)
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...)
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...)
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...)
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...)
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...)
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...)
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...)
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...)
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...)
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...)
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...)
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...)
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...)
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...)
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...)
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...)
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...)
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...)
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...)
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...)
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...)
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...)
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...)
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...)
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...)
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...)
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...)
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...)
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...)
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...)
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...)
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...)
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...)
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...)
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...)
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...)
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...)
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...)
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...)
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...)
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...)
|
| heaviside(...)
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...)
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...)
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...)
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...)
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...)
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...)
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...)
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...)
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...)
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...)
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...)
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...)
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index_add(...)
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...)
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...)
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...)
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...)
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...)
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...)
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...)
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...)
|
| index_reduce_(...)
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...)
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...)
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...)
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...)
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...)
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...)
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...)
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...)
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...)
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...)
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...)
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...)
|
| is_floating_point(...)
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...)
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...)
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...)
|
| is_pinned(...)
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...)
|
| is_set_to(...)
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_signed(...)
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...)
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...)
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...)
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...)
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...)
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...)
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...)
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| item(...)
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...)
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...)
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...)
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...)
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...)
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...)
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...)
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...)
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...)
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...)
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...)
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...)
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...)
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...)
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...)
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...)
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...)
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...)
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...)
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...)
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...)
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...)
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...)
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...)
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...)
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...)
|
| logaddexp(...)
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...)
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...)
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...)
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...)
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...)
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...)
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...)
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...)
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...)
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...)
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...)
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...)
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...)
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...)
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...)
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lt(...)
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...)
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu_solve(...)
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...)
|
| map_(...)
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...)
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...)
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...)
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...)
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...)
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...)
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...)
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...)
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...)
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...)
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...)
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...)
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...)
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...)
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...)
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...)
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| moveaxis(...)
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...)
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...)
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...)
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...)
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...)
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...)
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...)
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...)
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...)
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...)
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...)
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...)
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...)
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...)
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...)
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...)
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...)
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...)
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...)
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...)
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...)
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...)
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...)
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...)
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...)
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...)
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...)
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...)
|
| new_empty(...)
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...)
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...)
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...)
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...)
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...)
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...)
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...)
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...)
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...)
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| normal_(...)
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...)
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...)
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...)
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...)
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...)
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...)
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...)
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...)
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...)
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...)
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...)
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...)
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...)
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...)
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...)
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...)
|
| prod(...)
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...)
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...)
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...)
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...)
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...)
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...)
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...)
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...)
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...)
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...)
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...)
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...)
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...)
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...)
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...)
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...)
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...)
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| relu(...)
|
| relu_(...)
|
| remainder(...)
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...)
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...)
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...)
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...)
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...)
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...)
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...)
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...)
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize_(...)
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as_(...)
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...)
|
| resolve_conj(...)
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...)
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...)
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...)
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...)
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...)
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...)
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...)
|
| rsqrt(...)
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...)
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...)
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...)
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...)
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...)
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...)
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...)
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...)
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...)
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...)
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...)
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...)
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| short(...)
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...)
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...)
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...)
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...)
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...)
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...)
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...)
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...)
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...)
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...)
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...)
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...)
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...)
|
| slice_scatter(...)
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...)
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...)
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...)
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| sort(...)
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...)
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...)
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...)
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...)
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split_with_sizes(...)
|
| sqrt(...)
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...)
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...)
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...)
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...)
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...)
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...)
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...)
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| storage_offset(...)
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| stride(...)
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...)
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...)
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...)
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...)
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...)
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...)
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...)
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...)
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...)
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...)
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...)
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| t(...)
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...)
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...)
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...)
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...)
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...)
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...)
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...)
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...)
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...)
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...)
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_mkldnn(...)
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...)
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...)
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...)
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...)
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_csc(...)
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...)
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...)
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...)
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...)
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...)
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...)
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...)
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...)
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...)
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...)
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...)
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...)
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...)
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...)
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...)
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...)
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...)
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...)
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unfold(...)
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...)
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unsafe_chunk(...)
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...)
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...)
|
| unsqueeze(...)
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...)
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...)
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...)
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...)
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...)
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...)
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...)
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...)
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...)
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...)
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...)
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...)
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...)
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C.TensorBase:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| dtype
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_cuda
| Is ``True`` if the Tensor is stored on the GPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_sparse
| Is ``True`` if the Tensor uses sparse COO storage layout, ``False`` otherwise.
|
| is_sparse_csr
| Is ``True`` if the Tensor uses sparse CSR storage layout, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| is_xpu
| Is ``True`` if the Tensor is stored on the XPU, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| layout
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
class check_sparse_tensor_invariants(builtins.object)
| check_sparse_tensor_invariants(enable=True)
|
| A tool to control checking sparse tensor invariants.
|
| The following options exists to manage sparsr tensor invariants
| checking in sparse tensor construction:
|
| 1. Using a context manager:
|
| .. code:: python
|
| with torch.sparse.check_sparse_tensor_invariants():
| run_my_model()
|
| 2. Using a procedural approach:
|
| .. code:: python
|
| prev_checks_enabled = torch.sparse.check_sparse_tensor_invariants.is_enabled()
| torch.sparse.check_sparse_tensor_invariants.enable()
|
| run_my_model()
|
| if not prev_checks_enabled:
| torch.sparse.check_sparse_tensor_invariants.disable()
|
| 3. Using function decoration:
|
| .. code:: python
|
| @torch.sparse.check_sparse_tensor_invariants()
| def run_my_model():
| ...
|
| run_my_model()
|
| 4. Using ``check_invariants`` keyword argument in sparse tensor constructor call.
| For example:
|
| >>> torch.sparse_csr_tensor([0, 1, 3], [0, 1], [1, 2], check_invariants=True)
| Traceback (most recent call last):
| File "<stdin>", line 1, in <module>
| RuntimeError: `crow_indices[..., -1] == nnz` is not satisfied.
|
| Methods defined here:
|
| __call__(self, mth)
| Call self as a function.
|
| __enter__(self)
|
| __exit__(self, type, value, traceback)
|
| __init__(self, enable=True)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| disable()
| Disable sparse tensor invariants checking in sparse tensor constructors.
|
| See :func:`torch.sparse.check_sparse_tensor_invariants.enable` for more information.
|
| enable()
| Enable sparse tensor invariants checking in sparse tensor constructors.
|
| .. note::
|
| By default, the sparse tensor invariants checks are disabled. Use
| :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled` to
| retrieve the current state of sparse tensor invariants checking.
|
| .. note::
|
| The sparse tensor invariants check flag is effective to all sparse
| tensor constructors, both in Python and ATen.
|
| The flag can be locally overridden by the ``check_invariants``
| optional argument of the sparse tensor constructor functions.
|
| is_enabled()
| Return True if the sparse tensor invariants checking is enabled.
|
| .. note::
|
| Use :func:`torch.sparse.check_sparse_tensor_invariants.enable` or
| :func:`torch.sparse.check_sparse_tensor_invariants.disable` to
| manage the state of the sparse tensor invariants checks.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
addmm = _sparse_addmm(...)
sparse.addmm(mat, mat1, mat2, *, beta=1., alpha=1.) -> Tensor
This function does exact same thing as :func:`torch.addmm` in the forward,
except that it supports backward for sparse COO and CSR matrix :attr:`mat1`.
When :attr:`mat1` is a COO tensor it must have `sparse_dim = 2`.
Supports both CSR and COO storage formats.
.. note::
**Gradient support:**
- **COO @ Dense**: Backward is supported for both inputs. The gradient for the
sparse input is returned as a sparse COO tensor.
- **CSR @ Dense**: Backward is supported for both inputs. The gradient for the
sparse input is returned as a sparse CSR tensor.
- **CSC/BSR/BSC @ Dense**: Not supported.
- **Sparse @ Sparse** (COO @ COO, CSR @ CSR): Forward works, but backward is
not supported.
Args:
mat (Tensor): a dense matrix to be added
mat1 (Tensor): a sparse matrix to be multiplied
mat2 (Tensor): a dense matrix to be multiplied
beta (Number, optional): multiplier for :attr:`mat` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
as_sparse_gradcheck(gradcheck)
Decorate function, to extend gradcheck for sparse tensors.
Decorator for torch.autograd.gradcheck or its functools.partial
variants that extends the gradcheck function with support to input
functions that operate on or/and return sparse tensors.
The specified gradcheck function itself is guaranteed to operate
on strided tensors only.
For example:
>>> gradcheck = torch.sparse.as_sparse_gradcheck(torch.autograd.gradcheck)
>>> x = (
... torch.tensor([[0, 1], [2, 3]], dtype=torch.float64)
... .to_sparse_coo()
... .requires_grad_(True)
... )
>>> gradcheck(lambda x: x.to_sparse_csr(), x)
True
log_softmax = _sparse_log_softmax(...)
sparse.log_softmax(input, dim, *, dtype=None) -> Tensor
Applies a softmax function followed by logarithm.
See :class:`~torch.sparse.softmax` for more details.
Args:
input (Tensor): input
dim (int): A dimension along which softmax will be computed.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. This is useful for preventing data type
overflows. Default: None
mm = _sparse_mm(...)
Performs a matrix multiplication of the sparse matrix :attr:`mat1`
and the (sparse or strided) matrix :attr:`mat2`. Similar to :func:`torch.mm`, if :attr:`mat1` is a
:math:`(n \times m)` tensor, :attr:`mat2` is a :math:`(m \times p)` tensor, out will be a
:math:`(n \times p)` tensor.
When :attr:`mat1` is a COO tensor it must have `sparse_dim = 2`.
Supports both CSR and COO storage formats.
.. note::
**Gradient support:**
- **COO @ Dense**: Backward is supported for both inputs. The gradient for the
sparse input is returned as a sparse COO tensor.
- **CSR @ Dense**: Backward is supported for both inputs. The gradient for the
sparse input is returned as a sparse CSR tensor.
- **CSC/BSR/BSC @ Dense**: Not supported.
- **Sparse @ Sparse** (COO @ COO, CSR @ CSR): Forward works, but backward is
not supported.
- **Mixed formats** (COO @ CSR, CSR @ COO): Not supported.
This function also additionally accepts an optional :attr:`reduce` argument that allows
specification of an optional reduction operation, mathematically performs the following operation:
.. math::
z_{ij} = \bigoplus_{k = 0}^{K - 1} x_{ik} y_{kj}
where :math:`\bigoplus` defines the reduce operator. :attr:`reduce` is implemented only for
CSR storage format on CPU device.
Args:
mat1 (Tensor): the first sparse matrix to be multiplied
mat2 (Tensor): the second matrix to be multiplied, which could be sparse or dense
reduce (str, optional): the reduction operation to apply for non-unique indices
(:obj:`"sum"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`). Default :obj:`"sum"`.
Shape:
The format of the output tensor of this function follows:
- sparse x sparse -> sparse
- sparse x dense -> dense
Example::
>>> a = torch.tensor([[1., 0, 2], [0, 3, 0]]).to_sparse().requires_grad_()
>>> a
tensor(indices=tensor([[0, 0, 1],
[0, 2, 1]]),
values=tensor([1., 2., 3.]),
size=(2, 3), nnz=3, layout=torch.sparse_coo, requires_grad=True)
>>> b = torch.tensor([[0, 1.], [2, 0], [0, 0]], requires_grad=True)
>>> b
tensor([[0., 1.],
[2., 0.],
[0., 0.]], requires_grad=True)
>>> y = torch.sparse.mm(a, b)
>>> y
tensor([[0., 1.],
[6., 0.]], grad_fn=<SparseAddmmBackward0>)
>>> y.sum().backward()
>>> a.grad
tensor(indices=tensor([[0, 0, 1],
[0, 2, 1]]),
values=tensor([1., 0., 2.]),
size=(2, 3), nnz=3, layout=torch.sparse_coo)
>>> c = a.detach().to_sparse_csr()
>>> c
tensor(crow_indices=tensor([0, 2, 3]),
col_indices=tensor([0, 2, 1]),
values=tensor([1., 2., 3.]), size=(2, 3), nnz=3,
layout=torch.sparse_csr)
>>> y1 = torch.sparse.mm(c, b, 'sum')
>>> y1
tensor([[0., 1.],
[6., 0.]], grad_fn=<SparseMmReduceImplBackward0>)
>>> y2 = torch.sparse.mm(c, b, 'max')
>>> y2
tensor([[0., 1.],
[6., 0.]], grad_fn=<SparseMmReduceImplBackward0>)
softmax = _sparse_softmax(...)
sparse.softmax(input, dim, *, dtype=None) -> Tensor
Applies a softmax function.
Softmax is defined as:
:math:`\text{Softmax}(x_{i}) = \frac{exp(x_i)}{\sum_j exp(x_j)}`
where :math:`i, j` run over sparse tensor indices and unspecified
entries are ignores. This is equivalent to defining unspecified
entries as negative infinity so that :math:`exp(x_k) = 0` when the
entry with index :math:`k` has not specified.
It is applied to all slices along `dim`, and will re-scale them so
that the elements lie in the range `[0, 1]` and sum to 1.
Args:
input (Tensor): input
dim (int): A dimension along which softmax will be computed.
dtype (:class:`torch.dtype`, optional): the desired data type
of returned tensor. If specified, the input tensor is
casted to :attr:`dtype` before the operation is
performed. This is useful for preventing data type
overflows. Default: None
sum(input: torch.Tensor, dim: tuple[int] | None = None, dtype: int | None = None) -> torch.Tensor
Return the sum of each row of the given sparse tensor.
Returns the sum of each row of the sparse tensor :attr:`input` in the given
dimensions :attr:`dim`. If :attr:`dim` is a list of dimensions,
reduce over all of them. When sum over all ``sparse_dim``, this method
returns a dense tensor instead of a sparse tensor.
All summed :attr:`dim` are squeezed (see :func:`torch.squeeze`), resulting an output
tensor having :attr:`dim` fewer dimensions than :attr:`input`.
During backward, only gradients at ``nnz`` locations of :attr:`input`
will propagate back. Note that the gradients of :attr:`input` is coalesced.
Args:
input (Tensor): the input sparse tensor
dim (int or tuple of ints): a dimension or a list of dimensions to reduce. Default: reduce
over all dims.
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: dtype of :attr:`input`.
Example::
>>> nnz = 3
>>> dims = [5, 5, 2, 3]
>>> I = torch.cat([torch.randint(0, dims[0], size=(nnz,)),
torch.randint(0, dims[1], size=(nnz,))], 0).reshape(2, nnz)
>>> V = torch.randn(nnz, dims[2], dims[3])
>>> size = torch.Size(dims)
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> S = torch.sparse_coo_tensor(I, V, size)
>>> S
tensor(indices=tensor([[2, 0, 3],
[2, 4, 1]]),
values=tensor([[[-0.6438, -1.6467, 1.4004],
[ 0.3411, 0.0918, -0.2312]],
[[ 0.5348, 0.0634, -2.0494],
[-0.7125, -1.0646, 2.1844]],
[[ 0.1276, 0.1874, -0.6334],
[-1.9682, -0.5340, 0.7483]]]),
size=(5, 5, 2, 3), nnz=3, layout=torch.sparse_coo)
# when sum over only part of sparse_dims, return a sparse tensor
>>> torch.sparse.sum(S, [1, 3])
tensor(indices=tensor([[0, 2, 3]]),
values=tensor([[-1.4512, 0.4073],
[-0.8901, 0.2017],
[-0.3183, -1.7539]]),
size=(5, 2), nnz=3, layout=torch.sparse_coo)
# when sum over all sparse dim, return a dense tensor
# with summed dims squeezed
>>> torch.sparse.sum(S, [0, 1, 3])
tensor([-2.6596, -1.1450])
to_sparse_semi_structured(original_tensor: torch.Tensor, transposed: bool = False, alg_id: int = 0) -> torch.sparse.semi_structured.SparseSemiStructuredTensor
This function converts a dense tensor into a sparse semi-structured tensor.
It will return a SparseSemiStructuredTensor, a subclass of torch.Tensor.
This function will check to ensure the dense tensor has the right dtype, size, dims, and device.
We currently only support semi-structured sparse tensors for 2d CUDA tensors.
Additionally, your tensor must be a positive multiple of the minimum sparse block size, given in
`_DTYPE_TO_SHAPE_CONSTRAINTS` for each dtype (float32, float16, bfloat16, int8).
Args:
original_tensor (Tensor): the dense tensor to convert
transposed (bool, optional): deprecated arg to be removed in another release. Do not use.
alg_id (int, optional): the algorithm id to use for cuSPARSELt matmul. Defaults to 0.
Can be obtained via ``torch._cslt_sparse_mm_search``.
Returns:
SparseSemiStructuredTensor: A sparse semi-structured tensor created from the given original_tensor
Raises:
None
Example:
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
>>> A = torch.Tensor([0, 0, 1, 1]).tile((128, 32)).half().cuda()
tensor([[0., 0., 1., ..., 0., 1., 1.],
[0., 0., 1., ..., 0., 1., 1.],
[0., 0., 1., ..., 0., 1., 1.],
...,
[0., 0., 1., ..., 0., 1., 1.],
[0., 0., 1., ..., 0., 1., 1.],
[0., 0., 1., ..., 0., 1., 1.]], device='cuda:0', dtype=torch.float16)
>>> A_sparse = to_sparse_semi_structured(A)
SparseSemiStructuredTensor(shape=torch.Size([128, 128]))
>>> A_sparse.values()
tensor([[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
...,
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.]], device='cuda:0', dtype=torch.float16),
>>> A_sparse.indices()
tensor([[-4370, -4370, -4370, ..., -4370, -4370, -4370],
[-4370, -4370, -4370, ..., -4370, -4370, -4370],
[-4370, -4370, -4370, ..., -4370, -4370, -4370],
...,
[-4370, -4370, -4370, ..., -4370, -4370, -4370],
[-4370, -4370, -4370, ..., -4370, -4370, -4370],
[-4370, -4370, -4370, ..., -4370, -4370, -4370]], device='cuda:0', dtype=torch.int16))
DATA
__all__ = ['addmm', 'check_sparse_tensor_invariants', 'mm', 'sum', 'so...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\sparse\__init__.py
torch.sparse_bsc
Python Library Documentation: layout object class layout(builtins.object) | Methods defined here: | | __repr__(self, /) | Return repr(self).
torch.sparse_bsc_tensor
Python Library Documentation: built-in function sparse_bsc_tensor in module torch
sparse_bsc_tensor(...)
sparse_bsc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
Constructs a :ref:`sparse tensor in BSC (Block Compressed Sparse
Column)) <sparse-bsc-docs>` with specified 2-dimensional blocks at the
given :attr:`ccol_indices` and :attr:`row_indices`. Sparse matrix
multiplication operations in BSC format are typically faster than that
for sparse tensors in COO format. Make you have a look at :ref:`the
note on the data type of the indices <sparse-bsc-docs>`.
.. note::
If the ``device`` argument is not specified the device of the given
:attr:`values` and indices tensor(s) must match. If, however, the
argument is specified the input Tensors will be converted to the
given device and in turn determine the device of the constructed
sparse tensor.
Args:
ccol_indices (array_like): (B+1)-dimensional array of size
``(*batchsize, ncolblocks + 1)``. The last element of each
batch is the number of non-zeros. This tensor encodes the
index in values and row_indices depending on where the given
column starts. Each successive number in the tensor subtracted
by the number before it denotes the number of elements in a
given column.
row_indices (array_like): Row block coordinates of each block in
values. (B+1)-dimensional tensor with the same length
as values.
values (array_list): Initial blocks for the tensor. Can be a list,
tuple, NumPy ``ndarray``, and other types that
represents a (1 + 2 + K)-dimensional tensor where ``K`` is the
number of dense dimensions.
size (list, tuple, :class:`torch.Size`, optional): Size of the
sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
blocksize[1], *densesize)`` If not provided, the size will be
inferred as the minimum size big enough to hold all non-zero
blocks.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. Default: if None, infers data type from
:attr:`values`.
device (:class:`torch.device`, optional): the desired device of
returned tensor. Default: if None, uses the current device
for the default tensor type (see
:func:`torch.set_default_device`). :attr:`device` will be
the CPU for CPU tensor types and the current CUDA device for
CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
check_invariants (bool, optional): If sparse tensor invariants are checked.
Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
initially False.
Example::
>>> ccol_indices = [0, 1, 2]
>>> row_indices = [0, 1]
>>> values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
>>> torch.sparse_bsc_tensor(torch.tensor(ccol_indices, dtype=torch.int64),
... torch.tensor(row_indices, dtype=torch.int64),
... torch.tensor(values), dtype=torch.double)
tensor(ccol_indices=tensor([0, 1, 2]),
row_indices=tensor([0, 1]),
values=tensor([[[1., 2.],
[3., 4.]],
[[5., 6.],
[7., 8.]]]), size=(2, 2), nnz=2, dtype=torch.float64,
layout=torch.sparse_bsc)
torch.sparse_bsr
Python Library Documentation: layout object class layout(builtins.object) | Methods defined here: | | __repr__(self, /) | Return repr(self).
torch.sparse_bsr_tensor
Python Library Documentation: built-in function sparse_bsr_tensor in module torch
sparse_bsr_tensor(...)
sparse_bsr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
Constructs a :ref:`sparse tensor in BSR (Block Compressed Sparse Row))
<sparse-bsr-docs>` with specified 2-dimensional blocks at the given
:attr:`crow_indices` and :attr:`col_indices`. Sparse matrix
multiplication operations in BSR format are typically faster than that
for sparse tensors in COO format. Make you have a look at :ref:`the
note on the data type of the indices <sparse-bsr-docs>`.
.. note::
If the ``device`` argument is not specified the device of the given
:attr:`values` and indices tensor(s) must match. If, however, the
argument is specified the input Tensors will be converted to the
given device and in turn determine the device of the constructed
sparse tensor.
Args:
crow_indices (array_like): (B+1)-dimensional array of size
``(*batchsize, nrowblocks + 1)``. The last element of each
batch is the number of non-zeros. This tensor encodes the
block index in values and col_indices depending on where the
given row block starts. Each successive number in the tensor
subtracted by the number before it denotes the number of
blocks in a given row.
col_indices (array_like): Column block coordinates of each block
in values. (B+1)-dimensional tensor with the same length as
values.
values (array_list): Initial values for the tensor. Can be a list,
tuple, NumPy ``ndarray``, scalar, and other types that
represents a (1 + 2 + K)-dimensional tensor where ``K`` is the
number of dense dimensions.
size (list, tuple, :class:`torch.Size`, optional): Size of the
sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
blocksize[1], *densesize)`` where ``blocksize ==
values.shape[1:3]``. If not provided, the size will be
inferred as the minimum size big enough to hold all non-zero
blocks.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. Default: if None, infers data type from
:attr:`values`.
device (:class:`torch.device`, optional): the desired device of
returned tensor. Default: if None, uses the current device
for the default tensor type (see
:func:`torch.set_default_device`). :attr:`device` will be
the CPU for CPU tensor types and the current CUDA device for
CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
check_invariants (bool, optional): If sparse tensor invariants are checked.
Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
initially False.
Example::
>>> crow_indices = [0, 1, 2]
>>> col_indices = [0, 1]
>>> values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
>>> torch.sparse_bsr_tensor(torch.tensor(crow_indices, dtype=torch.int64),
... torch.tensor(col_indices, dtype=torch.int64),
... torch.tensor(values), dtype=torch.double)
tensor(crow_indices=tensor([0, 1, 2]),
col_indices=tensor([0, 1]),
values=tensor([[[1., 2.],
[3., 4.]],
[[5., 6.],
[7., 8.]]]), size=(2, 2), nnz=2, dtype=torch.float64,
layout=torch.sparse_bsr)
torch.sparse_compressed_tensor
Python Library Documentation: built-in function sparse_compressed_tensor in module torch
sparse_compressed_tensor(...)
sparse_compressed_tensor(compressed_indices, plain_indices, values, size=None, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
Constructs a :ref:`sparse tensor in Compressed Sparse format - CSR,
CSC, BSR, or BSC - <sparse-compressed-docs>` with specified values at
the given :attr:`compressed_indices` and :attr:`plain_indices`. Sparse
matrix multiplication operations in Compressed Sparse format are
typically faster than that for sparse tensors in COO format. Make you
have a look at :ref:`the note on the data type of the indices
<sparse-compressed-docs>`.
.. note::
If the ``device`` argument is not specified the device of the given
:attr:`values` and indices tensor(s) must match. If, however, the
argument is specified the input Tensors will be converted to the
given device and in turn determine the device of the constructed
sparse tensor.
Args:
compressed_indices (array_like): (B+1)-dimensional array of size
``(*batchsize, compressed_dim_size + 1)``. The last element of
each batch is the number of non-zero elements or blocks. This
tensor encodes the index in ``values`` and ``plain_indices``
depending on where the given compressed dimension (row or
column) starts. Each successive number in the tensor
subtracted by the number before it denotes the number of
elements or blocks in a given compressed dimension.
plain_indices (array_like): Plain dimension (column or row)
coordinates of each element or block in values. (B+1)-dimensional
tensor with the same length as values.
values (array_list): Initial values for the tensor. Can be a list,
tuple, NumPy ``ndarray``, scalar, and other types. that
represents a (1+K)-dimensional (for CSR and CSC layouts) or
(1+2+K)-dimensional tensor (for BSR and BSC layouts) where
``K`` is the number of dense dimensions.
size (list, tuple, :class:`torch.Size`, optional): Size of the
sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
blocksize[1], *densesize)`` where ``blocksize[0] ==
blocksize[1] == 1`` for CSR and CSC formats. If not provided,
the size will be inferred as the minimum size big enough to
hold all non-zero elements or blocks.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. Default: if None, infers data type from
:attr:`values`.
layout (:class:`torch.layout`, required): the desired layout of
returned tensor: :attr:`torch.sparse_csr`,
:attr:`torch.sparse_csc`, :attr:`torch.sparse_bsr`, or
:attr:`torch.sparse_bsc`.
device (:class:`torch.device`, optional): the desired device of
returned tensor. Default: if None, uses the current device
for the default tensor type (see
:func:`torch.set_default_device`). :attr:`device` will be
the CPU for CPU tensor types and the current CUDA device for
CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
check_invariants (bool, optional): If sparse tensor invariants are checked.
Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
initially False.
Example::
>>> compressed_indices = [0, 2, 4]
>>> plain_indices = [0, 1, 0, 1]
>>> values = [1, 2, 3, 4]
>>> torch.sparse_compressed_tensor(torch.tensor(compressed_indices, dtype=torch.int64),
... torch.tensor(plain_indices, dtype=torch.int64),
... torch.tensor(values), dtype=torch.double, layout=torch.sparse_csr)
tensor(crow_indices=tensor([0, 2, 4]),
col_indices=tensor([0, 1, 0, 1]),
values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
dtype=torch.float64, layout=torch.sparse_csr)
torch.sparse_coo
Python Library Documentation: layout object class layout(builtins.object) | Methods defined here: | | __repr__(self, /) | Return repr(self).
torch.sparse_coo_tensor
Python Library Documentation: built-in function sparse_coo_tensor in module torch
sparse_coo_tensor(...)
sparse_coo_tensor(indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None, is_coalesced=None) -> Tensor
Constructs a :ref:`sparse tensor in COO(rdinate) format
<sparse-coo-docs>` with specified values at the given
:attr:`indices`.
.. note::
This function returns an :ref:`uncoalesced tensor
<sparse-uncoalesced-coo-docs>` when :attr:`is_coalesced` is
unspecified or ``None``.
.. note::
If the ``device`` argument is not specified the device of the given
:attr:`values` and indices tensor(s) must match. If, however, the
argument is specified the input Tensors will be converted to the
given device and in turn determine the device of the constructed
sparse tensor.
Args:
indices (array_like): Initial data for the tensor. Can be a list, tuple,
NumPy ``ndarray``, scalar, and other types. Will be cast to a :class:`torch.LongTensor`
internally. The indices are the coordinates of the non-zero values in the matrix, and thus
should be two-dimensional where the first dimension is the number of tensor dimensions and
the second dimension is the number of non-zero values.
values (array_like): Initial values for the tensor. Can be a list, tuple,
NumPy ``ndarray``, scalar, and other types.
size (list, tuple, or :class:`torch.Size`, optional): Size of the sparse tensor. If not
provided the size will be inferred as the minimum size big enough to hold all non-zero
elements.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if None, infers data type from :attr:`values`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if None, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
check_invariants (bool, optional): If sparse tensor invariants are checked.
Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
initially False.
is_coalesced (bool, optional): When``True``, the caller is
responsible for providing tensor indices that correspond to a
coalesced tensor. If the :attr:`check_invariants` flag is
False, no error will be raised if the prerequisites are not
met and this will lead to silently incorrect results. To force
coalescing please use :meth:`coalesce` on the resulting
Tensor.
Default: None: except for trivial cases (e.g. nnz < 2) the
resulting Tensor has is_coalesced set to ``False```.
Example::
>>> i = torch.tensor([[0, 1, 1],
... [2, 0, 2]])
>>> v = torch.tensor([3, 4, 5], dtype=torch.float32)
>>> torch.sparse_coo_tensor(i, v, [2, 4])
tensor(indices=tensor([[0, 1, 1],
[2, 0, 2]]),
values=tensor([3., 4., 5.]),
size=(2, 4), nnz=3, layout=torch.sparse_coo)
>>> torch.sparse_coo_tensor(i, v) # Shape inference
tensor(indices=tensor([[0, 1, 1],
[2, 0, 2]]),
values=tensor([3., 4., 5.]),
size=(2, 3), nnz=3, layout=torch.sparse_coo)
>>> torch.sparse_coo_tensor(i, v, [2, 4],
... dtype=torch.float64,
... device=torch.device('cuda:0'))
tensor(indices=tensor([[0, 1, 1],
[2, 0, 2]]),
values=tensor([3., 4., 5.]),
device='cuda:0', size=(2, 4), nnz=3, dtype=torch.float64,
layout=torch.sparse_coo)
# Create an empty sparse tensor with the following invariants:
# 1. sparse_dim + dense_dim = len(SparseTensor.shape)
# 2. SparseTensor._indices().shape = (sparse_dim, nnz)
# 3. SparseTensor._values().shape = (nnz, SparseTensor.shape[sparse_dim:])
#
# For instance, to create an empty sparse tensor with nnz = 0, dense_dim = 0 and
# sparse_dim = 1 (hence indices is a 2D tensor of shape = (1, 0))
>>> S = torch.sparse_coo_tensor(torch.empty([1, 0]), [], [1])
tensor(indices=tensor([], size=(1, 0)),
values=tensor([], size=(0,)),
size=(1,), nnz=0, layout=torch.sparse_coo)
# and to create an empty sparse tensor with nnz = 0, dense_dim = 1 and
# sparse_dim = 1
>>> S = torch.sparse_coo_tensor(torch.empty([1, 0]), torch.empty([0, 2]), [1, 2])
tensor(indices=tensor([], size=(1, 0)),
values=tensor([], size=(0, 2)),
size=(1, 2), nnz=0, layout=torch.sparse_coo)
.. _torch.sparse: https://pytorch.org/docs/stable/sparse.html
torch.sparse_csc
Python Library Documentation: layout object class layout(builtins.object) | Methods defined here: | | __repr__(self, /) | Return repr(self).
torch.sparse_csc_tensor
Python Library Documentation: built-in function sparse_csc_tensor in module torch
sparse_csc_tensor(...)
sparse_csc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
Constructs a :ref:`sparse tensor in CSC (Compressed Sparse Column)
<sparse-csc-docs>` with specified values at the given
:attr:`ccol_indices` and :attr:`row_indices`. Sparse matrix
multiplication operations in CSC format are typically faster than that
for sparse tensors in COO format. Make you have a look at :ref:`the
note on the data type of the indices <sparse-csc-docs>`.
.. note::
If the ``device`` argument is not specified the device of the given
:attr:`values` and indices tensor(s) must match. If, however, the
argument is specified the input Tensors will be converted to the
given device and in turn determine the device of the constructed
sparse tensor.
Args:
ccol_indices (array_like): (B+1)-dimensional array of size
``(*batchsize, ncols + 1)``. The last element of each batch
is the number of non-zeros. This tensor encodes the index in
values and row_indices depending on where the given column
starts. Each successive number in the tensor subtracted by the
number before it denotes the number of elements in a given
column.
row_indices (array_like): Row coordinates of each element in
values. (B+1)-dimensional tensor with the same length as
values.
values (array_list): Initial values for the tensor. Can be a list,
tuple, NumPy ``ndarray``, scalar, and other types that
represents a (1+K)-dimensional tensor where ``K`` is the number
of dense dimensions.
size (list, tuple, :class:`torch.Size`, optional): Size of the
sparse tensor: ``(*batchsize, nrows, ncols, *densesize)``. If
not provided, the size will be inferred as the minimum size
big enough to hold all non-zero elements.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. Default: if None, infers data type from
:attr:`values`.
device (:class:`torch.device`, optional): the desired device of
returned tensor. Default: if None, uses the current device
for the default tensor type (see
:func:`torch.set_default_device`). :attr:`device` will be
the CPU for CPU tensor types and the current CUDA device for
CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
check_invariants (bool, optional): If sparse tensor invariants are checked.
Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
initially False.
Example::
>>> ccol_indices = [0, 2, 4]
>>> row_indices = [0, 1, 0, 1]
>>> values = [1, 2, 3, 4]
>>> torch.sparse_csc_tensor(torch.tensor(ccol_indices, dtype=torch.int64),
... torch.tensor(row_indices, dtype=torch.int64),
... torch.tensor(values), dtype=torch.double)
tensor(ccol_indices=tensor([0, 2, 4]),
row_indices=tensor([0, 1, 0, 1]),
values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
dtype=torch.float64, layout=torch.sparse_csc)
torch.sparse_csr
Python Library Documentation: layout object class layout(builtins.object) | Methods defined here: | | __repr__(self, /) | Return repr(self).
torch.sparse_csr_tensor
Python Library Documentation: built-in function sparse_csr_tensor in module torch
sparse_csr_tensor(...)
sparse_csr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
Constructs a :ref:`sparse tensor in CSR (Compressed Sparse Row) <sparse-csr-docs>` with specified
values at the given :attr:`crow_indices` and :attr:`col_indices`. Sparse matrix multiplication operations
in CSR format are typically faster than that for sparse tensors in COO format. Make you have a look
at :ref:`the note on the data type of the indices <sparse-csr-docs>`.
.. note::
If the ``device`` argument is not specified the device of the given
:attr:`values` and indices tensor(s) must match. If, however, the
argument is specified the input Tensors will be converted to the
given device and in turn determine the device of the constructed
sparse tensor.
Args:
crow_indices (array_like): (B+1)-dimensional array of size
``(*batchsize, nrows + 1)``. The last element of each batch
is the number of non-zeros. This tensor encodes the index in
values and col_indices depending on where the given row
starts. Each successive number in the tensor subtracted by the
number before it denotes the number of elements in a given
row.
col_indices (array_like): Column coordinates of each element in
values. (B+1)-dimensional tensor with the same length
as values.
values (array_list): Initial values for the tensor. Can be a list,
tuple, NumPy ``ndarray``, scalar, and other types that
represents a (1+K)-dimensional tensor where ``K`` is the number
of dense dimensions.
size (list, tuple, :class:`torch.Size`, optional): Size of the
sparse tensor: ``(*batchsize, nrows, ncols, *densesize)``. If
not provided, the size will be inferred as the minimum size
big enough to hold all non-zero elements.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. Default: if None, infers data type from
:attr:`values`.
device (:class:`torch.device`, optional): the desired device of
returned tensor. Default: if None, uses the current device
for the default tensor type (see
:func:`torch.set_default_device`). :attr:`device` will be
the CPU for CPU tensor types and the current CUDA device for
CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
check_invariants (bool, optional): If sparse tensor invariants are checked.
Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
initially False.
Example::
>>> crow_indices = [0, 2, 4]
>>> col_indices = [0, 1, 0, 1]
>>> values = [1, 2, 3, 4]
>>> torch.sparse_csr_tensor(torch.tensor(crow_indices, dtype=torch.int64),
... torch.tensor(col_indices, dtype=torch.int64),
... torch.tensor(values), dtype=torch.double)
tensor(crow_indices=tensor([0, 2, 4]),
col_indices=tensor([0, 1, 0, 1]),
values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
dtype=torch.float64, layout=torch.sparse_csr)
torch.special
Python Library Documentation: package torch.special in torch
NAME
torch.special
PACKAGE CONTENTS
FUNCTIONS
airy_ai = special_airy_ai(...)
airy_ai(input, *, out=None) -> Tensor
Airy function :math:`\text{Ai}\left(\text{input}\right)`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
bessel_j0 = special_bessel_j0(...)
bessel_j0(input, *, out=None) -> Tensor
Bessel function of the first kind of order :math:`0`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
bessel_j1 = special_bessel_j1(...)
bessel_j1(input, *, out=None) -> Tensor
Bessel function of the first kind of order :math:`1`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
bessel_y0 = special_bessel_y0(...)
bessel_y0(input, *, out=None) -> Tensor
Bessel function of the second kind of order :math:`0`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
bessel_y1 = special_bessel_y1(...)
bessel_y1(input, *, out=None) -> Tensor
Bessel function of the second kind of order :math:`1`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
chebyshev_polynomial_t = special_chebyshev_polynomial_t(...)
chebyshev_polynomial_t(input, n, *, out=None) -> Tensor
Chebyshev polynomial of the first kind :math:`T_{n}(\text{input})`.
If :math:`n = 0`, :math:`1` is returned. If :math:`n = 1`, :math:`\text{input}`
is returned. If :math:`n < 6` or :math:`|\text{input}| > 1` the recursion:
.. math::
T_{n + 1}(\text{input}) = 2 \times \text{input} \times T_{n}(\text{input}) - T_{n - 1}(\text{input})
is evaluated. Otherwise, the explicit trigonometric formula:
.. math::
T_{n}(\text{input}) = \text{cos}(n \times \text{arccos}(x))
is evaluated.
Args:
input (Tensor): the input tensor.
n (Tensor): Degree of the polynomial.
Keyword args:
out (Tensor, optional): the output tensor.
chebyshev_polynomial_u = special_chebyshev_polynomial_u(...)
chebyshev_polynomial_u(input, n, *, out=None) -> Tensor
Chebyshev polynomial of the second kind :math:`U_{n}(\text{input})`.
If :math:`n = 0`, :math:`1` is returned. If :math:`n = 1`,
:math:`2 \times \text{input}` is returned. If :math:`n < 6` or
:math:`|\text{input}| > 1`, the recursion:
.. math::
U_{n + 1}(\text{input}) = 2 \times \text{input} \times U_{n}(\text{input}) - U_{n - 1}(\text{input})
is evaluated. Otherwise, the explicit trigonometric formula:
.. math::
\frac{\text{sin}((n + 1) \times \text{arccos}(\text{input}))}{\text{sin}(\text{arccos}(\text{input}))}
is evaluated.
Args:
input (Tensor): the input tensor.
n (Tensor): Degree of the polynomial.
Keyword args:
out (Tensor, optional): the output tensor.
chebyshev_polynomial_v = special_chebyshev_polynomial_v(...)
chebyshev_polynomial_v(input, n, *, out=None) -> Tensor
Chebyshev polynomial of the third kind :math:`V_{n}^{\ast}(\text{input})`.
Args:
input (Tensor): the input tensor.
n (Tensor): Degree of the polynomial.
Keyword args:
out (Tensor, optional): the output tensor.
chebyshev_polynomial_w = special_chebyshev_polynomial_w(...)
chebyshev_polynomial_w(input, n, *, out=None) -> Tensor
Chebyshev polynomial of the fourth kind :math:`W_{n}^{\ast}(\text{input})`.
Args:
input (Tensor): the input tensor.
n (Tensor): Degree of the polynomial.
Keyword args:
out (Tensor, optional): the output tensor.
digamma = special_digamma(...)
digamma(input, *, out=None) -> Tensor
Computes the logarithmic derivative of the gamma function on `input`.
.. math::
\digamma(x) = \frac{d}{dx} \ln\left(\Gamma\left(x\right)\right) = \frac{\Gamma'(x)}{\Gamma(x)}
Args:
input (Tensor): the tensor to compute the digamma function on
Keyword args:
out (Tensor, optional): the output tensor.
.. note:: This function is similar to SciPy's `scipy.special.digamma`.
.. note:: From PyTorch 1.8 onwards, the digamma function returns `-Inf` for `0`.
Previously it returned `NaN` for `0`.
Example::
>>> a = torch.tensor([1, 0.5])
>>> torch.special.digamma(a)
tensor([-0.5772, -1.9635])
entr = special_entr(...)
entr(input, *, out=None) -> Tensor
Computes the entropy on :attr:`input` (as defined below), elementwise.
.. math::
\begin{align}
\text{entr(x)} = \begin{cases}
-x * \ln(x) & x > 0 \\
0 & x = 0.0 \\
-\infty & x < 0
\end{cases}
\end{align}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.arange(-0.5, 1, 0.5)
>>> a
tensor([-0.5000, 0.0000, 0.5000])
>>> torch.special.entr(a)
tensor([ -inf, 0.0000, 0.3466])
erf = special_erf(...)
erf(input, *, out=None) -> Tensor
Computes the error function of :attr:`input`. The error function is defined as follows:
.. math::
\mathrm{erf}(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^2} dt
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.special.erf(torch.tensor([0, -1., 10.]))
tensor([ 0.0000, -0.8427, 1.0000])
erfc = special_erfc(...)
erfc(input, *, out=None) -> Tensor
Computes the complementary error function of :attr:`input`.
The complementary error function is defined as follows:
.. math::
\mathrm{erfc}(x) = 1 - \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^2} dt
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.special.erfc(torch.tensor([0, -1., 10.]))
tensor([ 1.0000, 1.8427, 0.0000])
erfcx = special_erfcx(...)
erfcx(input, *, out=None) -> Tensor
Computes the scaled complementary error function for each element of :attr:`input`.
The scaled complementary error function is defined as follows:
.. math::
\mathrm{erfcx}(x) = e^{x^2} \mathrm{erfc}(x)
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.special.erfcx(torch.tensor([0, -1., 10.]))
tensor([ 1.0000, 5.0090, 0.0561])
erfinv = special_erfinv(...)
erfinv(input, *, out=None) -> Tensor
Computes the inverse error function of :attr:`input`.
The inverse error function is defined in the range :math:`(-1, 1)` as:
.. math::
\mathrm{erfinv}(\mathrm{erf}(x)) = x
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.special.erfinv(torch.tensor([0, 0.5, -1.]))
tensor([ 0.0000, 0.4769, -inf])
exp2 = special_exp2(...)
exp2(input, *, out=None) -> Tensor
Computes the base two exponential function of :attr:`input`.
.. math::
y_{i} = 2^{x_{i}}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.special.exp2(torch.tensor([0, math.log2(2.), 3, 4]))
tensor([ 1., 2., 8., 16.])
expit = special_expit(...)
expit(input, *, out=None) -> Tensor
Computes the expit (also known as the logistic sigmoid function) of the elements of :attr:`input`.
.. math::
\text{out}_{i} = \frac{1}{1 + e^{-\text{input}_{i}}}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.randn(4)
>>> t
tensor([ 0.9213, 1.0887, -0.8858, -1.7683])
>>> torch.special.expit(t)
tensor([ 0.7153, 0.7481, 0.2920, 0.1458])
expm1 = special_expm1(...)
expm1(input, *, out=None) -> Tensor
Computes the exponential of the elements minus 1
of :attr:`input`.
.. math::
y_{i} = e^{x_{i}} - 1
.. note:: This function provides greater precision than exp(x) - 1 for small values of x.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.special.expm1(torch.tensor([0, math.log(2.)]))
tensor([ 0., 1.])
gammainc = special_gammainc(...)
gammainc(input, other, *, out=None) -> Tensor
Computes the regularized lower incomplete gamma function:
.. math::
\text{out}_{i} = \frac{1}{\Gamma(\text{input}_i)} \int_0^{\text{other}_i} t^{\text{input}_i-1} e^{-t} dt
where both :math:`\text{input}_i` and :math:`\text{other}_i` are weakly positive
and at least one is strictly positive.
If both are zero or either is negative then :math:`\text{out}_i=\text{nan}`.
:math:`\Gamma(\cdot)` in the equation above is the gamma function,
.. math::
\Gamma(\text{input}_i) = \int_0^\infty t^{(\text{input}_i-1)} e^{-t} dt.
See :func:`torch.special.gammaincc` and :func:`torch.special.gammaln` for related functions.
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`
and float inputs.
.. note::
The backward pass with respect to :attr:`input` is not yet supported.
Please open an issue on PyTorch's Github to request it.
Args:
input (Tensor): the first non-negative input tensor
other (Tensor): the second non-negative input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a1 = torch.tensor([4.0])
>>> a2 = torch.tensor([3.0, 4.0, 5.0])
>>> a = torch.special.gammaincc(a1, a2)
tensor([0.3528, 0.5665, 0.7350])
tensor([0.3528, 0.5665, 0.7350])
>>> b = torch.special.gammainc(a1, a2) + torch.special.gammaincc(a1, a2)
tensor([1., 1., 1.])
gammaincc = special_gammaincc(...)
gammaincc(input, other, *, out=None) -> Tensor
Computes the regularized upper incomplete gamma function:
.. math::
\text{out}_{i} = \frac{1}{\Gamma(\text{input}_i)} \int_{\text{other}_i}^{\infty} t^{\text{input}_i-1} e^{-t} dt
where both :math:`\text{input}_i` and :math:`\text{other}_i` are weakly positive
and at least one is strictly positive.
If both are zero or either is negative then :math:`\text{out}_i=\text{nan}`.
:math:`\Gamma(\cdot)` in the equation above is the gamma function,
.. math::
\Gamma(\text{input}_i) = \int_0^\infty t^{(\text{input}_i-1)} e^{-t} dt.
See :func:`torch.special.gammainc` and :func:`torch.special.gammaln` for related functions.
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`
and float inputs.
.. note::
The backward pass with respect to :attr:`input` is not yet supported.
Please open an issue on PyTorch's Github to request it.
Args:
input (Tensor): the first non-negative input tensor
other (Tensor): the second non-negative input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a1 = torch.tensor([4.0])
>>> a2 = torch.tensor([3.0, 4.0, 5.0])
>>> a = torch.special.gammaincc(a1, a2)
tensor([0.6472, 0.4335, 0.2650])
>>> b = torch.special.gammainc(a1, a2) + torch.special.gammaincc(a1, a2)
tensor([1., 1., 1.])
gammaln = special_gammaln(...)
gammaln(input, *, out=None) -> Tensor
Computes the natural logarithm of the absolute value of the gamma function on :attr:`input`.
.. math::
\text{out}_{i} = \ln \Gamma(|\text{input}_{i}|)
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.arange(0.5, 2, 0.5)
>>> torch.special.gammaln(a)
tensor([ 0.5724, 0.0000, -0.1208])
hermite_polynomial_h = special_hermite_polynomial_h(...)
hermite_polynomial_h(input, n, *, out=None) -> Tensor
Physicist's Hermite polynomial :math:`H_{n}(\text{input})`.
If :math:`n = 0`, :math:`1` is returned. If :math:`n = 1`, :math:`\text{input}`
is returned. Otherwise, the recursion:
.. math::
H_{n + 1}(\text{input}) = 2 \times \text{input} \times H_{n}(\text{input}) - H_{n - 1}(\text{input})
is evaluated.
Args:
input (Tensor): the input tensor.
n (Tensor): Degree of the polynomial.
Keyword args:
out (Tensor, optional): the output tensor.
hermite_polynomial_he = special_hermite_polynomial_he(...)
hermite_polynomial_he(input, n, *, out=None) -> Tensor
Probabilist's Hermite polynomial :math:`He_{n}(\text{input})`.
If :math:`n = 0`, :math:`1` is returned. If :math:`n = 1`, :math:`\text{input}`
is returned. Otherwise, the recursion:
.. math::
He_{n + 1}(\text{input}) = 2 \times \text{input} \times He_{n}(\text{input}) - He_{n - 1}(\text{input})
is evaluated.
Args:
input (Tensor): the input tensor.
n (Tensor): Degree of the polynomial.
Keyword args:
out (Tensor, optional): the output tensor.
i0 = special_i0(...)
i0(input, *, out=None) -> Tensor
Computes the zeroth order modified Bessel function of the first kind for each element of :attr:`input`.
.. math::
\text{out}_{i} = I_0(\text{input}_{i}) = \sum_{k=0}^{\infty} \frac{(\text{input}_{i}^2/4)^k}{(k!)^2}
Args:
input (Tensor): the input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.i0(torch.arange(5, dtype=torch.float32))
tensor([ 1.0000, 1.2661, 2.2796, 4.8808, 11.3019])
i0e = special_i0e(...)
i0e(input, *, out=None) -> Tensor
Computes the exponentially scaled zeroth order modified Bessel function of the first kind (as defined below)
for each element of :attr:`input`.
.. math::
\text{out}_{i} = \exp(-|x|) * i0(x) = \exp(-|x|) * \sum_{k=0}^{\infty} \frac{(\text{input}_{i}^2/4)^k}{(k!)^2}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.special.i0e(torch.arange(5, dtype=torch.float32))
tensor([1.0000, 0.4658, 0.3085, 0.2430, 0.2070])
i1 = special_i1(...)
i1(input, *, out=None) -> Tensor
Computes the first order modified Bessel function of the first kind (as defined below)
for each element of :attr:`input`.
.. math::
\text{out}_{i} = \frac{(\text{input}_{i})}{2} * \sum_{k=0}^{\infty} \frac{(\text{input}_{i}^2/4)^k}{(k!) * (k+1)!}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.special.i1(torch.arange(5, dtype=torch.float32))
tensor([0.0000, 0.5652, 1.5906, 3.9534, 9.7595])
i1e = special_i1e(...)
i1e(input, *, out=None) -> Tensor
Computes the exponentially scaled first order modified Bessel function of the first kind (as defined below)
for each element of :attr:`input`.
.. math::
\text{out}_{i} = \exp(-|x|) * i1(x) =
\exp(-|x|) * \frac{(\text{input}_{i})}{2} * \sum_{k=0}^{\infty} \frac{(\text{input}_{i}^2/4)^k}{(k!) * (k+1)!}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.special.i1e(torch.arange(5, dtype=torch.float32))
tensor([0.0000, 0.2079, 0.2153, 0.1968, 0.1788])
laguerre_polynomial_l = special_laguerre_polynomial_l(...)
laguerre_polynomial_l(input, n, *, out=None) -> Tensor
Laguerre polynomial :math:`L_{n}(\text{input})`.
If :math:`n = 0`, :math:`1` is returned. If :math:`n = 1`, :math:`\text{input}`
is returned. Otherwise, the recursion:
.. math::
L_{n + 1}(\text{input}) = 2 \times \text{input} \times L_{n}(\text{input}) - L_{n - 1}(\text{input})
is evaluated.
Args:
input (Tensor): the input tensor.
n (Tensor): Degree of the polynomial.
Keyword args:
out (Tensor, optional): the output tensor.
legendre_polynomial_p = special_legendre_polynomial_p(...)
legendre_polynomial_p(input, n, *, out=None) -> Tensor
Legendre polynomial :math:`P_{n}(\text{input})`.
If :math:`n = 0`, :math:`1` is returned. If :math:`n = 1`, :math:`\text{input}`
is returned. Otherwise, the recursion:
.. math::
P_{n + 1}(\text{input}) = 2 \times \text{input} \times P_{n}(\text{input}) - P_{n - 1}(\text{input})
is evaluated.
Args:
input (Tensor): the input tensor.
n (Tensor): Degree of the polynomial.
Keyword args:
out (Tensor, optional): the output tensor.
log1p = special_log1p(...)
log1p(input, *, out=None) -> Tensor
Alias for :func:`torch.log1p`.
log_ndtr = special_log_ndtr(...)
log_ndtr(input, *, out=None) -> Tensor
Computes the log of the area under the standard Gaussian probability density function,
integrated from minus infinity to :attr:`input`, elementwise.
.. math::
\text{log\_ndtr}(x) = \log\left(\frac{1}{\sqrt{2 \pi}}\int_{-\infty}^{x} e^{-\frac{1}{2}t^2} dt \right)
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.special.log_ndtr(torch.tensor([-3., -2, -1, 0, 1, 2, 3]))
tensor([-6.6077 -3.7832 -1.841 -0.6931 -0.1728 -0.023 -0.0014])
log_softmax = special_log_softmax(...)
log_softmax(input, dim, *, dtype=None) -> Tensor
Computes softmax followed by a logarithm.
While mathematically equivalent to log(softmax(x)), doing these two
operations separately is slower and numerically unstable. This function
is computed as:
.. math::
\text{log\_softmax}(x_{i}) = \log\left(\frac{\exp(x_i) }{ \sum_j \exp(x_j)} \right)
Args:
input (Tensor): input
dim (int): A dimension along which log_softmax will be computed.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is cast to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> t = torch.ones(2, 2)
>>> torch.special.log_softmax(t, 0)
tensor([[-0.6931, -0.6931],
[-0.6931, -0.6931]])
logit = special_logit(...)
logit(input, eps=None, *, out=None) -> Tensor
Returns a new tensor with the logit of the elements of :attr:`input`.
:attr:`input` is clamped to [eps, 1 - eps] when eps is not None.
When eps is None and :attr:`input` < 0 or :attr:`input` > 1, the function will yield NaN.
.. math::
\begin{align}
y_{i} &= \ln(\frac{z_{i}}{1 - z_{i}}) \\
z_{i} &= \begin{cases}
x_{i} & \text{if eps is None} \\
\text{eps} & \text{if } x_{i} < \text{eps} \\
x_{i} & \text{if } \text{eps} \leq x_{i} \leq 1 - \text{eps} \\
1 - \text{eps} & \text{if } x_{i} > 1 - \text{eps}
\end{cases}
\end{align}
Args:
input (Tensor): the input tensor.
eps (float, optional): the epsilon for input clamp bound. Default: ``None``
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(5)
>>> a
tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516])
>>> torch.special.logit(a, eps=1e-6)
tensor([-0.9466, 2.6352, 0.6131, -1.7169, 0.6261])
logsumexp = special_logsumexp(...)
logsumexp(input, dim, keepdim=False, *, out=None)
Alias for :func:`torch.logsumexp`.
modified_bessel_i0 = special_modified_bessel_i0(...)
modified_bessel_i0(input, *, out=None) -> Tensor
Modified Bessel function of the first kind of order :math:`0`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
modified_bessel_i1 = special_modified_bessel_i1(...)
modified_bessel_i1(input, *, out=None) -> Tensor
Modified Bessel function of the first kind of order :math:`1`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
modified_bessel_k0 = special_modified_bessel_k0(...)
modified_bessel_k0(input, *, out=None) -> Tensor
Modified Bessel function of the second kind of order :math:`0`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
modified_bessel_k1 = special_modified_bessel_k1(...)
modified_bessel_k1(input, *, out=None) -> Tensor
Modified Bessel function of the second kind of order :math:`1`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
multigammaln = special_multigammaln(...)
multigammaln(input, p, *, out=None) -> Tensor
Computes the `multivariate log-gamma function
<https://en.wikipedia.org/wiki/Multivariate_gamma_function>`_ with dimension
:math:`p` element-wise, given by
.. math::
\log(\Gamma_{p}(a)) = C + \displaystyle \sum_{i=1}^{p} \log\left(\Gamma\left(a - \frac{i - 1}{2}\right)\right)
where :math:`C = \log(\pi) \cdot \frac{p (p - 1)}{4}` and :math:`\Gamma(-)` is the Gamma function.
All elements must be greater than :math:`\frac{p - 1}{2}`, otherwise the behavior is undefined.
Args:
input (Tensor): the tensor to compute the multivariate log-gamma function
p (int): the number of dimensions
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.empty(2, 3).uniform_(1, 2)
>>> a
tensor([[1.6835, 1.8474, 1.1929],
[1.0475, 1.7162, 1.4180]])
>>> torch.special.multigammaln(a, 2)
tensor([[0.3928, 0.4007, 0.7586],
[1.0311, 0.3901, 0.5049]])
ndtr = special_ndtr(...)
ndtr(input, *, out=None) -> Tensor
Computes the area under the standard Gaussian probability density function,
integrated from minus infinity to :attr:`input`, elementwise.
.. math::
\text{ndtr}(x) = \frac{1}{\sqrt{2 \pi}}\int_{-\infty}^{x} e^{-\frac{1}{2}t^2} dt
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.special.ndtr(torch.tensor([-3., -2, -1, 0, 1, 2, 3]))
tensor([0.0013, 0.0228, 0.1587, 0.5000, 0.8413, 0.9772, 0.9987])
ndtri = special_ndtri(...)
ndtri(input, *, out=None) -> Tensor
Computes the argument, x, for which the area under the Gaussian probability density function
(integrated from minus infinity to x) is equal to :attr:`input`, elementwise.
.. math::
\text{ndtri}(p) = \sqrt{2}\text{erf}^{-1}(2p - 1)
.. note::
Also known as quantile function for Normal Distribution.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.special.ndtri(torch.tensor([0, 0.25, 0.5, 0.75, 1]))
tensor([ -inf, -0.6745, 0.0000, 0.6745, inf])
polygamma = special_polygamma(...)
polygamma(n, input, *, out=None) -> Tensor
Computes the :math:`n^{th}` derivative of the digamma function on :attr:`input`.
:math:`n \geq 0` is called the order of the polygamma function.
.. math::
\psi^{(n)}(x) = \frac{d^{(n)}}{dx^{(n)}} \psi(x)
.. note::
This function is implemented only for nonnegative integers :math:`n \geq 0`.
Args:
n (int): the order of the polygamma function
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([1, 0.5])
>>> torch.special.polygamma(1, a)
tensor([1.64493, 4.9348])
>>> torch.special.polygamma(2, a)
tensor([ -2.4041, -16.8288])
>>> torch.special.polygamma(3, a)
tensor([ 6.4939, 97.4091])
>>> torch.special.polygamma(4, a)
tensor([ -24.8863, -771.4742])
psi = special_psi(...)
psi(input, *, out=None) -> Tensor
Alias for :func:`torch.special.digamma`.
round = special_round(...)
round(input, *, out=None) -> Tensor
Alias for :func:`torch.round`.
scaled_modified_bessel_k0 = special_scaled_modified_bessel_k0(...)
scaled_modified_bessel_k0(input, *, out=None) -> Tensor
Scaled modified Bessel function of the second kind of order :math:`0`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
scaled_modified_bessel_k1 = special_scaled_modified_bessel_k1(...)
scaled_modified_bessel_k1(input, *, out=None) -> Tensor
Scaled modified Bessel function of the second kind of order :math:`1`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
shifted_chebyshev_polynomial_t = special_shifted_chebyshev_polynomial_t(...)
shifted_chebyshev_polynomial_t(input, n, *, out=None) -> Tensor
Chebyshev polynomial of the first kind :math:`T_{n}^{\ast}(\text{input})`.
Args:
input (Tensor): the input tensor.
n (Tensor): Degree of the polynomial.
Keyword args:
out (Tensor, optional): the output tensor.
shifted_chebyshev_polynomial_u = special_shifted_chebyshev_polynomial_u(...)
shifted_chebyshev_polynomial_u(input, n, *, out=None) -> Tensor
Chebyshev polynomial of the second kind :math:`U_{n}^{\ast}(\text{input})`.
Args:
input (Tensor): the input tensor.
n (Tensor): Degree of the polynomial.
Keyword args:
out (Tensor, optional): the output tensor.
shifted_chebyshev_polynomial_v = special_shifted_chebyshev_polynomial_v(...)
shifted_chebyshev_polynomial_v(input, n, *, out=None) -> Tensor
Chebyshev polynomial of the third kind :math:`V_{n}^{\ast}(\text{input})`.
Args:
input (Tensor): the input tensor.
n (Tensor): Degree of the polynomial.
Keyword args:
out (Tensor, optional): the output tensor.
shifted_chebyshev_polynomial_w = special_shifted_chebyshev_polynomial_w(...)
shifted_chebyshev_polynomial_w(input, n, *, out=None) -> Tensor
Chebyshev polynomial of the fourth kind :math:`W_{n}^{\ast}(\text{input})`.
Args:
input (Tensor): the input tensor.
n (Tensor): Degree of the polynomial.
Keyword args:
out (Tensor, optional): the output tensor.
sinc = special_sinc(...)
sinc(input, *, out=None) -> Tensor
Computes the normalized sinc of :attr:`input.`
.. math::
\text{out}_{i} =
\begin{cases}
1, & \text{if}\ \text{input}_{i}=0 \\
\sin(\pi \text{input}_{i}) / (\pi \text{input}_{i}), & \text{otherwise}
\end{cases}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.randn(4)
>>> t
tensor([ 0.2252, -0.2948, 1.0267, -1.1566])
>>> torch.special.sinc(t)
tensor([ 0.9186, 0.8631, -0.0259, -0.1300])
softmax = special_softmax(...)
softmax(input, dim, *, dtype=None) -> Tensor
Computes the softmax function.
Softmax is defined as:
:math:`\text{Softmax}(x_{i}) = \frac{\exp(x_i)}{\sum_j \exp(x_j)}`
It is applied to all slices along dim, and will re-scale them so that the elements
lie in the range `[0, 1]` and sum to 1.
Args:
input (Tensor): input
dim (int): A dimension along which softmax will be computed.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is cast to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Examples::
>>> t = torch.ones(2, 2)
>>> torch.special.softmax(t, 0)
tensor([[0.5000, 0.5000],
[0.5000, 0.5000]])
spherical_bessel_j0 = special_spherical_bessel_j0(...)
spherical_bessel_j0(input, *, out=None) -> Tensor
Spherical Bessel function of the first kind of order :math:`0`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
xlog1py = special_xlog1py(...)
xlog1py(input, other, *, out=None) -> Tensor
Computes ``input * log1p(other)`` with the following cases.
.. math::
\text{out}_{i} = \begin{cases}
\text{NaN} & \text{if } \text{other}_{i} = \text{NaN} \\
0 & \text{if } \text{input}_{i} = 0.0 \text{ and } \text{other}_{i} != \text{NaN} \\
\text{input}_{i} * \text{log1p}(\text{other}_{i})& \text{otherwise}
\end{cases}
Similar to SciPy's `scipy.special.xlog1py`.
Args:
input (Number or Tensor) : Multiplier
other (Number or Tensor) : Argument
.. note:: At least one of :attr:`input` or :attr:`other` must be a tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.zeros(5,)
>>> y = torch.tensor([-1, 0, 1, float('inf'), float('nan')])
>>> torch.special.xlog1py(x, y)
tensor([0., 0., 0., 0., nan])
>>> x = torch.tensor([1, 2, 3])
>>> y = torch.tensor([3, 2, 1])
>>> torch.special.xlog1py(x, y)
tensor([1.3863, 2.1972, 2.0794])
>>> torch.special.xlog1py(x, 4)
tensor([1.6094, 3.2189, 4.8283])
>>> torch.special.xlog1py(2, y)
tensor([2.7726, 2.1972, 1.3863])
xlogy = special_xlogy(...)
xlogy(input, other, *, out=None) -> Tensor
Computes ``input * log(other)`` with the following cases.
.. math::
\text{out}_{i} = \begin{cases}
\text{NaN} & \text{if } \text{other}_{i} = \text{NaN} \\
0 & \text{if } \text{input}_{i} = 0.0 \\
\text{input}_{i} * \log{(\text{other}_{i})} & \text{otherwise}
\end{cases}
Similar to SciPy's `scipy.special.xlogy`.
Args:
input (Number or Tensor) : Multiplier
other (Number or Tensor) : Argument
.. note:: At least one of :attr:`input` or :attr:`other` must be a tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.zeros(5,)
>>> y = torch.tensor([-1, 0, 1, float('inf'), float('nan')])
>>> torch.special.xlogy(x, y)
tensor([0., 0., 0., 0., nan])
>>> x = torch.tensor([1, 2, 3])
>>> y = torch.tensor([3, 2, 1])
>>> torch.special.xlogy(x, y)
tensor([1.0986, 1.3863, 0.0000])
>>> torch.special.xlogy(x, 4)
tensor([1.3863, 2.7726, 4.1589])
>>> torch.special.xlogy(2, y)
tensor([2.1972, 1.3863, 0.0000])
zeta = special_zeta(...)
zeta(input, other, *, out=None) -> Tensor
Computes the Hurwitz zeta function, elementwise.
.. math::
\zeta(x, q) = \sum_{k=0}^{\infty} \frac{1}{(k + q)^x}
Args:
input (Tensor): the input tensor corresponding to `x`.
other (Tensor): the input tensor corresponding to `q`.
.. note::
The Riemann zeta function corresponds to the case when `q = 1`
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.tensor([2., 4.])
>>> torch.special.zeta(x, 1)
tensor([1.6449, 1.0823])
>>> torch.special.zeta(x, torch.tensor([1., 2.]))
tensor([1.6449, 0.0823])
>>> torch.special.zeta(2, torch.tensor([1., 2.]))
tensor([1.6449, 0.6449])
DATA
__all__ = ['airy_ai', 'bessel_j0', 'bessel_j1', 'bessel_y0', 'bessel_y...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\special\__init__.py
torch.split
Python Library Documentation: function split in module torch.functional
split(tensor: torch.Tensor, split_size_or_sections: int | list[int], dim: int = 0) -> tuple[torch.Tensor, ...]
Splits the tensor into chunks. Each chunk is a view of the original tensor.
If :attr:`split_size_or_sections` is an integer type, then :attr:`tensor` will
be split into equally sized chunks (if possible). Last chunk will be smaller if
the tensor size along the given dimension :attr:`dim` is not divisible by
:attr:`split_size`.
If :attr:`split_size_or_sections` is a list, then :attr:`tensor` will be split
into ``len(split_size_or_sections)`` chunks with sizes in :attr:`dim` according
to :attr:`split_size_or_sections`.
Args:
tensor (Tensor): tensor to split.
split_size_or_sections (int) or (list(int)): size of a single chunk or
list of sizes for each chunk
dim (int): dimension along which to split the tensor.
Example::
>>> a = torch.arange(10).reshape(5, 2)
>>> a
tensor([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
>>> torch.split(a, 2)
(tensor([[0, 1],
[2, 3]]),
tensor([[4, 5],
[6, 7]]),
tensor([[8, 9]]))
>>> torch.split(a, [1, 4])
(tensor([[0, 1]]),
tensor([[2, 3],
[4, 5],
[6, 7],
[8, 9]]))
torch.split_copy
Python Library Documentation: built-in function split_copy in module torch
split_copy(...)
Performs the same operation as :func:`torch.split`, but all output tensors
are freshly created instead of aliasing the input.
torch.split_with_sizes
Python Library Documentation: built-in function split_with_sizes in module torch split_with_sizes(...)
torch.split_with_sizes_copy
Python Library Documentation: built-in function split_with_sizes_copy in module torch
split_with_sizes_copy(...)
Performs the same operation as :func:`torch.split_with_sizes`, but all output tensors
are freshly created instead of aliasing the input.
torch.spmm
Python Library Documentation: built-in function spmm in module torch spmm(...)
torch.sqrt
Python Library Documentation: built-in function sqrt in module torch
sqrt(...)
sqrt(input, *, out=None) -> Tensor
Returns a new tensor with the square-root of the elements of :attr:`input`.
.. math::
\text{out}_{i} = \sqrt{\text{input}_{i}}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-2.0755, 1.0226, 0.0831, 0.4806])
>>> torch.sqrt(a)
tensor([ nan, 1.0112, 0.2883, 0.6933])
torch.sqrt_
Python Library Documentation: built-in function sqrt_ in module torch sqrt_(...)
torch.square
Python Library Documentation: built-in function square in module torch
square(...)
square(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the square of the elements of :attr:`input`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-2.0755, 1.0226, 0.0831, 0.4806])
>>> torch.square(a)
tensor([ 4.3077, 1.0457, 0.0069, 0.2310])
torch.square_
Python Library Documentation: built-in function square_ in module torch square_(...)
torch.squeeze
Python Library Documentation: built-in function squeeze in module torch
squeeze(...)
squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
For example, if `input` is of shape:
:math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
will be of shape: :math:`(A \times B \times C \times D)`.
When :attr:`dim` is given, a squeeze operation is done only in the given
dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
will squeeze the tensor to the shape :math:`(A \times B)`.
.. note:: The returned tensor shares the storage with the input tensor,
so changing the contents of one will change the contents of the other.
.. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
will also remove the batch dimension, which can lead to unexpected
errors. Consider specifying only the dims you wish to be squeezed.
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): if given, the input will be squeezed
only in the specified dimensions.
.. versionchanged:: 2.0
:attr:`dim` now accepts tuples of dimensions.
Example::
>>> x = torch.zeros(2, 1, 2, 1, 2)
>>> x.size()
torch.Size([2, 1, 2, 1, 2])
>>> y = torch.squeeze(x)
>>> y.size()
torch.Size([2, 2, 2])
>>> y = torch.squeeze(x, 0)
>>> y.size()
torch.Size([2, 1, 2, 1, 2])
>>> y = torch.squeeze(x, 1)
>>> y.size()
torch.Size([2, 2, 1, 2])
>>> y = torch.squeeze(x, (1, 2, 3))
torch.Size([2, 2, 2])
torch.squeeze_copy
Python Library Documentation: built-in function squeeze_copy in module torch
squeeze_copy(...)
Performs the same operation as :func:`torch.squeeze`, but all output tensors
are freshly created instead of aliasing the input.
torch.sspaddmm
Python Library Documentation: built-in function sspaddmm in module torch
sspaddmm(...)
sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
Matrix multiplies a sparse tensor :attr:`mat1` with a dense tensor
:attr:`mat2`, then adds the sparse tensor :attr:`input` to the result.
Note: This function is equivalent to :func:`torch.addmm`, except
:attr:`input` and :attr:`mat1` are sparse.
Args:
input (Tensor): a sparse matrix to be added
mat1 (Tensor): a sparse matrix to be matrix multiplied
mat2 (Tensor): a dense matrix to be matrix multiplied
Keyword args:
beta (Number, optional): multiplier for :attr:`mat` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
torch.stack
Python Library Documentation: built-in function stack in module torch
stack(...)
stack(tensors, dim=0, *, out=None) -> Tensor
Concatenates a sequence of tensors along a new dimension.
All tensors need to be of the same size.
.. seealso::
:func:`torch.cat` concatenates the given sequence along an existing dimension.
Arguments:
tensors (sequence of Tensors): sequence of tensors to concatenate
dim (int, optional): dimension to insert. Has to be between 0 and the number
of dimensions of concatenated tensors (inclusive). Default: 0
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.randn(2, 3)
>>> x
tensor([[ 0.3367, 0.1288, 0.2345],
[ 0.2303, -1.1229, -0.1863]])
>>> torch.stack((x, x)) # same as torch.stack((x, x), dim=0)
tensor([[[ 0.3367, 0.1288, 0.2345],
[ 0.2303, -1.1229, -0.1863]],
[[ 0.3367, 0.1288, 0.2345],
[ 0.2303, -1.1229, -0.1863]]])
>>> torch.stack((x, x)).size()
torch.Size([2, 2, 3])
>>> torch.stack((x, x), dim=1)
tensor([[[ 0.3367, 0.1288, 0.2345],
[ 0.3367, 0.1288, 0.2345]],
[[ 0.2303, -1.1229, -0.1863],
[ 0.2303, -1.1229, -0.1863]]])
>>> torch.stack((x, x), dim=2)
tensor([[[ 0.3367, 0.3367],
[ 0.1288, 0.1288],
[ 0.2345, 0.2345]],
[[ 0.2303, 0.2303],
[-1.1229, -1.1229],
[-0.1863, -0.1863]]])
>>> torch.stack((x, x), dim=-1)
tensor([[[ 0.3367, 0.3367],
[ 0.1288, 0.1288],
[ 0.2345, 0.2345]],
[[ 0.2303, 0.2303],
[-1.1229, -1.1229],
[-0.1863, -0.1863]]])
torch.std
Python Library Documentation: built-in function std in module torch
std(...)
std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
Calculates the standard deviation over the dimensions specified by :attr:`dim`.
:attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
reduce over all dimensions.
The standard deviation (:math:`\sigma`) is calculated as
.. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
sample mean, :math:`N` is the number of samples and :math:`\delta N` is
the :attr:`correction`.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
Keyword args:
correction (int): difference between the sample size and sample degrees of freedom.
Defaults to `Bessel's correction`_, ``correction=1``.
.. versionchanged:: 2.0
Previously this argument was called ``unbiased`` and was a boolean
with ``True`` corresponding to ``correction=1`` and ``False`` being
``correction=0``.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
out (Tensor, optional): the output tensor.
Example:
>>> a = torch.tensor(
... [[ 0.2035, 1.2959, 1.8101, -0.4644],
... [ 1.5027, -0.3270, 0.5905, 0.6538],
... [-1.5745, 1.3330, -0.5596, -0.6548],
... [ 0.1264, -0.5080, 1.6420, 0.1992]]
... ) # fmt: skip
>>> torch.std(a, dim=1, keepdim=True)
tensor([[1.0311],
[0.7477],
[1.2204],
[0.9087]])
.. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
torch.std_mean
Python Library Documentation: built-in function std_mean in module torch
std_mean(...)
std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
Calculates the standard deviation and mean over the dimensions specified by
:attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
``None`` to reduce over all dimensions.
The standard deviation (:math:`\sigma`) is calculated as
.. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
sample mean, :math:`N` is the number of samples and :math:`\delta N` is
the :attr:`correction`.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
Keyword args:
correction (int): difference between the sample size and sample degrees of freedom.
Defaults to `Bessel's correction`_, ``correction=1``.
.. versionchanged:: 2.0
Previously this argument was called ``unbiased`` and was a boolean
with ``True`` corresponding to ``correction=1`` and ``False`` being
``correction=0``.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
out (Tensor, optional): the output tensor.
Returns:
A tuple (std, mean) containing the standard deviation and mean.
Example:
>>> a = torch.tensor(
... [[ 0.2035, 1.2959, 1.8101, -0.4644],
... [ 1.5027, -0.3270, 0.5905, 0.6538],
... [-1.5745, 1.3330, -0.5596, -0.6548],
... [ 0.1264, -0.5080, 1.6420, 0.1992]]
... ) # fmt: skip
>>> torch.std_mean(a, dim=0, keepdim=True)
(tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
.. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
torch.stft
Python Library Documentation: function stft in module torch.functional
stft(input: torch.Tensor, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: torch.Tensor | None = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) -> torch.Tensor
Short-time Fourier transform (STFT).
.. warning::
From version 1.8.0, :attr:`return_complex` must always be given
explicitly for real inputs and `return_complex=False` has been
deprecated. Strongly prefer `return_complex=True` as in a future
pytorch release, this function will only return complex tensors.
Note that :func:`torch.view_as_real` can be used to recover a real
tensor with an extra last dimension for real and imaginary components.
.. warning::
From version 2.1, a warning will be provided if a :attr:`window` is
not specified. In a future release, this attribute will be required.
Not providing a window currently defaults to using a rectangular window,
which may result in undesirable artifacts. Consider using tapered windows,
such as :func:`torch.hann_window`.
The STFT computes the Fourier transform of short overlapping windows of the
input. This giving frequency components of the signal as they change over
time. The interface of this function is modeled after (but *not* a drop-in
replacement for) librosa_ stft function.
.. _librosa: https://librosa.org/doc/latest/generated/librosa.stft.html
Ignoring the optional batch dimension, this method computes the following
expression:
.. math::
X[\omega, m] = \sum_{k = 0}^{\text{win\_length-1}}%
\text{window}[k]\ \text{input}[m \times \text{hop\_length} + k]\ %
\exp\left(- j \frac{2 \pi \cdot \omega k}{\text{n\_fft}}\right),
where :math:`m` is the index of the sliding window, and :math:`\omega` is
the frequency :math:`0 \leq \omega < \text{n\_fft}` for ``onesided=False``,
or :math:`0 \leq \omega < \lfloor \text{n\_fft} / 2 \rfloor + 1` for ``onesided=True``.
* :attr:`input` must be either a 1-D time sequence or a 2-D batch of time
sequences.
* If :attr:`hop_length` is ``None`` (default), it is treated as equal to
``floor(n_fft / 4)``.
* If :attr:`win_length` is ``None`` (default), it is treated as equal to
:attr:`n_fft`.
* :attr:`window` can be a 1-D tensor of size :attr:`win_length`, e.g., from
:meth:`torch.hann_window`. If :attr:`window` is ``None`` (default), it is
treated as if having :math:`1` everywhere in the window. If
:math:`\text{win\_length} < \text{n\_fft}`, :attr:`window` will be padded on
both sides to length :attr:`n_fft` before being applied.
* If :attr:`center` is ``True`` (default), :attr:`input` will be padded on
both sides so that the :math:`t`-th frame is centered at time
:math:`t \times \text{hop\_length}`. Otherwise, the :math:`t`-th frame
begins at time :math:`t \times \text{hop\_length}`.
* :attr:`pad_mode` determines the padding method used on :attr:`input` when
:attr:`center` is ``True``. See :meth:`torch.nn.functional.pad` for
all available options. Default is ``"reflect"``.
* If :attr:`onesided` is ``True`` (default for real input), only values for
:math:`\omega` in :math:`\left[0, 1, 2, \dots, \left\lfloor
\frac{\text{n\_fft}}{2} \right\rfloor + 1\right]` are returned because
the real-to-complex Fourier transform satisfies the conjugate symmetry,
i.e., :math:`X[m, \omega] = X[m, \text{n\_fft} - \omega]^*`.
Note if the input or window tensors are complex, then :attr:`onesided`
output is not possible.
* If :attr:`normalized` is ``True`` (default is ``False``), the function
returns the normalized STFT results, i.e., multiplied by :math:`(\text{frame\_length})^{-0.5}`.
* If :attr:`return_complex` is ``True`` (default if input is complex), the
return is a ``input.dim() + 1`` dimensional complex tensor. If ``False``,
the output is a ``input.dim() + 2`` dimensional real tensor where the last
dimension represents the real and imaginary components.
Returns either a complex tensor of size :math:`(* \times N \times T)` if
:attr:`return_complex` is true, or a real tensor of size :math:`(* \times N
\times T \times 2)`. Where :math:`*` is the optional batch size of
:attr:`input`, :math:`N` is the number of frequencies where STFT is applied
and :math:`T` is the total number of frames used.
.. warning::
This function changed signature at version 0.4.1. Calling with the
previous signature may cause error or return incorrect result.
Args:
input (Tensor): the input tensor of shape `(B?, L)` where `B?` is an optional
batch dimension
n_fft (int): size of Fourier transform
hop_length (int, optional): the distance between neighboring sliding window
frames. Default: ``None`` (treated as equal to ``floor(n_fft / 4)``)
win_length (int, optional): the size of window frame and STFT filter.
Default: ``None`` (treated as equal to :attr:`n_fft`)
window (Tensor, optional): the optional window function.
Shape must be 1d and `<= n_fft`
Default: ``None`` (treated as window of all :math:`1` s)
center (bool, optional): whether to pad :attr:`input` on both sides so
that the :math:`t`-th frame is centered at time :math:`t \times \text{hop\_length}`.
Default: ``True``
pad_mode (str, optional): controls the padding method used when
:attr:`center` is ``True``. Default: ``"reflect"``
normalized (bool, optional): controls whether to return the normalized STFT results
Default: ``False``
onesided (bool, optional): controls whether to return half of results to
avoid redundancy for real inputs.
Default: ``True`` for real :attr:`input` and :attr:`window`, ``False`` otherwise.
return_complex (bool, optional): whether to return a complex tensor, or
a real tensor with an extra last dimension for the real and
imaginary components.
.. versionchanged:: 2.0
``return_complex`` is now a required argument for real inputs,
as the default is being transitioned to ``True``.
.. deprecated:: 2.0
``return_complex=False`` is deprecated, instead use ``return_complex=True``
Note that calling :func:`torch.view_as_real` on the output will
recover the deprecated output format.
Returns:
Tensor: A tensor containing the STFT result with shape `(B?, N, T, C?)` where
- `B?` is an optional batch dimension from the input.
- `N` is the number of frequency samples, `(n_fft // 2) + 1` for
`onesided=True`, or otherwise `n_fft`.
- `T` is the number of frames, `1 + L // hop_length`
for `center=True`, or `1 + (L - n_fft) // hop_length` otherwise.
- `C?` is an optional length-2 dimension of real and imaginary
components, present when `return_complex=False`.
torch.storage
Python Library Documentation: module torch.storage in torch
NAME
torch.storage - # mypy: allow-untyped-defs
CLASSES
builtins.object
TypedStorage
torch._C.StorageBase(builtins.object)
UntypedStorage(torch._C.StorageBase, _StorageBase)
_StorageBase(builtins.object)
UntypedStorage(torch._C.StorageBase, _StorageBase)
class TypedStorage(builtins.object)
| TypedStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Methods defined here:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class UntypedStorage(torch._C.StorageBase, _StorageBase)
| UntypedStorage(*args, **kwargs)
|
| Method resolution order:
| UntypedStorage
| torch._C.StorageBase
| _StorageBase
| builtins.object
|
| Methods defined here:
|
| __getitem__(self, *args, **kwargs)
| Return self[key].
|
| share_memory_(self, *args, **kwargs)
| Moves the storage to shared memory.
|
| This is a no-op for storages already in shared memory and for CUDA
| storages, which do not need to be moved for sharing across processes.
| Storages in shared memory cannot be resized.
|
| Note that to mitigate issues like `this <https://github.com/pytorch/pytorch/issues/95606>`_
| it is thread safe to call this function from multiple threads on the same object.
| It is NOT thread safe though to call any other function on self without proper
| synchronization. Please see :doc:`/notes/multiprocessing` for more details.
|
| .. note::
| When all references to a storage in shared memory are deleted, the associated shared memory
| object will also be deleted. PyTorch has a special cleanup process to ensure that this happens
| even if the current process exits unexpectedly.
|
| It is worth noting the difference between :meth:`share_memory_` and :meth:`from_file` with ``shared = True``
|
| #. ``share_memory_`` uses `shm_open(3) <https://man7.org/linux/man-pages/man3/shm_open.3.html>`_ to create a
| POSIX shared memory object while :meth:`from_file` uses
| `open(2) <https://man7.org/linux/man-pages/man2/open.2.html>`_ to open the filename passed by the user.
| #. Both use an `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_ with ``MAP_SHARED``
| to map the file/object into the current virtual address space
| #. ``share_memory_`` will call ``shm_unlink(3)`` on the object after mapping it to make sure the shared memory
| object is freed when no process has the object open. ``torch.from_file(shared=True)`` does not unlink the
| file. This file is persistent and will remain until it is deleted by the user.
|
| Returns:
| ``self``
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| filename
| Returns the file name associated with this storage.
|
| The file name will be a string if the storage is on CPU and was created via
| :meth:`~torch.from_file()` with ``shared`` as ``True``. This attribute is ``None`` otherwise.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C.StorageBase:
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __len__(self, /)
| Return len(self).
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| copy_(...)
|
| data_ptr(...)
|
| element_size(...)
|
| fill_(...)
|
| is_shared(...)
|
| nbytes(...)
|
| new(...)
|
| resizable(...)
|
| resize_(...)
|
| ----------------------------------------------------------------------
| Static methods inherited from torch._C.StorageBase:
|
| __new__(*args, **kwargs) class method of torch._C.StorageBase
| Create and return a new object. See help(type) for accurate signature.
|
| from_buffer(...)
|
| from_file(...)
| from_file(filename, shared=False, nbytes=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``nbytes`` is the number of bytes of storage. If ``shared`` is ``False``,
| then the file must contain at least ``nbytes`` bytes. If ``shared`` is
| ``True`` the file will be created if needed. (Note that for ``UntypedStorage``
| this argument differs from that of ``TypedStorage.from_file``)
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| nbytes (int): number of bytes of storage
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C.StorageBase:
|
| device
|
| ----------------------------------------------------------------------
| Methods inherited from _StorageBase:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| byteswap(self, dtype)
| Swap bytes in underlying data.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> '_StorageBase | TypedStorage'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| double(self)
| Casts this storage to double type.
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> '_StorageBase | TypedStorage'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU storage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| long(self)
| Casts this storage to long type.
|
| mps(self)
| Return a MPS copy of this storage if it's not already on the MPS.
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU storage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| short(self)
| Casts this storage to short type.
|
| size(self) -> '_int'
|
| to(self, *, device: 'DeviceLikeType', non_blocking: '_bool' = False)
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: '_bool' = False) -> '_StorageBase | TypedStorage'
|
| untyped(self)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from _StorageBase:
|
| is_sparse = False
|
| is_sparse_csr = False
DATA
__all__ = ['TypedStorage', 'UntypedStorage']
__annotations__ = {'_share_memory_map': 'dict[int, threading.RLock]'}
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\storage.py
torch.strided
Python Library Documentation: layout object class layout(builtins.object) | Methods defined here: | | __repr__(self, /) | Return repr(self).
torch.sub
Python Library Documentation: built-in function sub in module torch
sub(...)
sub(input, other, *, alpha=1, out=None) -> Tensor
Subtracts :attr:`other`, scaled by :attr:`alpha`, from :attr:`input`.
.. math::
\text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
Args:
input (Tensor): the input tensor.
other (Tensor or Number): the tensor or number to subtract from :attr:`input`.
Keyword args:
alpha (Number): the multiplier for :attr:`other`.
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor((1, 2))
>>> b = torch.tensor((0, 1))
>>> torch.sub(a, b, alpha=2)
tensor([1, 0])
torch.subtract
Python Library Documentation: built-in function subtract in module torch
subtract(...)
subtract(input, other, *, alpha=1, out=None) -> Tensor
Alias for :func:`torch.sub`.
torch.sum
Python Library Documentation: built-in function sum in module torch
sum(...)
sum(input, *, dtype=None) -> Tensor
Returns the sum of all elements in the :attr:`input` tensor.
Args:
input (Tensor): the input tensor.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
.. note:: Use the `dtype` argument if you need the result in a specific tensor type.
Otherwise, the result type may be automatically promoted (e.g., from `torch.int32` to `torch.int64`).
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.1133, -0.9567, 0.2958]])
>>> torch.sum(a)
tensor(-0.5475)
.. function:: sum(input, dim, keepdim=False, *, dtype=None) -> Tensor
:noindex:
Returns the sum of each row of the :attr:`input` tensor in the given
dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
reduce over all of them.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.0569, -0.2475, 0.0737, -0.3429],
[-0.2993, 0.9138, 0.9337, -1.6864],
[ 0.1132, 0.7892, -0.1003, 0.5688],
[ 0.3637, -0.9906, -0.4752, -1.5197]])
>>> torch.sum(a, 1)
tensor([-0.4598, -0.1381, 1.3708, -2.6217])
>>> b = torch.arange(4 * 5 * 6).view(4, 5, 6)
>>> torch.sum(b, (2, 1))
tensor([ 435., 1335., 2235., 3135.])
torch.svd
Python Library Documentation: built-in function svd in module torch
svd(...)
svd(input, some=True, compute_uv=True, *, out=None) -> (Tensor, Tensor, Tensor)
Computes the singular value decomposition of either a matrix or batch of
matrices :attr:`input`. The singular value decomposition is represented as a
namedtuple `(U, S, V)`, such that :attr:`input` :math:`= U \text{diag}(S) V^{\text{H}}`.
where :math:`V^{\text{H}}` is the transpose of `V` for real inputs,
and the conjugate transpose of `V` for complex inputs.
If :attr:`input` is a batch of matrices, then `U`, `S`, and `V` are also
batched with the same batch dimensions as :attr:`input`.
If :attr:`some` is `True` (default), the method returns the reduced singular
value decomposition. In this case, if the last two dimensions of :attr:`input` are
`m` and `n`, then the returned `U` and `V` matrices will contain only
`min(n, m)` orthonormal columns.
If :attr:`compute_uv` is `False`, the returned `U` and `V` will be
zero-filled matrices of shape `(m, m)` and `(n, n)`
respectively, and the same device as :attr:`input`. The argument :attr:`some`
has no effect when :attr:`compute_uv` is `False`.
Supports :attr:`input` of float, double, cfloat and cdouble data types.
The dtypes of `U` and `V` are the same as :attr:`input`'s. `S` will
always be real-valued, even if :attr:`input` is complex.
.. warning::
:func:`torch.svd` is deprecated in favor of :func:`torch.linalg.svd`
and will be removed in a future PyTorch release.
``U, S, V = torch.svd(A, some=some, compute_uv=True)`` (default) should be replaced with
.. code:: python
U, S, Vh = torch.linalg.svd(A, full_matrices=not some)
V = Vh.mH
``_, S, _ = torch.svd(A, some=some, compute_uv=False)`` should be replaced with
.. code:: python
S = torch.linalg.svdvals(A)
.. note:: Differences with :func:`torch.linalg.svd`:
* :attr:`some` is the opposite of
:func:`torch.linalg.svd`'s :attr:`full_matrices`. Note that
default value for both is `True`, so the default behavior is
effectively the opposite.
* :func:`torch.svd` returns `V`, whereas :func:`torch.linalg.svd` returns
`Vh`, that is, :math:`V^{\text{H}}`.
* If :attr:`compute_uv` is `False`, :func:`torch.svd` returns zero-filled
tensors for `U` and `Vh`, whereas :func:`torch.linalg.svd` returns
empty tensors.
.. note:: The singular values are returned in descending order. If :attr:`input` is a batch of matrices,
then the singular values of each matrix in the batch are returned in descending order.
.. note:: The `S` tensor can only be used to compute gradients if :attr:`compute_uv` is `True`.
.. note:: When :attr:`some` is `False`, the gradients on `U[..., :, min(m, n):]`
and `V[..., :, min(m, n):]` will be ignored in the backward pass, as those vectors
can be arbitrary bases of the corresponding subspaces.
.. note:: The implementation of :func:`torch.linalg.svd` on CPU uses LAPACK's routine `?gesdd`
(a divide-and-conquer algorithm) instead of `?gesvd` for speed. Analogously,
on GPU, it uses cuSOLVER's routines `gesvdj` and `gesvdjBatched`.
.. note:: The returned `U` will not be contiguous. The matrix (or batch of matrices) will
be represented as a column-major matrix (i.e. Fortran-contiguous).
.. warning:: The gradients with respect to `U` and `V` will only be finite when the input does not
have zero nor repeated singular values.
.. warning:: If the distance between any two singular values is close to zero, the gradients with respect to
`U` and `V` will be numerically unstable, as they depends on
:math:`\frac{1}{\min_{i \neq j} \sigma_i^2 - \sigma_j^2}`. The same happens when the matrix
has small singular values, as these gradients also depend on `S^{-1}`.
.. warning:: For complex-valued :attr:`input` the singular value decomposition is not unique,
as `U` and `V` may be multiplied by an arbitrary phase factor :math:`e^{i \phi}` on every column.
The same happens when :attr:`input` has repeated singular values, where one may multiply
the columns of the spanning subspace in `U` and `V` by a rotation matrix
and `the resulting vectors will span the same subspace`_.
Different platforms, like NumPy, or inputs on different device types,
may produce different `U` and `V` tensors.
Args:
input (Tensor): the input tensor of size `(*, m, n)` where `*` is zero or more
batch dimensions consisting of `(m, n)` matrices.
some (bool, optional): controls whether to compute the reduced or full decomposition, and
consequently, the shape of returned `U` and `V`. Default: `True`.
compute_uv (bool, optional): controls whether to compute `U` and `V`. Default: `True`.
Keyword args:
out (tuple, optional): the output tuple of tensors
Example::
>>> a = torch.randn(5, 3)
>>> a
tensor([[ 0.2364, -0.7752, 0.6372],
[ 1.7201, 0.7394, -0.0504],
[-0.3371, -1.0584, 0.5296],
[ 0.3550, -0.4022, 1.5569],
[ 0.2445, -0.0158, 1.1414]])
>>> u, s, v = torch.svd(a)
>>> u
tensor([[ 0.4027, 0.0287, 0.5434],
[-0.1946, 0.8833, 0.3679],
[ 0.4296, -0.2890, 0.5261],
[ 0.6604, 0.2717, -0.2618],
[ 0.4234, 0.2481, -0.4733]])
>>> s
tensor([2.3289, 2.0315, 0.7806])
>>> v
tensor([[-0.0199, 0.8766, 0.4809],
[-0.5080, 0.4054, -0.7600],
[ 0.8611, 0.2594, -0.4373]])
>>> torch.dist(a, torch.mm(torch.mm(u, torch.diag(s)), v.t()))
tensor(8.6531e-07)
>>> a_big = torch.randn(7, 5, 3)
>>> u, s, v = torch.svd(a_big)
>>> torch.dist(a_big, torch.matmul(torch.matmul(u, torch.diag_embed(s)), v.mT))
tensor(2.6503e-06)
.. _the resulting vectors will span the same subspace:
(https://en.wikipedia.org/wiki/Singular_value_decomposition#Singular_values,_singular_vectors,_and_their_relation_to_the_SVD)
torch.svd_lowrank
Python Library Documentation: function svd_lowrank in module torch._lowrank
svd_lowrank(A: torch.Tensor, q: int | None = 6, niter: int | None = 2, M: torch.Tensor | None = None) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]
Return the singular value decomposition ``(U, S, V)`` of a matrix,
batches of matrices, or a sparse matrix :math:`A` such that
:math:`A \approx U \operatorname{diag}(S) V^{\text{H}}`. In case :math:`M` is given, then
SVD is computed for the matrix :math:`A - M`.
.. note:: The implementation is based on the Algorithm 5.1 from
Halko et al., 2009.
.. note:: For an adequate approximation of a k-rank matrix
:math:`A`, where k is not known in advance but could be
estimated, the number of :math:`Q` columns, q, can be
chosen according to the following criteria: in general,
:math:`k <= q <= min(2*k, m, n)`. For large low-rank
matrices, take :math:`q = k + 5..10`. If k is
relatively small compared to :math:`min(m, n)`, choosing
:math:`q = k + 0..2` may be sufficient.
.. note:: This is a randomized method. To obtain repeatable results,
set the seed for the pseudorandom number generator
.. note:: In general, use the full-rank SVD implementation
:func:`torch.linalg.svd` for dense matrices due to its 10x
higher performance characteristics. The low-rank SVD
will be useful for huge sparse matrices that
:func:`torch.linalg.svd` cannot handle.
Args::
A (Tensor): the input tensor of size :math:`(*, m, n)`
q (int, optional): a slightly overestimated rank of A.
niter (int, optional): the number of subspace iterations to
conduct; niter must be a nonnegative
integer, and defaults to 2
M (Tensor, optional): the input tensor's mean of size
:math:`(*, m, n)`, which will be broadcasted
to the size of A in this function.
References::
- Nathan Halko, Per-Gunnar Martinsson, and Joel Tropp, Finding
structure with randomness: probabilistic algorithms for
constructing approximate matrix decompositions,
arXiv:0909.4061 [math.NA; math.PR], 2009 (available at
`arXiv <https://arxiv.org/abs/0909.4061>`_).
torch.swapaxes
Python Library Documentation: built-in function swapaxes in module torch
swapaxes(...)
swapaxes(input, axis0, axis1) -> Tensor
Alias for :func:`torch.transpose`.
This function is equivalent to NumPy's swapaxes function.
Examples::
>>> x = torch.tensor([[[0,1],[2,3]],[[4,5],[6,7]]])
>>> x
tensor([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
>>> torch.swapaxes(x, 0, 1)
tensor([[[0, 1],
[4, 5]],
[[2, 3],
[6, 7]]])
>>> torch.swapaxes(x, 0, 2)
tensor([[[0, 4],
[2, 6]],
[[1, 5],
[3, 7]]])
torch.swapdims
Python Library Documentation: built-in function swapdims in module torch
swapdims(...)
swapdims(input, dim0, dim1) -> Tensor
Alias for :func:`torch.transpose`.
This function is equivalent to NumPy's swapaxes function.
Examples::
>>> x = torch.tensor([[[0,1],[2,3]],[[4,5],[6,7]]])
>>> x
tensor([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
>>> torch.swapdims(x, 0, 1)
tensor([[[0, 1],
[4, 5]],
[[2, 3],
[6, 7]]])
>>> torch.swapdims(x, 0, 2)
tensor([[[0, 4],
[2, 6]],
[[1, 5],
[3, 7]]])
torch.sym_constrain_range
Python Library Documentation: built-in function sym_constrain_range in module torch sym_constrain_range(...)
torch.sym_constrain_range_for_size
Python Library Documentation: built-in function sym_constrain_range_for_size in module torch sym_constrain_range_for_size(...)
torch.sym_float
Python Library Documentation: function sym_float in module torch
sym_float(a)
SymInt-aware utility for float casting.
Args:
a (SymInt, SymFloat, or object): Object to cast
torch.sym_fresh_size
Python Library Documentation: function sym_fresh_size in module torch
sym_fresh_size(expr)
# Create a fresh unbacked int, from an (possibly unbacked int) expression.
torch.sym_int
Python Library Documentation: function sym_int in module torch
sym_int(a)
SymInt-aware utility for int casting.
Args:
a (SymInt, SymFloat, or object): Object to cast
torch.sym_ite
Python Library Documentation: function sym_ite in module torch
sym_ite(b, t, f)
SymInt-aware utility for ternary operator (``t if b else f``.)
torch.sym_max
Python Library Documentation: function sym_max in module torch
sym_max(a, b)
SymInt-aware utility for max which avoids branching on a < b.
Unlike builtins.max(), this only works for int/float, and it always
promotes to float if any argument is float (unlike builtins.max, which
will faithfully preserve the type of the input argument).
torch.sym_min
Python Library Documentation: function sym_min in module torch
sym_min(a, b)
SymInt-aware utility for min().
torch.sym_not
Python Library Documentation: function sym_not in module torch
sym_not(a)
SymInt-aware utility for logical negation.
Args:
a (SymBool or bool): Object to negate
torch.sym_sqrt
Python Library Documentation: function _sym_sqrt in module torch _sym_sqrt(a)
torch.sym_sum
Python Library Documentation: function sym_sum in module torch
sym_sum(*args)
N-ary add which is faster to compute for long lists than iterated binary
addition. Only does something special for integers.
Accepts both ``sym_sum([a, b, c])`` and ``sym_sum(a, b, c)``.
torch.symeig
Python Library Documentation: function _symeig in module torch._linalg_utils _symeig(input, eigenvectors=False, upper=True, *, out=None) -> tuple[torch.Tensor, torch.Tensor]
torch.sys
Python Library Documentation: built-in module sys
NAME
sys
MODULE REFERENCE
https://docs.python.org/3.12/library/sys.html
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
DESCRIPTION
This module provides access to some objects used or maintained by the
interpreter and to functions that interact strongly with the interpreter.
Dynamic objects:
argv -- command line arguments; argv[0] is the script pathname if known
path -- module search path; path[0] is the script directory, else ''
modules -- dictionary of loaded modules
displayhook -- called to show results in an interactive session
excepthook -- called to handle any uncaught exception other than SystemExit
To customize printing in an interactive session or to install a custom
top-level exception handler, assign other functions to replace these.
stdin -- standard input file object; used by input()
stdout -- standard output file object; used by print()
stderr -- standard error object; used for error messages
By assigning other file objects (or objects that behave like files)
to these, it is possible to redirect all of the interpreter's I/O.
last_exc - the last uncaught exception
Only available in an interactive session after a
traceback has been printed.
last_type -- type of last uncaught exception
last_value -- value of last uncaught exception
last_traceback -- traceback of last uncaught exception
These three are the (deprecated) legacy representation of last_exc.
Static objects:
builtin_module_names -- tuple of module names built into this interpreter
copyright -- copyright notice pertaining to this interpreter
exec_prefix -- prefix used to find the machine-specific Python library
executable -- absolute path of the executable binary of the Python interpreter
float_info -- a named tuple with information about the float implementation.
float_repr_style -- string indicating the style of repr() output for floats
hash_info -- a named tuple with information about the hash algorithm.
hexversion -- version information encoded as a single integer
implementation -- Python implementation information.
int_info -- a named tuple with information about the int implementation.
maxsize -- the largest supported length of containers.
maxunicode -- the value of the largest Unicode code point
platform -- platform identifier
prefix -- prefix used to find the Python library
thread_info -- a named tuple with information about the thread implementation.
version -- the version of this interpreter as a string
version_info -- version information as a named tuple
dllhandle -- [Windows only] integer handle of the Python DLL
winver -- [Windows only] version number of the Python DLL
_enablelegacywindowsfsencoding -- [Windows only]
__stdin__ -- the original stdin; don't touch!
__stdout__ -- the original stdout; don't touch!
__stderr__ -- the original stderr; don't touch!
__displayhook__ -- the original displayhook; don't touch!
__excepthook__ -- the original excepthook; don't touch!
Functions:
displayhook() -- print an object to the screen, and save it in builtins._
excepthook() -- print an exception and its traceback to sys.stderr
exception() -- return the current thread's active exception
exc_info() -- return information about the current thread's active exception
exit() -- exit the interpreter by raising SystemExit
getdlopenflags() -- returns flags to be used for dlopen() calls
getprofile() -- get the global profiling function
getrefcount() -- return the reference count for an object (plus one :-)
getrecursionlimit() -- return the max recursion depth for the interpreter
getsizeof() -- return the size of an object in bytes
gettrace() -- get the global debug tracing function
setdlopenflags() -- set the flags to be used for dlopen() calls
setprofile() -- set the global profiling function
setrecursionlimit() -- set the max recursion depth for the interpreter
settrace() -- set the global debug tracing function
SUBMODULES
monitoring
FUNCTIONS
__breakpointhook__ = breakpointhook(...)
breakpointhook(*args, **kws)
This hook function is called by built-in breakpoint().
__displayhook__ = displayhook(object, /)
Print an object to sys.stdout and also save it in builtins._
__excepthook__ = excepthook(exctype, value, traceback, /)
Handle an exception by displaying it with a traceback on sys.stderr.
__unraisablehook__ = unraisablehook(unraisable, /)
Handle an unraisable exception.
The unraisable argument has the following attributes:
* exc_type: Exception type.
* exc_value: Exception value, can be None.
* exc_traceback: Exception traceback, can be None.
* err_msg: Error message, can be None.
* object: Object causing the exception, can be None.
activate_stack_trampoline(backend, /)
Activate stack profiler trampoline *backend*.
addaudithook(hook)
Adds a new audit hook callback.
audit(...)
audit(event, *args)
Passes the event to any audit hooks that are attached.
breakpointhook(...)
breakpointhook(*args, **kws)
This hook function is called by built-in breakpoint().
call_tracing(func, args, /)
Call func(*args), while tracing is enabled.
The tracing state is saved, and restored afterwards. This is intended
to be called from a debugger from a checkpoint, to recursively debug
some other code.
deactivate_stack_trampoline()
Deactivate the current stack profiler trampoline backend.
If no stack profiler is activated, this function has no effect.
displayhook(object, /)
Print an object to sys.stdout and also save it in builtins._
exc_info()
Return current exception information: (type, value, traceback).
Return information about the most recent exception caught by an except
clause in the current stack frame or in an older stack frame.
excepthook(exctype, value, traceback, /)
Handle an exception by displaying it with a traceback on sys.stderr.
exception()
Return the current exception.
Return the most recent exception caught by an except clause
in the current stack frame or in an older stack frame, or None
if no such exception exists.
exit(status=None, /)
Exit the interpreter by raising SystemExit(status).
If the status is omitted or None, it defaults to zero (i.e., success).
If the status is an integer, it will be used as the system exit status.
If it is another kind of object, it will be printed and the system
exit status will be one (i.e., failure).
get_asyncgen_hooks()
Return the installed asynchronous generators hooks.
This returns a namedtuple of the form (firstiter, finalizer).
get_coroutine_origin_tracking_depth()
Check status of origin tracking for coroutine objects in this thread.
get_int_max_str_digits()
Return the maximum string digits limit for non-binary int<->str conversions.
getallocatedblocks()
Return the number of memory blocks currently allocated.
getdefaultencoding()
Return the current default encoding used by the Unicode implementation.
getfilesystemencodeerrors()
Return the error mode used Unicode to OS filename conversion.
getfilesystemencoding()
Return the encoding used to convert Unicode filenames to OS filenames.
getprofile()
Return the profiling function set with sys.setprofile.
See the profiler chapter in the library manual.
getrecursionlimit()
Return the current value of the recursion limit.
The recursion limit is the maximum depth of the Python interpreter
stack. This limit prevents infinite recursion from causing an overflow
of the C stack and crashing Python.
getrefcount(object, /)
Return the reference count of object.
The count returned is generally one higher than you might expect,
because it includes the (temporary) reference as an argument to
getrefcount().
getsizeof(...)
getsizeof(object [, default]) -> int
Return the size of object in bytes.
getswitchinterval()
Return the current thread switch interval; see sys.setswitchinterval().
gettrace()
Return the global debug tracing function set with sys.settrace.
See the debugger chapter in the library manual.
getunicodeinternedsize()
Return the number of elements of the unicode interned dictionary
getwindowsversion()
Return info about the running version of Windows as a named tuple.
The members are named: major, minor, build, platform, service_pack,
service_pack_major, service_pack_minor, suite_mask, product_type and
platform_version. For backward compatibility, only the first 5 items
are available by indexing. All elements are numbers, except
service_pack and platform_type which are strings, and platform_version
which is a 3-tuple. Platform is always 2. Product_type may be 1 for a
workstation, 2 for a domain controller, 3 for a server.
Platform_version is a 3-tuple containing a version number that is
intended for identifying the OS rather than feature detection.
intern(string, /)
``Intern'' the given string.
This enters the string in the (global) table of interned strings whose
purpose is to speed up dictionary lookups. Return the string itself or
the previously interned string object with the same value.
is_finalizing()
Return True if Python is exiting.
is_stack_trampoline_active()
Return *True* if a stack profiler trampoline is active.
set_asyncgen_hooks(...)
set_asyncgen_hooks([firstiter] [, finalizer])
Set a finalizer for async generators objects.
set_coroutine_origin_tracking_depth(depth)
Enable or disable origin tracking for coroutine objects in this thread.
Coroutine objects will track 'depth' frames of traceback information
about where they came from, available in their cr_origin attribute.
Set a depth of 0 to disable.
set_int_max_str_digits(maxdigits)
Set the maximum string digits limit for non-binary int<->str conversions.
setprofile(...)
setprofile(function)
Set the profiling function. It will be called on each function call
and return. See the profiler chapter in the library manual.
setrecursionlimit(limit, /)
Set the maximum depth of the Python interpreter stack to n.
This limit prevents infinite recursion from causing an overflow of the C
stack and crashing Python. The highest possible limit is platform-
dependent.
setswitchinterval(interval, /)
Set the ideal thread switching delay inside the Python interpreter.
The actual frequency of switching threads can be lower if the
interpreter executes long sequences of uninterruptible code
(this is implementation-specific and workload-dependent).
The parameter must represent the desired switching delay in seconds
A typical value is 0.005 (5 milliseconds).
settrace(...)
settrace(function)
Set the global debug tracing function. It will be called on each
function call. See the debugger chapter in the library manual.
unraisablehook(unraisable, /)
Handle an unraisable exception.
The unraisable argument has the following attributes:
* exc_type: Exception type.
* exc_value: Exception value, can be None.
* exc_traceback: Exception traceback, can be None.
* err_msg: Error message, can be None.
* object: Object causing the exception, can be None.
DATA
__stderr__ = <_io.TextIOWrapper name='<stderr>' mode='w' encoding='cp1...
__stdin__ = <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8...
__stdout__ = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1...
api_version = 1013
argv = [r'f:\JoeyCodes\PyDocs\py_docs.py', '--worker', 'torch', r'F:\J...
base_exec_prefix = r'C:\Users\Youse\AppData\Local\Programs\Python\Pyth...
base_prefix = r'C:\Users\Youse\AppData\Local\Programs\Python\Python312...
builtin_module_names = ('_abc', '_ast', '_bisect', '_blake2', '_codecs...
byteorder = 'little'
copyright = 'Copyright (c) 2001-2023 Python Software Foundati...ematis...
dllhandle = 140727031824384
dont_write_bytecode = False
exec_prefix = r'C:\Users\Youse\AppData\Local\Programs\Python\Python312...
executable = r'C:\Users\Youse\AppData\Local\Programs\Python\Python312\...
flags = sys.flags(debug=0, inspect=0, interactive=0, opt...ding=0, saf...
float_info = sys.float_info(max=1.7976931348623157e+308, max_...epsilo...
float_repr_style = 'short'
hash_info = sys.hash_info(width=64, modulus=2305843009213693...iphash1...
hexversion = 51119856
implementation = namespace(name='cpython', cache_tag='cpython-312...as...
int_info = sys.int_info(bits_per_digit=30, sizeof_digit=4, ..._str_dig...
maxsize = 9223372036854775807
maxunicode = 1114111
meta_path = [<_distutils_hack.DistutilsMetaFinder object>, <class '_fr...
modules = {'__future__': <module '__future__' from 'C:\\Users\\Youse\\...
orig_argv = [r'C:\Users\Youse\AppData\Local\Programs\Python\Python312\...
path = [r'f:\JoeyCodes\PyDocs', r'C:\Users\Youse\AppData\Local\Program...
path_hooks = [<class 'zipimport.zipimporter'>, <function FileFinder.pa...
path_importer_cache = {r'C:\Users\Youse\AppData\Local\Programs\Python\...
platform = 'win32'
platlibdir = 'DLLs'
prefix = r'C:\Users\Youse\AppData\Local\Programs\Python\Python312'
pycache_prefix = None
stderr = <_io.TextIOWrapper name='<stderr>' mode='w' encoding='cp1252'...
stdin = <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>
stdlib_module_names = frozenset({'__future__', '_abc', '_aix_support',...
stdout = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'...
thread_info = sys.thread_info(name='nt', lock=None, version=None)
version = '3.12.6 (tags/v3.12.6:a4a2d2b, Sep 6 2024, 20:11:23) [MSC v...
version_info = sys.version_info(major=3, minor=12, micro=6, releaselev...
warnoptions = []
winver = '3.12'
FILE
(built-in)
torch.t
Python Library Documentation: built-in function t in module torch
t(...)
t(input) -> Tensor
Expects :attr:`input` to be <= 2-D tensor and transposes dimensions 0
and 1.
0-D and 1-D tensors are returned as is. When input is a 2-D tensor this
is equivalent to ``transpose(input, 0, 1)``.
Args:
input (Tensor): the input tensor.
Example::
>>> x = torch.randn(())
>>> x
tensor(0.1995)
>>> torch.t(x)
tensor(0.1995)
>>> x = torch.randn(3)
>>> x
tensor([ 2.4320, -0.4608, 0.7702])
>>> torch.t(x)
tensor([ 2.4320, -0.4608, 0.7702])
>>> x = torch.randn(2, 3)
>>> x
tensor([[ 0.4875, 0.9158, -0.5872],
[ 0.3938, -0.6929, 0.6932]])
>>> torch.t(x)
tensor([[ 0.4875, 0.3938],
[ 0.9158, -0.6929],
[-0.5872, 0.6932]])
See also :func:`torch.transpose`.
torch.t_copy
Python Library Documentation: built-in function t_copy in module torch
t_copy(...)
Performs the same operation as :func:`torch.t`, but all output tensors
are freshly created instead of aliasing the input.
torch.take
Python Library Documentation: built-in function take in module torch
take(...)
take(input, index) -> Tensor
Returns a new tensor with the elements of :attr:`input` at the given indices.
The input tensor is treated as if it were viewed as a 1-D tensor. The result
takes the same shape as the indices.
Args:
input (Tensor): the input tensor.
index (LongTensor): the indices into tensor
Example::
>>> src = torch.tensor([[4, 3, 5],
... [6, 7, 8]])
>>> torch.take(src, torch.tensor([0, 2, 5]))
tensor([ 4, 5, 8])
torch.take_along_dim
Python Library Documentation: built-in function take_along_dim in module torch
take_along_dim(...)
take_along_dim(input, indices, dim=None, *, out=None) -> Tensor
Selects values from :attr:`input` at the 1-dimensional indices from :attr:`indices` along the given :attr:`dim`.
If :attr:`dim` is None, the input array is treated as if it has been flattened to 1d.
Functions that return indices along a dimension, like :func:`torch.argmax` and :func:`torch.argsort`,
are designed to work with this function. See the examples below.
.. note::
This function is similar to NumPy's `take_along_axis`.
See also :func:`torch.gather`.
Args:
input (Tensor): the input tensor.
indices (LongTensor): the indices into :attr:`input`. Must have long dtype.
dim (int, optional): dimension to select along. Default: `None`.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.tensor([[10, 30, 20], [60, 40, 50]])
>>> max_idx = torch.argmax(t)
>>> torch.take_along_dim(t, max_idx)
tensor([60])
>>> sorted_idx = torch.argsort(t, dim=1)
>>> torch.take_along_dim(t, sorted_idx, dim=1)
tensor([[10, 20, 30],
[40, 50, 60]])
torch.tan
Python Library Documentation: built-in function tan in module torch
tan(...)
tan(input, *, out=None) -> Tensor
Returns a new tensor with the tangent of the elements in the :attr:`input` tensor,
where each value in this input tensor is in radians.
.. math::
\text{out}_{i} = \tan(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-1.2027, -1.7687, 0.4412, -1.3856])
>>> torch.tan(a)
tensor([-2.5930, 4.9859, 0.4722, -5.3366])
torch.tan_
Python Library Documentation: built-in function tan_ in module torch tan_(...)
torch.tanh
Python Library Documentation: built-in function tanh in module torch
tanh(...)
tanh(input, *, out=None) -> Tensor
Returns a new tensor with the hyperbolic tangent of the elements
of :attr:`input`.
.. math::
\text{out}_{i} = \tanh(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.8986, -0.7279, 1.1745, 0.2611])
>>> torch.tanh(a)
tensor([ 0.7156, -0.6218, 0.8257, 0.2553])
torch.tanh_
Python Library Documentation: built-in function tanh_ in module torch tanh_(...)
torch.tensor
Python Library Documentation: built-in function tensor in module torch
tensor(...)
tensor(data, *, dtype=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
Constructs a tensor with no autograd history (also known as a "leaf tensor", see :doc:`/notes/autograd`) by copying :attr:`data`.
.. warning::
When working with tensors prefer using :func:`torch.Tensor.clone`,
:func:`torch.Tensor.detach`, and :func:`torch.Tensor.requires_grad_` for
readability. Letting `t` be a tensor, ``torch.tensor(t)`` is equivalent to
``t.detach().clone()``, and ``torch.tensor(t, requires_grad=True)``
is equivalent to ``t.detach().clone().requires_grad_(True)``.
.. seealso::
:func:`torch.as_tensor` preserves autograd history and avoids copies where possible.
:func:`torch.from_numpy` creates a tensor that shares storage with a NumPy array.
Args:
data (array_like): Initial data for the tensor. Can be a list, tuple,
NumPy ``ndarray``, scalar, and other types.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, infers data type from :attr:`data`.
device (:class:`torch.device`, optional): the device of the constructed tensor. If None and data is a tensor
then the device of data is used. If None and data is not a tensor then
the result tensor is constructed on the current device.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> torch.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])
tensor([[ 0.1000, 1.2000],
[ 2.2000, 3.1000],
[ 4.9000, 5.2000]])
>>> torch.tensor([0, 1]) # Type inference on data
tensor([ 0, 1])
>>> torch.tensor([[0.11111, 0.222222, 0.3333333]],
... dtype=torch.float64,
... device=torch.device('cuda:0')) # creates a double tensor on a CUDA device
tensor([[ 0.1111, 0.2222, 0.3333]], dtype=torch.float64, device='cuda:0')
>>> torch.tensor(3.14159) # Create a zero-dimensional (scalar) tensor
tensor(3.1416)
>>> torch.tensor([]) # Create an empty tensor (of size (0,))
tensor([])
torch.tensor_split
Python Library Documentation: built-in function tensor_split in module torch
tensor_split(...)
tensor_split(input, indices_or_sections, dim=0) -> List of Tensors
Splits a tensor into multiple sub-tensors, all of which are views of :attr:`input`,
along dimension :attr:`dim` according to the indices or number of sections specified
by :attr:`indices_or_sections`. This function is based on NumPy's
:func:`numpy.array_split`.
.. function:: tensor_split(input, sections, dim=0) -> List of Tensors
:noindex:
Splits :attr:`input` into :attr:`sections` sections along dimension :attr:`dim`.
If :attr:`input` is divisible by :attr:`sections` along dimension :attr:`dim`, each
section will be of equal size, :code:`input.size(dim) / sections`. If :attr:`input`
is not divisible by :attr:`sections`, the sizes of the first
:code:`int(input.size(dim) % sections)` sections will have size
:code:`int(input.size(dim) / sections) + 1`, and the rest will have size
:code:`int(input.size(dim) / sections)`.
:attr:`sections` can also be a zero-dimensional long tensor.
.. function:: tensor_split(input, indices, dim=0) -> List of Tensors
:noindex:
Splits :attr:`input` along dimension :attr:`dim` at each of the indices in
:attr:`indices`. For instance, :code:`indices=[2, 3]` and :code:`dim=0`
would result in the tensors :code:`input[:2]`, :code:`input[2:3]`, and
:code:`input[3:]`.
:attr:`indices` can be a list or tuple of ints, or a one-dimensional long
tensor on the CPU.
Args:
input (Tensor): the tensor to split
dim (int, optional): dimension along which to split the tensor. Default: ``0``
Example::
>>> x = torch.arange(8)
>>> torch.tensor_split(x, 3)
(tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7]))
>>> x = torch.arange(7)
>>> torch.tensor_split(x, 3)
(tensor([0, 1, 2]), tensor([3, 4]), tensor([5, 6]))
>>> torch.tensor_split(x, (1, 6))
(tensor([0]), tensor([1, 2, 3, 4, 5]), tensor([6]))
>>> x = torch.arange(14).reshape(2, 7)
>>> x
tensor([[ 0, 1, 2, 3, 4, 5, 6],
[ 7, 8, 9, 10, 11, 12, 13]])
>>> torch.tensor_split(x, 3, dim=1)
(tensor([[0, 1, 2],
[7, 8, 9]]),
tensor([[ 3, 4],
[10, 11]]),
tensor([[ 5, 6],
[12, 13]]))
>>> torch.tensor_split(x, (1, 6), dim=1)
(tensor([[0],
[7]]),
tensor([[ 1, 2, 3, 4, 5],
[ 8, 9, 10, 11, 12]]),
tensor([[ 6],
[13]]))
torch.tensordot
Python Library Documentation: function tensordot in module torch.functional
tensordot(a, b, dims=2, out: torch.Tensor | None = None)
Returns a contraction of a and b over multiple dimensions.
:attr:`tensordot` implements a generalized matrix product.
Args:
a (Tensor): Left tensor to contract
b (Tensor): Right tensor to contract
dims (int or Tuple[List[int], List[int]] or List[List[int]] containing two lists or Tensor): number of dimensions to
contract or explicit lists of dimensions for :attr:`a` and
:attr:`b` respectively
When called with a non-negative integer argument :attr:`dims` = :math:`d`, and
the number of dimensions of :attr:`a` and :attr:`b` is :math:`m` and :math:`n`,
respectively, :func:`~torch.tensordot` computes the tensor :math:`r` of shape
``a.shape[:-dims] + b.shape[dims:]`` given by:
.. math::
r_{i_1,...,i_{m-d}, j_1,...,j_{n-d}}
= \sum_{k_1,...,k_d} a_{i_1,...,i_{m-d},k_1,...,k_d} \times b_{k_1,...,k_d, j_1,...,j_{n-d}}.
When called with :attr:`dims` of the list form, the given dimensions will be contracted
in place of the last :math:`d` of :attr:`a` and the first :math:`d` of :math:`b`. The sizes
in these dimensions must match, but :func:`~torch.tensordot` will deal with broadcasted
dimensions.
Examples::
>>> a = torch.arange(60.).reshape(3, 4, 5)
>>> b = torch.arange(24.).reshape(4, 3, 2)
>>> torch.tensordot(a, b, dims=([1, 0], [0, 1]))
tensor([[4400., 4730.],
[4532., 4874.],
[4664., 5018.],
[4796., 5162.],
[4928., 5306.]])
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
>>> a = torch.randn(3, 4, 5, device='cuda')
>>> b = torch.randn(4, 5, 6, device='cuda')
>>> c = torch.tensordot(a, b, dims=2).cpu()
tensor([[ 8.3504, -2.5436, 6.2922, 2.7556, -1.0732, 3.2741],
[ 3.3161, 0.0704, 5.0187, -0.4079, -4.3126, 4.8744],
[ 0.8223, 3.9445, 3.2168, -0.2400, 3.4117, 1.7780]])
>>> a = torch.randn(3, 5, 4, 6)
>>> b = torch.randn(6, 4, 5, 3)
>>> torch.tensordot(a, b, dims=([2, 1, 3], [1, 2, 0]))
tensor([[ 7.7193, -2.4867, -10.3204],
[ 1.5513, -14.4737, -6.5113],
[ -0.2850, 4.2573, -3.5997]])
torch.testing
Python Library Documentation: package torch.testing in torch
NAME
torch.testing
PACKAGE CONTENTS
_comparison
_creation
_internal (package)
_utils
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\testing\__init__.py
torch.textwrap
Python Library Documentation: module textwrap
NAME
textwrap - Text wrapping and filling.
MODULE REFERENCE
https://docs.python.org/3.12/library/textwrap.html
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
CLASSES
builtins.object
TextWrapper
class TextWrapper(builtins.object)
| TextWrapper(width=70, initial_indent='', subsequent_indent='', expand_tabs=True, replace_whitespace=True, fix_sentence_endings=False, break_long_words=True, drop_whitespace=True, break_on_hyphens=True, tabsize=8, *, max_lines=None, placeholder=' [...]')
|
| Object for wrapping/filling text. The public interface consists of
| the wrap() and fill() methods; the other methods are just there for
| subclasses to override in order to tweak the default behaviour.
| If you want to completely replace the main wrapping algorithm,
| you'll probably have to override _wrap_chunks().
|
| Several instance attributes control various aspects of wrapping:
| width (default: 70)
| the maximum width of wrapped lines (unless break_long_words
| is false)
| initial_indent (default: "")
| string that will be prepended to the first line of wrapped
| output. Counts towards the line's width.
| subsequent_indent (default: "")
| string that will be prepended to all lines save the first
| of wrapped output; also counts towards each line's width.
| expand_tabs (default: true)
| Expand tabs in input text to spaces before further processing.
| Each tab will become 0 .. 'tabsize' spaces, depending on its position
| in its line. If false, each tab is treated as a single character.
| tabsize (default: 8)
| Expand tabs in input text to 0 .. 'tabsize' spaces, unless
| 'expand_tabs' is false.
| replace_whitespace (default: true)
| Replace all whitespace characters in the input text by spaces
| after tab expansion. Note that if expand_tabs is false and
| replace_whitespace is true, every tab will be converted to a
| single space!
| fix_sentence_endings (default: false)
| Ensure that sentence-ending punctuation is always followed
| by two spaces. Off by default because the algorithm is
| (unavoidably) imperfect.
| break_long_words (default: true)
| Break words longer than 'width'. If false, those words will not
| be broken, and some lines might be longer than 'width'.
| break_on_hyphens (default: true)
| Allow breaking hyphenated words. If true, wrapping will occur
| preferably on whitespaces and right after hyphens part of
| compound words.
| drop_whitespace (default: true)
| Drop leading and trailing whitespace from lines.
| max_lines (default: None)
| Truncate wrapped lines.
| placeholder (default: ' [...]')
| Append to the last line of truncated text.
|
| Methods defined here:
|
| __init__(self, width=70, initial_indent='', subsequent_indent='', expand_tabs=True, replace_whitespace=True, fix_sentence_endings=False, break_long_words=True, drop_whitespace=True, break_on_hyphens=True, tabsize=8, *, max_lines=None, placeholder=' [...]')
| Initialize self. See help(type(self)) for accurate signature.
|
| fill(self, text)
| fill(text : string) -> string
|
| Reformat the single paragraph in 'text' to fit in lines of no
| more than 'self.width' columns, and return a new string
| containing the entire wrapped paragraph.
|
| wrap(self, text)
| wrap(text : string) -> [string]
|
| Reformat the single paragraph in 'text' so it fits in lines of
| no more than 'self.width' columns, and return a list of wrapped
| lines. Tabs in 'text' are expanded with string.expandtabs(),
| and all other whitespace characters (including newline) are
| converted to space.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| sentence_end_re = re.compile('[a-z][\\.\\!\\?][\\"\\\']?\\Z')
|
| unicode_whitespace_trans = {9: 32, 10: 32, 11: 32, 12: 32, 13: 32, 32:...
|
| wordsep_re = re.compile('\n ( # any whitespace\n ...# word...
|
| wordsep_simple_re = re.compile('([\\\t\\\n\\\x0b\\\x0c\\\r\\ ]+)')
FUNCTIONS
dedent(text)
Remove any common leading whitespace from every line in `text`.
This can be used to make triple-quoted strings line up with the left
edge of the display, while still presenting them in the source code
in indented form.
Note that tabs and spaces are both treated as whitespace, but they
are not equal: the lines " hello" and "\thello" are
considered to have no common leading whitespace.
Entirely blank lines are normalized to a newline character.
fill(text, width=70, **kwargs)
Fill a single paragraph of text, returning a new string.
Reformat the single paragraph in 'text' to fit in lines of no more
than 'width' columns, and return a new string containing the entire
wrapped paragraph. As with wrap(), tabs are expanded and other
whitespace characters converted to space. See TextWrapper class for
available keyword args to customize wrapping behaviour.
indent(text, prefix, predicate=None)
Adds 'prefix' to the beginning of selected lines in 'text'.
If 'predicate' is provided, 'prefix' will only be added to the lines
where 'predicate(line)' is True. If 'predicate' is not provided,
it will default to adding 'prefix' to all non-empty lines that do not
consist solely of whitespace characters.
shorten(text, width, **kwargs)
Collapse and truncate the given text to fit in the given width.
The text first has its whitespace collapsed. If it then fits in
the *width*, it is returned as is. Otherwise, as many words
as possible are joined and then the placeholder is appended::
>>> textwrap.shorten("Hello world!", width=12)
'Hello world!'
>>> textwrap.shorten("Hello world!", width=11)
'Hello [...]'
wrap(text, width=70, **kwargs)
Wrap a single paragraph of text, returning a list of wrapped lines.
Reformat the single paragraph in 'text' so it fits in lines of no
more than 'width' columns, and return a list of wrapped lines. By
default, tabs in 'text' are expanded with string.expandtabs(), and
all other whitespace characters (including newline) are converted to
space. See TextWrapper class for available keyword args to customize
wrapping behaviour.
DATA
__all__ = ['TextWrapper', 'wrap', 'fill', 'dedent', 'indent', 'shorten...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\textwrap.py
torch.thread_safe_generator
Python Library Documentation: function thread_safe_generator in module torch.random
thread_safe_generator() -> torch._C.Generator | None
Returns a thread-safe random number generator for use in DataLoader workers.
This function provides a convenient way for transforms and user code to use
thread-safe random number generation without manually checking worker context.
When called in a DataLoader thread worker, returns the worker's thread-local
:class:`torch.Generator`. When called in the main process or process workers,
returns ``None`` (which causes PyTorch functions to use the default global RNG).
Returns:
Optional[torch.Generator]: Thread-local generator in thread workers, None otherwise.
Example::
>>> from torch.random import thread_safe_generator
>>> generator = thread_safe_generator()
>>> torch.randint(0, 10, (5,), generator=generator)
Example with transforms::
>>> from torch.random import thread_safe_generator
>>> class MyRandomTransform:
... def __call__(self, img):
... generator = thread_safe_generator()
... offset = torch.randint(0, 10, (2,), generator=generator)
... return img[..., offset[0]:, offset[1]:]
torch.threading
Python Library Documentation: module threading
NAME
threading - Thread module emulating a subset of Java's threading model.
MODULE REFERENCE
https://docs.python.org/3.12/library/threading.html
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
CLASSES
builtins.Exception(builtins.BaseException)
builtins.RuntimeError
BrokenBarrierError
builtins.object
_thread._local
Barrier
Condition
Event
Semaphore
BoundedSemaphore
Thread
Timer
builtins.tuple(builtins.object)
_thread._ExceptHookArgs
class Barrier(builtins.object)
| Barrier(parties, action=None, timeout=None)
|
| Implements a Barrier.
|
| Useful for synchronizing a fixed number of threads at known synchronization
| points. Threads block on 'wait()' and are simultaneously awoken once they
| have all made that call.
|
| Methods defined here:
|
| __init__(self, parties, action=None, timeout=None)
| Create a barrier, initialised to 'parties' threads.
|
| 'action' is a callable which, when supplied, will be called by one of
| the threads after they have all entered the barrier and just prior to
| releasing them all. If a 'timeout' is provided, it is used as the
| default for all subsequent 'wait()' calls.
|
| __repr__(self)
| Return repr(self).
|
| abort(self)
| Place the barrier into a 'broken' state.
|
| Useful in case of error. Any currently waiting threads and threads
| attempting to 'wait()' will have BrokenBarrierError raised.
|
| reset(self)
| Reset the barrier to the initial state.
|
| Any threads currently waiting will get the BrokenBarrier exception
| raised.
|
| wait(self, timeout=None)
| Wait for the barrier.
|
| When the specified number of threads have started waiting, they are all
| simultaneously awoken. If an 'action' was provided for the barrier, one
| of the threads will have executed that callback prior to returning.
| Returns an individual index number from 0 to 'parties-1'.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| broken
| Return True if the barrier is in a broken state.
|
| n_waiting
| Return the number of threads currently waiting at the barrier.
|
| parties
| Return the number of threads required to trip the barrier.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class BoundedSemaphore(Semaphore)
| BoundedSemaphore(value=1)
|
| Implements a bounded semaphore.
|
| A bounded semaphore checks to make sure its current value doesn't exceed its
| initial value. If it does, ValueError is raised. In most situations
| semaphores are used to guard resources with limited capacity.
|
| If the semaphore is released too many times it's a sign of a bug. If not
| given, value defaults to 1.
|
| Like regular semaphores, bounded semaphores manage a counter representing
| the number of release() calls minus the number of acquire() calls, plus an
| initial value. The acquire() method blocks if necessary until it can return
| without making the counter negative. If not given, value defaults to 1.
|
| Method resolution order:
| BoundedSemaphore
| Semaphore
| builtins.object
|
| Methods defined here:
|
| __init__(self, value=1)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| release(self, n=1)
| Release a semaphore, incrementing the internal counter by one or more.
|
| When the counter is zero on entry and another thread is waiting for it
| to become larger than zero again, wake up that thread.
|
| If the number of releases exceeds the number of acquires,
| raise a ValueError.
|
| ----------------------------------------------------------------------
| Methods inherited from Semaphore:
|
| __enter__ = acquire(self, blocking=True, timeout=None)
|
| __exit__(self, t, v, tb)
|
| acquire(self, blocking=True, timeout=None)
| Acquire a semaphore, decrementing the internal counter by one.
|
| When invoked without arguments: if the internal counter is larger than
| zero on entry, decrement it by one and return immediately. If it is zero
| on entry, block, waiting until some other thread has called release() to
| make it larger than zero. This is done with proper interlocking so that
| if multiple acquire() calls are blocked, release() will wake exactly one
| of them up. The implementation may pick one at random, so the order in
| which blocked threads are awakened should not be relied on. There is no
| return value in this case.
|
| When invoked with blocking set to true, do the same thing as when called
| without arguments, and return true.
|
| When invoked with blocking set to false, do not block. If a call without
| an argument would block, return false immediately; otherwise, do the
| same thing as when called without arguments, and return true.
|
| When invoked with a timeout other than None, it will block for at
| most timeout seconds. If acquire does not complete successfully in
| that interval, return false. Return true otherwise.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Semaphore:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class BrokenBarrierError(builtins.RuntimeError)
| # exception raised by the Barrier class
|
| Method resolution order:
| BrokenBarrierError
| builtins.RuntimeError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.RuntimeError:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.RuntimeError:
|
| __new__(*args, **kwargs) class method of builtins.RuntimeError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class Condition(builtins.object)
| Condition(lock=None)
|
| Class that implements a condition variable.
|
| A condition variable allows one or more threads to wait until they are
| notified by another thread.
|
| If the lock argument is given and not None, it must be a Lock or RLock
| object, and it is used as the underlying lock. Otherwise, a new RLock object
| is created and used as the underlying lock.
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, *args)
|
| __init__(self, lock=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| notify(self, n=1)
| Wake up one or more threads waiting on this condition, if any.
|
| If the calling thread has not acquired the lock when this method is
| called, a RuntimeError is raised.
|
| This method wakes up at most n of the threads waiting for the condition
| variable; it is a no-op if no threads are waiting.
|
| notifyAll(self)
| Wake up all threads waiting on this condition.
|
| This method is deprecated, use notify_all() instead.
|
| notify_all(self)
| Wake up all threads waiting on this condition.
|
| If the calling thread has not acquired the lock when this method
| is called, a RuntimeError is raised.
|
| wait(self, timeout=None)
| Wait until notified or until a timeout occurs.
|
| If the calling thread has not acquired the lock when this method is
| called, a RuntimeError is raised.
|
| This method releases the underlying lock, and then blocks until it is
| awakened by a notify() or notify_all() call for the same condition
| variable in another thread, or until the optional timeout occurs. Once
| awakened or timed out, it re-acquires the lock and returns.
|
| When the timeout argument is present and not None, it should be a
| floating-point number specifying a timeout for the operation in seconds
| (or fractions thereof).
|
| When the underlying lock is an RLock, it is not released using its
| release() method, since this may not actually unlock the lock when it
| was acquired multiple times recursively. Instead, an internal interface
| of the RLock class is used, which really unlocks it even when it has
| been recursively acquired several times. Another internal interface is
| then used to restore the recursion level when the lock is reacquired.
|
| wait_for(self, predicate, timeout=None)
| Wait until a condition evaluates to True.
|
| predicate should be a callable which result will be interpreted as a
| boolean value. A timeout may be provided giving the maximum time to
| wait.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Event(builtins.object)
| Class implementing event objects.
|
| Events manage a flag that can be set to true with the set() method and reset
| to false with the clear() method. The wait() method blocks until the flag is
| true. The flag is initially false.
|
| Methods defined here:
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| clear(self)
| Reset the internal flag to false.
|
| Subsequently, threads calling wait() will block until set() is called to
| set the internal flag to true again.
|
| isSet(self)
| Return true if and only if the internal flag is true.
|
| This method is deprecated, use is_set() instead.
|
| is_set(self)
| Return true if and only if the internal flag is true.
|
| set(self)
| Set the internal flag to true.
|
| All threads waiting for it to become true are awakened. Threads
| that call wait() once the flag is true will not block at all.
|
| wait(self, timeout=None)
| Block until the internal flag is true.
|
| If the internal flag is true on entry, return immediately. Otherwise,
| block until another thread calls set() to set the flag to true, or until
| the optional timeout occurs.
|
| When the timeout argument is present and not None, it should be a
| floating-point number specifying a timeout for the operation in seconds
| (or fractions thereof).
|
| This method returns the internal flag on exit, so it will always return
| True except if a timeout is given and the operation times out.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
ExceptHookArgs = class _ExceptHookArgs(builtins.tuple)
| ExceptHookArgs(iterable=(), /)
|
| ExceptHookArgs
|
| Type used to pass arguments to threading.excepthook.
|
| Method resolution order:
| _ExceptHookArgs
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| exc_traceback
| Exception traceback
|
| exc_type
| Exception type
|
| exc_value
| Exception value
|
| thread
| Thread
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __match_args__ = ('exc_type', 'exc_value', 'exc_traceback', 'thread')
|
| n_fields = 4
|
| n_sequence_fields = 4
|
| n_unnamed_fields = 0
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __rmul__(self, value, /)
| Return value*self.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class Semaphore(builtins.object)
| Semaphore(value=1)
|
| This class implements semaphore objects.
|
| Semaphores manage a counter representing the number of release() calls minus
| the number of acquire() calls, plus an initial value. The acquire() method
| blocks if necessary until it can return without making the counter
| negative. If not given, value defaults to 1.
|
| Methods defined here:
|
| __enter__ = acquire(self, blocking=True, timeout=None)
|
| __exit__(self, t, v, tb)
|
| __init__(self, value=1)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(self)
| Return repr(self).
|
| acquire(self, blocking=True, timeout=None)
| Acquire a semaphore, decrementing the internal counter by one.
|
| When invoked without arguments: if the internal counter is larger than
| zero on entry, decrement it by one and return immediately. If it is zero
| on entry, block, waiting until some other thread has called release() to
| make it larger than zero. This is done with proper interlocking so that
| if multiple acquire() calls are blocked, release() will wake exactly one
| of them up. The implementation may pick one at random, so the order in
| which blocked threads are awakened should not be relied on. There is no
| return value in this case.
|
| When invoked with blocking set to true, do the same thing as when called
| without arguments, and return true.
|
| When invoked with blocking set to false, do not block. If a call without
| an argument would block, return false immediately; otherwise, do the
| same thing as when called without arguments, and return true.
|
| When invoked with a timeout other than None, it will block for at
| most timeout seconds. If acquire does not complete successfully in
| that interval, return false. Return true otherwise.
|
| release(self, n=1)
| Release a semaphore, incrementing the internal counter by one or more.
|
| When the counter is zero on entry and another thread is waiting for it
| to become larger than zero again, wake up that thread.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Thread(builtins.object)
| Thread(group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None)
|
| A class that represents a thread of control.
|
| This class can be safely subclassed in a limited fashion. There are two ways
| to specify the activity: by passing a callable object to the constructor, or
| by overriding the run() method in a subclass.
|
| Methods defined here:
|
| __init__(self, group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None)
| This constructor should always be called with keyword arguments. Arguments are:
|
| *group* should be None; reserved for future extension when a ThreadGroup
| class is implemented.
|
| *target* is the callable object to be invoked by the run()
| method. Defaults to None, meaning nothing is called.
|
| *name* is the thread name. By default, a unique name is constructed of
| the form "Thread-N" where N is a small decimal number.
|
| *args* is a list or tuple of arguments for the target invocation. Defaults to ().
|
| *kwargs* is a dictionary of keyword arguments for the target
| invocation. Defaults to {}.
|
| If a subclass overrides the constructor, it must make sure to invoke
| the base class constructor (Thread.__init__()) before doing anything
| else to the thread.
|
| __repr__(self)
| Return repr(self).
|
| getName(self)
| Return a string used for identification purposes only.
|
| This method is deprecated, use the name attribute instead.
|
| isDaemon(self)
| Return whether this thread is a daemon.
|
| This method is deprecated, use the daemon attribute instead.
|
| is_alive(self)
| Return whether the thread is alive.
|
| This method returns True just before the run() method starts until just
| after the run() method terminates. See also the module function
| enumerate().
|
| join(self, timeout=None)
| Wait until the thread terminates.
|
| This blocks the calling thread until the thread whose join() method is
| called terminates -- either normally or through an unhandled exception
| or until the optional timeout occurs.
|
| When the timeout argument is present and not None, it should be a
| floating-point number specifying a timeout for the operation in seconds
| (or fractions thereof). As join() always returns None, you must call
| is_alive() after join() to decide whether a timeout happened -- if the
| thread is still alive, the join() call timed out.
|
| When the timeout argument is not present or None, the operation will
| block until the thread terminates.
|
| A thread can be join()ed many times.
|
| join() raises a RuntimeError if an attempt is made to join the current
| thread as that would cause a deadlock. It is also an error to join() a
| thread before it has been started and attempts to do so raises the same
| exception.
|
| run(self)
| Method representing the thread's activity.
|
| You may override this method in a subclass. The standard run() method
| invokes the callable object passed to the object's constructor as the
| target argument, if any, with sequential and keyword arguments taken
| from the args and kwargs arguments, respectively.
|
| setDaemon(self, daemonic)
| Set whether this thread is a daemon.
|
| This method is deprecated, use the .daemon property instead.
|
| setName(self, name)
| Set the name string for this thread.
|
| This method is deprecated, use the name attribute instead.
|
| start(self)
| Start the thread's activity.
|
| It must be called at most once per thread object. It arranges for the
| object's run() method to be invoked in a separate thread of control.
|
| This method will raise a RuntimeError if called more than once on the
| same thread object.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| ident
| Thread identifier of this thread or None if it has not been started.
|
| This is a nonzero integer. See the get_ident() function. Thread
| identifiers may be recycled when a thread exits and another thread is
| created. The identifier is available even after the thread has exited.
|
| native_id
| Native integral thread ID of this thread, or None if it has not been started.
|
| This is a non-negative integer. See the get_native_id() function.
| This represents the Thread ID as reported by the kernel.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| daemon
| A boolean value indicating whether this thread is a daemon thread.
|
| This must be set before start() is called, otherwise RuntimeError is
| raised. Its initial value is inherited from the creating thread; the
| main thread is not a daemon thread and therefore all threads created in
| the main thread default to daemon = False.
|
| The entire Python program exits when only daemon threads are left.
|
| name
| A string used for identification purposes only.
|
| It has no semantics. Multiple threads may be given the same name. The
| initial name is set by the constructor.
ThreadError = class RuntimeError(Exception)
| Unspecified run-time error.
|
| Method resolution order:
| RuntimeError
| Exception
| BaseException
| object
|
| Built-in subclasses:
| NotImplementedError
| RecursionError
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class Timer(Thread)
| Timer(interval, function, args=None, kwargs=None)
|
| Call a function after a specified number of seconds:
|
| t = Timer(30.0, f, args=None, kwargs=None)
| t.start()
| t.cancel() # stop the timer's action if it's still waiting
|
| Method resolution order:
| Timer
| Thread
| builtins.object
|
| Methods defined here:
|
| __init__(self, interval, function, args=None, kwargs=None)
| This constructor should always be called with keyword arguments. Arguments are:
|
| *group* should be None; reserved for future extension when a ThreadGroup
| class is implemented.
|
| *target* is the callable object to be invoked by the run()
| method. Defaults to None, meaning nothing is called.
|
| *name* is the thread name. By default, a unique name is constructed of
| the form "Thread-N" where N is a small decimal number.
|
| *args* is a list or tuple of arguments for the target invocation. Defaults to ().
|
| *kwargs* is a dictionary of keyword arguments for the target
| invocation. Defaults to {}.
|
| If a subclass overrides the constructor, it must make sure to invoke
| the base class constructor (Thread.__init__()) before doing anything
| else to the thread.
|
| cancel(self)
| Stop the timer if it hasn't finished yet.
|
| run(self)
| Method representing the thread's activity.
|
| You may override this method in a subclass. The standard run() method
| invokes the callable object passed to the object's constructor as the
| target argument, if any, with sequential and keyword arguments taken
| from the args and kwargs arguments, respectively.
|
| ----------------------------------------------------------------------
| Methods inherited from Thread:
|
| __repr__(self)
| Return repr(self).
|
| getName(self)
| Return a string used for identification purposes only.
|
| This method is deprecated, use the name attribute instead.
|
| isDaemon(self)
| Return whether this thread is a daemon.
|
| This method is deprecated, use the daemon attribute instead.
|
| is_alive(self)
| Return whether the thread is alive.
|
| This method returns True just before the run() method starts until just
| after the run() method terminates. See also the module function
| enumerate().
|
| join(self, timeout=None)
| Wait until the thread terminates.
|
| This blocks the calling thread until the thread whose join() method is
| called terminates -- either normally or through an unhandled exception
| or until the optional timeout occurs.
|
| When the timeout argument is present and not None, it should be a
| floating-point number specifying a timeout for the operation in seconds
| (or fractions thereof). As join() always returns None, you must call
| is_alive() after join() to decide whether a timeout happened -- if the
| thread is still alive, the join() call timed out.
|
| When the timeout argument is not present or None, the operation will
| block until the thread terminates.
|
| A thread can be join()ed many times.
|
| join() raises a RuntimeError if an attempt is made to join the current
| thread as that would cause a deadlock. It is also an error to join() a
| thread before it has been started and attempts to do so raises the same
| exception.
|
| setDaemon(self, daemonic)
| Set whether this thread is a daemon.
|
| This method is deprecated, use the .daemon property instead.
|
| setName(self, name)
| Set the name string for this thread.
|
| This method is deprecated, use the name attribute instead.
|
| start(self)
| Start the thread's activity.
|
| It must be called at most once per thread object. It arranges for the
| object's run() method to be invoked in a separate thread of control.
|
| This method will raise a RuntimeError if called more than once on the
| same thread object.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Thread:
|
| ident
| Thread identifier of this thread or None if it has not been started.
|
| This is a nonzero integer. See the get_ident() function. Thread
| identifiers may be recycled when a thread exits and another thread is
| created. The identifier is available even after the thread has exited.
|
| native_id
| Native integral thread ID of this thread, or None if it has not been started.
|
| This is a non-negative integer. See the get_native_id() function.
| This represents the Thread ID as reported by the kernel.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Thread:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| daemon
| A boolean value indicating whether this thread is a daemon thread.
|
| This must be set before start() is called, otherwise RuntimeError is
| raised. Its initial value is inherited from the creating thread; the
| main thread is not a daemon thread and therefore all threads created in
| the main thread default to daemon = False.
|
| The entire Python program exits when only daemon threads are left.
|
| name
| A string used for identification purposes only.
|
| It has no semantics. Multiple threads may be given the same name. The
| initial name is set by the constructor.
local = class _local(builtins.object)
| Thread-local data
|
| Methods defined here:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
FUNCTIONS
Lock = allocate_lock(...)
allocate_lock() -> lock object
(allocate() is an obsolete synonym)
Create a new lock object. See help(type(threading.Lock())) for
information about locks.
RLock(*args, **kwargs)
Factory function that returns a new reentrant lock.
A reentrant lock must be released by the thread that acquired it. Once a
thread has acquired a reentrant lock, the same thread may acquire it again
without blocking; the thread must release it once for each time it has
acquired it.
__excepthook__ = _excepthook(...)
excepthook(exc_type, exc_value, exc_traceback, thread)
Handle uncaught Thread.run() exception.
active_count()
Return the number of Thread objects currently alive.
The returned count is equal to the length of the list returned by
enumerate().
current_thread()
Return the current Thread object, corresponding to the caller's thread of control.
If the caller's thread of control was not created through the threading
module, a dummy thread object with limited functionality is returned.
enumerate()
Return a list of all Thread objects currently alive.
The list includes daemonic threads, dummy thread objects created by
current_thread(), and the main thread. It excludes terminated threads and
threads that have not yet been started.
excepthook = _excepthook(...)
excepthook(exc_type, exc_value, exc_traceback, thread)
Handle uncaught Thread.run() exception.
get_ident(...)
get_ident() -> integer
Return a non-zero integer that uniquely identifies the current thread
amongst other threads that exist simultaneously.
This may be used to identify per-thread resources.
Even though on some platforms threads identities may appear to be
allocated consecutive numbers starting at 1, this behavior should not
be relied upon, and the number should be seen purely as a magic cookie.
A thread's identity may be reused for another thread after it exits.
get_native_id(...)
get_native_id() -> integer
Return a non-negative integer identifying the thread as reported
by the OS (kernel). This may be used to uniquely identify a
particular thread within a system.
getprofile()
Get the profiler function as set by threading.setprofile().
gettrace()
Get the trace function as set by threading.settrace().
main_thread()
Return the main thread object.
In normal conditions, the main thread is the thread from which the
Python interpreter was started.
setprofile(func)
Set a profile function for all threads started from the threading module.
The func will be passed to sys.setprofile() for each thread, before its
run() method is called.
setprofile_all_threads(func)
Set a profile function for all threads started from the threading module
and all Python threads that are currently executing.
The func will be passed to sys.setprofile() for each thread, before its
run() method is called.
settrace(func)
Set a trace function for all threads started from the threading module.
The func will be passed to sys.settrace() for each thread, before its run()
method is called.
settrace_all_threads(func)
Set a trace function for all threads started from the threading module
and all Python threads that are currently executing.
The func will be passed to sys.settrace() for each thread, before its run()
method is called.
stack_size(...)
stack_size([size]) -> size
Return the thread stack size used when creating new threads. The
optional size argument specifies the stack size (in bytes) to be used
for subsequently created threads, and must be 0 (use platform or
configured default) or a positive integer value of at least 32,768 (32k).
If changing the thread stack size is unsupported, a ThreadError
exception is raised. If the specified size is invalid, a ValueError
exception is raised, and the stack size is unmodified. 32k bytes
currently the minimum supported stack size value to guarantee
sufficient stack space for the interpreter itself.
Note that some platforms may have particular restrictions on values for
the stack size, such as requiring a minimum stack size larger than 32 KiB or
requiring allocation in multiples of the system memory page size
- platform documentation should be referred to for more information
(4 KiB pages are common; using multiples of 4096 for the stack size is
the suggested approach in the absence of more specific information).
DATA
TIMEOUT_MAX = 4294967.0
__all__ = ['get_ident', 'active_count', 'Condition', 'current_thread',...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\threading.py
torch.threshold
Python Library Documentation: built-in function threshold in module torch threshold(...)
torch.threshold_
Python Library Documentation: built-in function threshold_ in module torch
threshold_(...)
threshold_(input, threshold, value) -> Tensor
In-place version of :func:`~threshold`.
torch.tile
Python Library Documentation: built-in function tile in module torch
tile(...)
tile(input, dims) -> Tensor
Constructs a tensor by repeating the elements of :attr:`input`.
The :attr:`dims` argument specifies the number of repetitions
in each dimension.
If :attr:`dims` specifies fewer dimensions than :attr:`input` has, then
ones are prepended to :attr:`dims` until all dimensions are specified.
For example, if :attr:`input` has shape (8, 6, 4, 2) and :attr:`dims`
is (2, 2), then :attr:`dims` is treated as (1, 1, 2, 2).
Analogously, if :attr:`input` has fewer dimensions than :attr:`dims`
specifies, then :attr:`input` is treated as if it were unsqueezed at
dimension zero until it has as many dimensions as :attr:`dims` specifies.
For example, if :attr:`input` has shape (4, 2) and :attr:`dims`
is (3, 3, 2, 2), then :attr:`input` is treated as if it had the
shape (1, 1, 4, 2).
.. note::
This function is similar to NumPy's tile function.
Args:
input (Tensor): the tensor whose elements to repeat.
dims (tuple): the number of repetitions per dimension.
Example::
>>> x = torch.tensor([1, 2, 3])
>>> x.tile((2,))
tensor([1, 2, 3, 1, 2, 3])
>>> y = torch.tensor([[1, 2], [3, 4]])
>>> torch.tile(y, (2, 2))
tensor([[1, 2, 1, 2],
[3, 4, 3, 4],
[1, 2, 1, 2],
[3, 4, 3, 4]])
torch.to_dlpack
Python Library Documentation: built-in function _to_dlpack in module torch._C
_to_dlpack(...)
to_dlpack(tensor) -> PyCapsule
Returns an opaque object (a "DLPack capsule") representing the tensor.
.. note::
``to_dlpack`` is a legacy DLPack interface. The capsule it returns
cannot be used for anything in Python other than use it as input to
``from_dlpack``. The more idiomatic use of DLPack is to call
``from_dlpack`` directly on the tensor object - this works when that
object has a ``__dlpack__`` method, which PyTorch and most other
libraries indeed have now.
.. warning::
Only call ``from_dlpack`` once per capsule produced with ``to_dlpack``.
Behavior when a capsule is consumed multiple times is undefined.
Args:
tensor: a tensor to be exported
The DLPack capsule shares the tensor's memory.
torch.topk
Python Library Documentation: built-in function topk in module torch
topk(...)
topk(input, k, dim=None, largest=True, sorted=True, *, out=None) -> (Tensor, LongTensor)
Returns the :attr:`k` largest elements of the given :attr:`input` tensor along
a given dimension.
If :attr:`dim` is not given, the last dimension of the `input` is chosen.
If :attr:`largest` is ``False`` then the `k` smallest elements are returned.
A namedtuple of `(values, indices)` is returned with the `values` and
`indices` of the largest `k` elements of each row of the `input` tensor in the
given dimension `dim`.
The boolean option :attr:`sorted` if ``True``, will make sure that the returned
`k` elements are themselves sorted
.. note::
When using `torch.topk`, the indices of tied elements are not guaranteed to be stable
and may vary across different invocations.
Args:
input (Tensor): the input tensor.
k (int): the k in "top-k"
dim (int, optional): the dimension to sort along
largest (bool, optional): controls whether to return largest or
smallest elements
sorted (bool, optional): controls whether to return the elements
in sorted order
Keyword args:
out (tuple, optional): the output tuple of (Tensor, LongTensor) that can be
optionally given to be used as output buffers
Example::
>>> x = torch.arange(1., 6.)
>>> x
tensor([ 1., 2., 3., 4., 5.])
>>> torch.topk(x, 3)
torch.return_types.topk(values=tensor([5., 4., 3.]), indices=tensor([4, 3, 2]))
torch.torch
Python Library Documentation: package torch
NAME
torch
DESCRIPTION
The torch package contains data structures for multi-dimensional
tensors and defines mathematical operations over these tensors.
Additionally, it provides many utilities for efficient serialization of
Tensors and arbitrary types, and other useful utilities.
It has a CUDA counterpart, that enables you to run your tensor computations
on an NVIDIA GPU with compute capability >= 3.0.
PACKAGE CONTENTS
_C
_VF
__config__
__future__
_appdirs
_awaits (package)
_classes
_compile
_custom_op (package)
_custom_ops
_decomp (package)
_dispatch (package)
_dynamo (package)
_environment
_export (package)
_functorch (package)
_guards
_higher_order_ops (package)
_inductor (package)
_jit_internal
_lazy (package)
_library (package)
_linalg_utils
_lobpcg
_logging (package)
_lowrank
_meta_registrations
_native (package)
_numpy (package)
_opaque_base
_ops
_prims (package)
_prims_common (package)
_python_dispatcher
_refs (package)
_size_docs
_sources
_storage_docs
_streambase
_strobelight (package)
_subclasses (package)
_tensor
_tensor_docs
_tensor_iterator
_tensor_str
_thread_safe_fork
_torch_docs
_utils
_utils_internal
_vendor (package)
_vmap_internals
_weights_only_unpickler
accelerator (package)
amp (package)
ao (package)
autograd (package)
backends (package)
compiler (package)
contrib (package)
cpu (package)
cuda (package)
distributed (package)
distributions (package)
export (package)
fft (package)
func (package)
functional
futures (package)
fx (package)
hub
jit (package)
library
linalg (package)
masked (package)
monitor (package)
mps (package)
mtia (package)
multiprocessing (package)
nativert (package)
nested (package)
nn (package)
numa (package)
onnx (package)
optim (package)
overrides
package (package)
profiler (package)
quantization (package)
quasirandom
random
return_types
serialization
signal (package)
sparse (package)
special (package)
storage
testing (package)
torch_version
types
utils (package)
version
xpu (package)
SUBMODULES
classes
cpp
ops
windows
CLASSES
builtins.Exception(builtins.BaseException)
FatalError
torch.jit.Error
builtins.RuntimeError(builtins.Exception)
AcceleratorError
OutOfMemoryError
builtins.object
BoolTensor
ByteTensor
CharTensor
DoubleTensor
Event
FloatTensor
IntTensor
LongTensor
ShortTensor
Stream
SymBool
SymFloat
SymInt
device
dtype
finfo
iinfo
layout
memory_format
qscheme
torch._C.DisableTorchFunction
torch._C.DisableTorchFunctionSubclass
torch._C.Generator
torch.amp.autocast_mode.autocast
torch.amp.grad_scaler.GradScaler
torch.storage.TypedStorage
builtins.tuple(builtins.object)
Size
pybind11_builtins.pybind11_object(builtins.object)
AggregationType
AliasDb
Argument
ArgumentSpec
BenchmarkConfig
BenchmarkExecutionStats
Block
BufferDict
CallStack
Capsule
Code
CompleteArgumentSpec
ConcreteModuleType
ConcreteModuleTypeBuilder
DeepCopyMemoTable
DeserializationStorageContext
DispatchKey
DispatchKeySet
ErrorReport
ExcludeDispatchKeyGuard
ExecutionPlan
FileCheck
FunctionSchema
Future
Gradient
Graph
GraphExecutorState
IODescriptor
InferredType
LiteScriptModule
ModuleDict
Node
OperatorInfo
ParameterDict
PyTorchFileReader
PyTorchFileWriter
ScriptClass
ScriptClassFunction
ScriptDict
ScriptDictIterator
ScriptDictKeyIterator
ScriptList
ScriptListIterator
ScriptMethod
ScriptModuleSerializer
ScriptObject
ScriptModule
ScriptObjectProperty
SerializationStorageContext
StaticModule
Tag
ThroughputBenchmark
TracingState
Type
AnyType
AwaitType
BoolType
ClassType
ComplexType
DeviceObjType
DictType
EnumType
FloatType
FutureType
IntType
InterfaceType
ListType
NoneType
NumberType
OptionalType
PyObjectType
RRefType
StreamObjType
StringType
SymBoolType
SymIntType
TensorType
TupleType
UnionType
Use
Value
torch.jit.CompilationUnit
torch.jit.ScriptFunction
torch._C.LoggerBase(pybind11_builtins.pybind11_object)
LockingLogger
NoopLogger
torch._C.StorageBase(builtins.object)
torch.storage.UntypedStorage(torch._C.StorageBase, torch.storage._StorageBase)
torch._C.TensorBase(builtins.object)
Tensor
torch.storage._LegacyStorage(torch.storage.TypedStorage)
BoolStorage
ByteStorage
CharStorage
DoubleStorage
FloatStorage
IntStorage
LongStorage
ShortStorage
torch.storage._StorageBase(builtins.object)
torch.storage.UntypedStorage(torch._C.StorageBase, torch.storage._StorageBase)
torch.utils._contextlib._DecoratorContextManager(builtins.object)
torch.autograd.grad_mode.inference_mode
torch.utils._contextlib._NoParamDecoratorContextManager(torch.utils._contextlib._DecoratorContextManager)
torch.autograd.grad_mode.enable_grad
torch.autograd.grad_mode.no_grad
class AcceleratorError(builtins.RuntimeError)
| Exception raised while executing on device
|
| Method resolution order:
| AcceleratorError
| builtins.RuntimeError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.RuntimeError:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.RuntimeError:
|
| __new__(*args, **kwargs) class method of builtins.RuntimeError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class AggregationType(pybind11_builtins.pybind11_object)
| Method resolution order:
| AggregationType
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __eq__(...)
| __eq__(self: object, other: object, /) -> bool
|
| __getstate__(...)
| __getstate__(self: object, /) -> int
|
| __hash__(...)
| __hash__(self: object, /) -> int
|
| __index__(...)
| __index__(self: torch._C.AggregationType, /) -> int
|
| __init__(...)
| __init__(self: torch._C.AggregationType, value: typing.SupportsInt | typing.SupportsIndex) -> None
|
| __int__(...)
| __int__(self: torch._C.AggregationType, /) -> int
|
| __ne__(...)
| __ne__(self: object, other: object, /) -> bool
|
| __repr__(...)
| __repr__(self: object, /) -> str
|
| __setstate__(...)
| __setstate__(self: torch._C.AggregationType, state: typing.SupportsInt | typing.SupportsIndex, /) -> None
|
| __str__(...)
| __str__(self: object, /) -> str
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __members__
|
| name
| name(self: object, /) -> str
|
| value
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| AVG = <AggregationType.AVG: 1>
|
| SUM = <AggregationType.SUM: 0>
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class AliasDb(pybind11_builtins.pybind11_object)
| Method resolution order:
| AliasDb
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(...)
| __str__(self: torch._C.AliasDb) -> str
|
| dump(...)
| dump(self: torch._C.AliasDb) -> None
|
| has_writers(...)
| has_writers(self: torch._C.AliasDb, arg0: torch::jit::Value) -> bool
|
| may_contain_alias(...)
| may_contain_alias(self: torch._C.AliasDb, arg0: torch::jit::Value, arg1: torch::jit::Value) -> bool
|
| move_after_topologically_valid(...)
| move_after_topologically_valid(self: torch._C.AliasDb, arg0: torch::jit::Node, arg1: torch::jit::Node) -> bool
|
| move_before_topologically_valid(...)
| move_before_topologically_valid(self: torch._C.AliasDb, arg0: torch::jit::Node, arg1: torch::jit::Node) -> bool
|
| to_graphviz_str(...)
| to_graphviz_str(self: torch._C.AliasDb) -> str
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class AnyType(Type)
| Method resolution order:
| AnyType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.AnyType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Argument(pybind11_builtins.pybind11_object)
| Method resolution order:
| Argument
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.Argument, arg0: str, arg1: c10::Type, arg2: typing.SupportsInt | typing.SupportsIndex | None, arg3: IValue | None, arg4: bool, arg5: c10::AliasInfo | None) -> None
|
| has_default_value(...)
| has_default_value(self: torch._C.Argument) -> bool
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| N
|
| alias_info
|
| default_value
|
| is_out
|
| is_write
|
| kwarg_only
|
| name
|
| real_type
|
| type
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ArgumentSpec(pybind11_builtins.pybind11_object)
| Method resolution order:
| ArgumentSpec
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class AwaitType(Type)
| Method resolution order:
| AwaitType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.AwaitType, arg0: torch._C.Type) -> None
|
| getElementType(...)
| getElementType(self: torch._C.AwaitType) -> torch._C.Type
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class BenchmarkConfig(pybind11_builtins.pybind11_object)
| Method resolution order:
| BenchmarkConfig
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.BenchmarkConfig) -> None
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| num_calling_threads
|
| num_iters
|
| num_warmup_iters
|
| num_worker_threads
|
| profiler_output_path
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class BenchmarkExecutionStats(pybind11_builtins.pybind11_object)
| Method resolution order:
| BenchmarkExecutionStats
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| latency_avg_ms
|
| num_iters
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Block(pybind11_builtins.pybind11_object)
| Method resolution order:
| Block
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| addInputToBlock(...)
| addInputToBlock(self: torch._C.Block) -> torch._C.Value
|
| addNode(...)
| addNode(self: torch._C.Block, arg0: str, arg1: collections.abc.Sequence[torch._C.Value]) -> torch::jit::Node
|
| findAllNodes(...)
| findAllNodes(self: torch._C.Block, kind: str, recurse: bool = True) -> list[torch::jit::Node]
|
| Find all nodes
|
| findNode(...)
| findNode(self: torch._C.Block, kind: str, recurse: bool = True) -> torch::jit::Node
|
| Find Node
|
| inputs(...)
| inputs(self: torch._C.Block) -> collections.abc.Iterator[torch._C.Value]
|
| nodes(...)
| nodes(self: torch._C.Block) -> collections.abc.Iterator[torch::jit::Node]
|
| outputs(...)
| outputs(self: torch._C.Block) -> collections.abc.Iterator[torch._C.Value]
|
| owningNode(...)
| owningNode(self: torch._C.Block) -> torch::jit::Node
|
| paramNode(...)
| paramNode(self: torch._C.Block) -> torch::jit::Node
|
| registerOutput(...)
| registerOutput(self: torch._C.Block, arg0: torch._C.Value) -> int
|
| returnNode(...)
| returnNode(self: torch._C.Block) -> torch::jit::Node
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class BoolStorage(torch.storage._LegacyStorage)
| BoolStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| BoolStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.bool
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class BoolTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.bool
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class BoolType(Type)
| Method resolution order:
| BoolType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.BoolType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class BufferDict(pybind11_builtins.pybind11_object)
| Method resolution order:
| BufferDict
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.BufferDict, arg0: torch._C.ScriptModule) -> None
|
| contains(...)
| contains(self: torch._C.BufferDict, arg0: str) -> bool
|
| getattr(...)
| getattr(self: torch._C.BufferDict, arg0: str) -> object
|
| items(...)
| items(self: torch._C.BufferDict) -> list[tuple[str, object]]
|
| setattr(...)
| setattr(self: torch._C.BufferDict, arg0: str, arg1: object) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ByteStorage(torch.storage._LegacyStorage)
| ByteStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| # NOTE: New <type>Storage classes should never be added. When adding a new
| # dtype, use torch.storage.TypedStorage directly.
|
| Method resolution order:
| ByteStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.uint8
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class ByteTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.uint8
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class CallStack(pybind11_builtins.pybind11_object)
| Method resolution order:
| CallStack
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.CallStack, arg0: str, arg1: torch._C._jit_tree_views.SourceRange) -> None
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Capsule(pybind11_builtins.pybind11_object)
| Method resolution order:
| Capsule
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class CharStorage(torch.storage._LegacyStorage)
| CharStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| CharStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.int8
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class CharTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.int8
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class ClassType(Type)
| Method resolution order:
| ClassType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.ClassType, arg0: str) -> None
|
| method_names(...)
| method_names(self: torch._C.ClassType) -> list[str]
|
| name(...)
| name(self: torch._C.ClassType) -> str
|
| qualified_name(...)
| qualified_name(self: torch._C.ClassType) -> str
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Code(pybind11_builtins.pybind11_object)
| Method resolution order:
| Code
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| differentiable_op_executor_states(...)
| differentiable_op_executor_states(self: torch._C.Code) -> list[torch::jit::GraphExecutorState]
|
| grad_executor_states(...)
| grad_executor_states(self: torch._C.Code) -> list[torch::jit::GraphExecutorState]
|
| num_bailouts(...)
| num_bailouts(self: torch._C.Code) -> int
|
| request_bailout(...)
| request_bailout(self: torch._C.Code, arg0: typing.SupportsInt | typing.SupportsIndex) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class CompilationUnit(pybind11_builtins.pybind11_object)
| Method resolution order:
| CompilationUnit
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __getattr__(...)
| __getattr__(self: torch._C.CompilationUnit, arg0: str) -> torch::jit::StrongFunctionPtr
|
| __init__(...)
| __init__(self: torch._C.CompilationUnit, lang: str = '', _frames_up: typing.SupportsInt | typing.SupportsIndex = 0) -> None
|
| create_function(...)
| create_function(self: torch._C.CompilationUnit, qualified_name: str, graph: torch._C.Graph, should_mangle: bool = False) -> torch::jit::StrongFunctionPtr
|
| define(...)
| define(self: torch._C.CompilationUnit, src: str, rcb: collections.abc.Callable[[str], object] = None, _frames_up: typing.SupportsInt | typing.SupportsIndex = 0) -> None
|
| drop_all_functions(...)
| drop_all_functions(self: torch._C.CompilationUnit) -> None
|
| find_function(...)
| find_function(self: torch._C.CompilationUnit, arg0: str) -> torch::jit::StrongFunctionPtr | None
|
| get_class(...)
| get_class(self: torch._C.CompilationUnit, arg0: str) -> torch._C.ClassType
|
| get_functions(...)
| get_functions(self: torch._C.CompilationUnit) -> list[torch::jit::StrongFunctionPtr]
|
| get_interface(...)
| get_interface(self: torch._C.CompilationUnit, arg0: str) -> torch._C.InterfaceType
|
| set_optimized(...)
| set_optimized(self: torch._C.CompilationUnit, arg0: bool) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class CompleteArgumentSpec(pybind11_builtins.pybind11_object)
| Method resolution order:
| CompleteArgumentSpec
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(...)
| __repr__(self: torch._C.CompleteArgumentSpec) -> str
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ComplexType(Type)
| Method resolution order:
| ComplexType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.ComplexType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ConcreteModuleType(pybind11_builtins.pybind11_object)
| Method resolution order:
| ConcreteModuleType
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| dump(...)
| dump(self: torch._C.ConcreteModuleType) -> None
|
| equals(...)
| equals(*args, **kwargs)
| Overloaded function.
|
| 1. equals(self: torch._C.ConcreteModuleType, arg0: torch._C.ConcreteModuleType) -> bool
|
| 2. equals(self: torch._C.ConcreteModuleType, arg0: torch._C.ConcreteModuleTypeBuilder) -> bool
|
| get_attributes(...)
| get_attributes(self: torch._C.ConcreteModuleType) -> dict[str, tuple[torch._C.Type, bool]]
|
| get_constants(...)
| get_constants(self: torch._C.ConcreteModuleType) -> dict[str, object]
|
| get_modules(...)
| get_modules(self: torch._C.ConcreteModuleType) -> list[tuple[str, torch._C.ConcreteModuleType]]
|
| is_ignored_attribute(...)
| is_ignored_attribute(self: torch._C.ConcreteModuleType, arg0: str) -> bool
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| from_jit_type(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| from_jit_type(arg0: torch._C.Type) -> torch._C.ConcreteModuleType
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| jit_type
|
| py_class
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ConcreteModuleTypeBuilder(pybind11_builtins.pybind11_object)
| Method resolution order:
| ConcreteModuleTypeBuilder
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.ConcreteModuleTypeBuilder, arg0: object) -> None
|
| add_attribute(...)
| add_attribute(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: torch._C.Type, arg2: bool, arg3: bool) -> None
|
| add_builtin_function(...)
| add_builtin_function(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: str) -> None
|
| add_constant(...)
| add_constant(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: object) -> None
|
| add_failed_attribute(...)
| add_failed_attribute(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: str) -> None
|
| add_forward_hook(...)
| add_forward_hook(self: torch._C.ConcreteModuleTypeBuilder, arg0: object) -> None
|
| add_forward_pre_hook(...)
| add_forward_pre_hook(self: torch._C.ConcreteModuleTypeBuilder, arg0: object) -> None
|
| add_function_attribute(...)
| add_function_attribute(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: torch._C.Type, arg2: object) -> None
|
| add_ignored_attribute(...)
| add_ignored_attribute(self: torch._C.ConcreteModuleTypeBuilder, arg0: str) -> None
|
| add_ignored_attributes(...)
| add_ignored_attributes(self: torch._C.ConcreteModuleTypeBuilder, arg0: collections.abc.Sequence[str]) -> None
|
| add_module(...)
| add_module(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: torch::jit::ConcreteModuleType) -> None
|
| add_overload(...)
| add_overload(self: torch._C.ConcreteModuleTypeBuilder, arg0: str, arg1: collections.abc.Sequence[str]) -> None
|
| build(...)
| build(self: torch._C.ConcreteModuleTypeBuilder) -> torch::jit::ConcreteModuleType
|
| equals(...)
| equals(self: torch._C.ConcreteModuleTypeBuilder, arg0: torch._C.ConcreteModuleTypeBuilder) -> bool
|
| set_module_dict(...)
| set_module_dict(self: torch._C.ConcreteModuleTypeBuilder) -> None
|
| set_module_list(...)
| set_module_list(self: torch._C.ConcreteModuleTypeBuilder) -> None
|
| set_parameter_dict(...)
| set_parameter_dict(self: torch._C.ConcreteModuleTypeBuilder) -> None
|
| set_parameter_list(...)
| set_parameter_list(self: torch._C.ConcreteModuleTypeBuilder) -> None
|
| set_poisoned(...)
| set_poisoned(self: torch._C.ConcreteModuleTypeBuilder) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class DeepCopyMemoTable(pybind11_builtins.pybind11_object)
| Method resolution order:
| DeepCopyMemoTable
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class DeserializationStorageContext(pybind11_builtins.pybind11_object)
| Method resolution order:
| DeserializationStorageContext
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.DeserializationStorageContext) -> None
|
| add_storage(...)
| add_storage(self: torch._C.DeserializationStorageContext, arg0: str, arg1: torch.Tensor) -> None
|
| get_storage(...)
| get_storage(self: torch._C.DeserializationStorageContext, arg0: str, arg1: object) -> torch.Tensor
|
| has_storage(...)
| has_storage(self: torch._C.DeserializationStorageContext, arg0: str) -> bool
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class DeviceObjType(Type)
| Method resolution order:
| DeviceObjType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.DeviceObjType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class DictType(Type)
| Method resolution order:
| DictType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.DictType, arg0: torch._C.Type, arg1: torch._C.Type) -> None
|
| getKeyType(...)
| getKeyType(self: torch._C.DictType) -> torch._C.Type
|
| getValueType(...)
| getValueType(self: torch._C.DictType) -> torch._C.Type
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class DisableTorchFunction(builtins.object)
| Methods defined here:
|
| __enter__(...)
|
| __exit__(...)
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
class DisableTorchFunctionSubclass(builtins.object)
| Methods defined here:
|
| __enter__(...)
|
| __exit__(...)
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
class DispatchKey(pybind11_builtins.pybind11_object)
| Method resolution order:
| DispatchKey
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __eq__(...)
| __eq__(self: object, other: object, /) -> bool
|
| __getstate__(...)
| __getstate__(self: object, /) -> int
|
| __hash__(...)
| __hash__(self: object, /) -> int
|
| __index__(...)
| __index__(self: torch._C.DispatchKey, /) -> int
|
| __init__(...)
| __init__(self: torch._C.DispatchKey, value: typing.SupportsInt | typing.SupportsIndex) -> None
|
| __int__(...)
| __int__(self: torch._C.DispatchKey, /) -> int
|
| __ne__(...)
| __ne__(self: object, other: object, /) -> bool
|
| __repr__(...)
| __repr__(self: object, /) -> str
|
| __setstate__(...)
| __setstate__(self: torch._C.DispatchKey, state: typing.SupportsInt | typing.SupportsIndex, /) -> None
|
| __str__(...)
| __str__(self: object, /) -> str
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __members__
|
| name
| name(self: object, /) -> str
|
| value
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| ADInplaceOrView = <DispatchKey.ADInplaceOrView: 19>
|
| AutocastCPU = <DispatchKey.AutocastCPU: 24>
|
| AutocastCUDA = <DispatchKey.AutocastCUDA: 32>
|
| AutocastHPU = <DispatchKey.AutocastHPU: 29>
|
| AutocastIPU = <DispatchKey.AutocastIPU: 28>
|
| AutocastMPS = <DispatchKey.AutocastMPS: 31>
|
| AutocastPrivateUse1 = <DispatchKey.AutocastPrivateUse1: 33>
|
| AutocastXPU = <DispatchKey.AutocastXPU: 27>
|
| Autograd = <DispatchKey.Autograd: 150>
|
| AutogradCPU = <DispatchKey.AutogradCPU: 134>
|
| AutogradCUDA = <DispatchKey.AutogradCUDA: 135>
|
| AutogradFunctionality = <DispatchKey.AutogradFunctionality: 21>
|
| AutogradHIP = <DispatchKey.AutogradHIP: 136>
|
| AutogradHPU = <DispatchKey.AutogradHPU: 141>
|
| AutogradIPU = <DispatchKey.AutogradIPU: 139>
|
| AutogradLazy = <DispatchKey.AutogradLazy: 143>
|
| AutogradMAIA = <DispatchKey.AutogradMAIA: 145>
|
| AutogradMPS = <DispatchKey.AutogradMPS: 138>
|
| AutogradMTIA = <DispatchKey.AutogradMTIA: 144>
|
| AutogradMeta = <DispatchKey.AutogradMeta: 149>
|
| AutogradNestedTensor = <DispatchKey.AutogradNestedTensor: 22>
|
| AutogradOther = <DispatchKey.AutogradOther: 20>
|
| AutogradPrivateUse1 = <DispatchKey.AutogradPrivateUse1: 146>
|
| AutogradPrivateUse2 = <DispatchKey.AutogradPrivateUse2: 147>
|
| AutogradPrivateUse3 = <DispatchKey.AutogradPrivateUse3: 148>
|
| AutogradVE = <DispatchKey.AutogradVE: 142>
|
| AutogradXLA = <DispatchKey.AutogradXLA: 137>
|
| AutogradXPU = <DispatchKey.AutogradXPU: 140>
|
| BackendSelect = <DispatchKey.BackendSelect: 11>
|
| CPU = <DispatchKey.CPU: 49>
|
| CUDA = <DispatchKey.CUDA: 50>
|
| CompositeExplicitAutograd = <DispatchKey.CompositeExplicitAutograd: 15...
|
| CompositeExplicitAutogradNonFunctional = <DispatchKey.CompositeExplici...
|
| CompositeImplicitAutograd = <DispatchKey.CompositeImplicitAutograd: 15...
|
| CompositeImplicitAutogradNestedTensor = <DispatchKey.CompositeImplicit...
|
| Conjugate = <DispatchKey.Conjugate: 16>
|
| Dense = <DispatchKey.Dense: 1>
|
| EndOfAutogradFunctionalityBackends = <DispatchKey.AutogradMeta: 149>
|
| EndOfDenseBackends = <DispatchKey.Meta: 64>
|
| EndOfNestedTensorBackends = <DispatchKey.NestedTensorMeta: 132>
|
| EndOfQuantizedBackends = <DispatchKey.QuantizedMeta: 81>
|
| EndOfSparseBackends = <DispatchKey.SparseMeta: 98>
|
| EndOfSparseCsrBackends = <DispatchKey.SparseCsrMeta: 115>
|
| FuncTorchBatched = <DispatchKey.FuncTorchBatched: 34>
|
| FuncTorchBatchedDecomposition = <DispatchKey.FuncTorchBatchedDecomposi...
|
| FuncTorchDynamicLayerBackMode = <DispatchKey.FuncTorchDynamicLayerBack...
|
| FuncTorchDynamicLayerFrontMode = <DispatchKey.FuncTorchDynamicLayerFro...
|
| FuncTorchGradWrapper = <DispatchKey.FuncTorchGradWrapper: 39>
|
| FuncTorchVmapMode = <DispatchKey.FuncTorchVmapMode: 36>
|
| Functionalize = <DispatchKey.Functionalize: 15>
|
| HIP = <DispatchKey.HIP: 51>
|
| HPU = <DispatchKey.HPU: 56>
|
| IPU = <DispatchKey.IPU: 54>
|
| Lazy = <DispatchKey.Lazy: 58>
|
| MAIA = <DispatchKey.MAIA: 60>
|
| MPS = <DispatchKey.MPS: 53>
|
| MTIA = <DispatchKey.MTIA: 59>
|
| Meta = <DispatchKey.Meta: 64>
|
| Negative = <DispatchKey.Negative: 17>
|
| NestedTensor = <DispatchKey.NestedTensor: 10>
|
| NestedTensorCPU = <DispatchKey.NestedTensorCPU: 117>
|
| NestedTensorCUDA = <DispatchKey.NestedTensorCUDA: 118>
|
| NestedTensorHIP = <DispatchKey.NestedTensorHIP: 119>
|
| NestedTensorHPU = <DispatchKey.NestedTensorHPU: 124>
|
| NestedTensorIPU = <DispatchKey.NestedTensorIPU: 122>
|
| NestedTensorLazy = <DispatchKey.NestedTensorLazy: 126>
|
| NestedTensorMAIA = <DispatchKey.NestedTensorMAIA: 128>
|
| NestedTensorMPS = <DispatchKey.NestedTensorMPS: 121>
|
| NestedTensorMTIA = <DispatchKey.NestedTensorMTIA: 127>
|
| NestedTensorMeta = <DispatchKey.NestedTensorMeta: 132>
|
| NestedTensorPrivateUse1 = <DispatchKey.NestedTensorPrivateUse1: 129>
|
| NestedTensorPrivateUse2 = <DispatchKey.NestedTensorPrivateUse2: 130>
|
| NestedTensorPrivateUse3 = <DispatchKey.NestedTensorPrivateUse3: 131>
|
| NestedTensorVE = <DispatchKey.NestedTensorVE: 125>
|
| NestedTensorXLA = <DispatchKey.NestedTensorXLA: 120>
|
| NestedTensorXPU = <DispatchKey.NestedTensorXPU: 123>
|
| PreDispatch = <DispatchKey.PreDispatch: 45>
|
| PrivateUse1 = <DispatchKey.PrivateUse1: 61>
|
| PrivateUse2 = <DispatchKey.PrivateUse2: 62>
|
| PrivateUse3 = <DispatchKey.PrivateUse3: 63>
|
| Python = <DispatchKey.Python: 13>
|
| PythonDispatcher = <DispatchKey.PythonDispatcher: 46>
|
| PythonTLSSnapshot = <DispatchKey.PythonTLSSnapshot: 41>
|
| Quantized = <DispatchKey.Quantized: 5>
|
| QuantizedCPU = <DispatchKey.QuantizedCPU: 66>
|
| QuantizedCUDA = <DispatchKey.QuantizedCUDA: 67>
|
| QuantizedHIP = <DispatchKey.QuantizedHIP: 68>
|
| QuantizedHPU = <DispatchKey.QuantizedHPU: 73>
|
| QuantizedIPU = <DispatchKey.QuantizedIPU: 71>
|
| QuantizedLazy = <DispatchKey.QuantizedLazy: 75>
|
| QuantizedMAIA = <DispatchKey.QuantizedMAIA: 77>
|
| QuantizedMPS = <DispatchKey.QuantizedMPS: 70>
|
| QuantizedMTIA = <DispatchKey.QuantizedMTIA: 76>
|
| QuantizedMeta = <DispatchKey.QuantizedMeta: 81>
|
| QuantizedPrivateUse1 = <DispatchKey.QuantizedPrivateUse1: 78>
|
| QuantizedPrivateUse2 = <DispatchKey.QuantizedPrivateUse2: 79>
|
| QuantizedPrivateUse3 = <DispatchKey.QuantizedPrivateUse3: 80>
|
| QuantizedVE = <DispatchKey.QuantizedVE: 74>
|
| QuantizedXLA = <DispatchKey.QuantizedXLA: 69>
|
| QuantizedXPU = <DispatchKey.QuantizedXPU: 72>
|
| Sparse = <DispatchKey.Sparse: 8>
|
| SparseCPU = <DispatchKey.SparseCPU: 83>
|
| SparseCUDA = <DispatchKey.SparseCUDA: 84>
|
| SparseCsr = <DispatchKey.SparseCsr: 9>
|
| SparseCsrCPU = <DispatchKey.SparseCsrCPU: 100>
|
| SparseCsrCUDA = <DispatchKey.SparseCsrCUDA: 101>
|
| SparseCsrHIP = <DispatchKey.SparseCsrHIP: 102>
|
| SparseCsrHPU = <DispatchKey.SparseCsrHPU: 107>
|
| SparseCsrIPU = <DispatchKey.SparseCsrIPU: 105>
|
| SparseCsrLazy = <DispatchKey.SparseCsrLazy: 109>
|
| SparseCsrMAIA = <DispatchKey.SparseCsrMAIA: 111>
|
| SparseCsrMPS = <DispatchKey.SparseCsrMPS: 104>
|
| SparseCsrMTIA = <DispatchKey.SparseCsrMTIA: 110>
|
| SparseCsrMeta = <DispatchKey.SparseCsrMeta: 115>
|
| SparseCsrPrivateUse1 = <DispatchKey.SparseCsrPrivateUse1: 112>
|
| SparseCsrPrivateUse2 = <DispatchKey.SparseCsrPrivateUse2: 113>
|
| SparseCsrPrivateUse3 = <DispatchKey.SparseCsrPrivateUse3: 114>
|
| SparseCsrVE = <DispatchKey.SparseCsrVE: 108>
|
| SparseCsrXLA = <DispatchKey.SparseCsrXLA: 103>
|
| SparseCsrXPU = <DispatchKey.SparseCsrXPU: 106>
|
| SparseHIP = <DispatchKey.SparseHIP: 85>
|
| SparseHPU = <DispatchKey.SparseHPU: 90>
|
| SparseIPU = <DispatchKey.SparseIPU: 88>
|
| SparseLazy = <DispatchKey.SparseLazy: 92>
|
| SparseMAIA = <DispatchKey.SparseMAIA: 94>
|
| SparseMPS = <DispatchKey.SparseMPS: 87>
|
| SparseMTIA = <DispatchKey.SparseMTIA: 93>
|
| SparseMeta = <DispatchKey.SparseMeta: 98>
|
| SparsePrivateUse1 = <DispatchKey.SparsePrivateUse1: 95>
|
| SparsePrivateUse2 = <DispatchKey.SparsePrivateUse2: 96>
|
| SparsePrivateUse3 = <DispatchKey.SparsePrivateUse3: 97>
|
| SparseVE = <DispatchKey.SparseVE: 91>
|
| SparseXLA = <DispatchKey.SparseXLA: 86>
|
| SparseXPU = <DispatchKey.SparseXPU: 89>
|
| StartOfAutogradFunctionalityBackends = <DispatchKey.StartOfAutogradFun...
|
| StartOfDenseBackends = <DispatchKey.StartOfDenseBackends: 48>
|
| StartOfNestedTensorBackends = <DispatchKey.StartOfNestedTensorBackends...
|
| StartOfQuantizedBackends = <DispatchKey.StartOfQuantizedBackends: 65>
|
| StartOfSparseBackends = <DispatchKey.StartOfSparseBackends: 82>
|
| StartOfSparseCsrBackends = <DispatchKey.StartOfSparseCsrBackends: 99>
|
| Undefined = <DispatchKey.Undefined: 0>
|
| VE = <DispatchKey.VE: 57>
|
| XLA = <DispatchKey.XLA: 52>
|
| XPU = <DispatchKey.XPU: 55>
|
| ZeroTensor = <DispatchKey.ZeroTensor: 18>
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class DispatchKeySet(pybind11_builtins.pybind11_object)
| Method resolution order:
| DispatchKeySet
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __and__(...)
| __and__(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKeySet) -> torch._C.DispatchKeySet
|
| __eq__(...)
| __eq__(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKeySet) -> bool
|
| __getstate__(...)
| __getstate__(self: torch._C.DispatchKeySet, /) -> tuple[int]
|
| __init__(...)
| __init__(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKey) -> None
|
| __or__(...)
| __or__(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKeySet) -> torch._C.DispatchKeySet
|
| __repr__(...)
| __repr__(self: torch._C.DispatchKeySet) -> str
|
| __setstate__(...)
| __setstate__(self: torch._C.DispatchKeySet, arg0: tuple) -> None
|
| __sub__(...)
| __sub__(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKeySet) -> torch._C.DispatchKeySet
|
| add(...)
| add(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKey) -> torch._C.DispatchKeySet
|
| has(...)
| has(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKey) -> bool
|
| highestPriorityTypeId(...)
| highestPriorityTypeId(self: torch._C.DispatchKeySet) -> torch._C.DispatchKey
|
| raw_repr(...)
| raw_repr(self: torch._C.DispatchKeySet) -> int
|
| remove(...)
| remove(self: torch._C.DispatchKeySet, arg0: torch._C.DispatchKey) -> torch._C.DispatchKeySet
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| from_raw_repr(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| from_raw_repr(arg0: typing.SupportsInt | typing.SupportsIndex) -> torch._C.DispatchKeySet
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class DoubleStorage(torch.storage._LegacyStorage)
| DoubleStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| DoubleStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.float64
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class DoubleTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.float64
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class EnumType(Type)
| Method resolution order:
| EnumType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.EnumType, arg0: str, arg1: torch._C.Type, arg2: collections.abc.Sequence[object]) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ErrorReport(pybind11_builtins.pybind11_object)
| Method resolution order:
| ErrorReport
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.ErrorReport, arg0: torch._C._jit_tree_views.SourceRange) -> None
|
| what(...)
| what(self: torch._C.ErrorReport) -> str
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| call_stack(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| call_stack() -> str
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Event(builtins.object)
| Event(device=None, *, enable_timing=False, blocking=False, interprocess=False)
|
| Query and record Stream status to identify or control dependencies across Stream and measure timing.
|
| Arguments:
| device (:class:`torch.device`, optional): the desired device for the Event.
| If not given, the current :ref:`accelerator<accelerators>` type will be used.
| enable_timing (bool, optional): indicates if the event should measure time (default: ``False``)
| blocking (bool, optional): if ``True``, :meth:`wait` will be blocking (default: ``False``)
| interprocess (bool): if ``True``, the event can be shared between processes (default: ``False``)
|
| .. warning::
|
| Both blocking and interprocess are not supported right now and are noops.
|
| Returns:
| Event: An torch.Event object.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> event = torch.Event()
| >>> e_cuda = torch.Event(device='cuda')
|
| Methods defined here:
|
| __repr__(self, /)
| Return repr(self).
|
| elapsed_time(...)
| Event.elapsed_time(end_event) -> float
|
| Returns the elapsed time in milliseconds between when this event and the :attr:`end_event` are
| each recorded via :func:`torch.Stream.record_event`.
|
| Arguments:
| end_event (:class:`torch.Event`): The ending event has been recorded.
|
| Returns:
| float: Time between starting and ending event in milliseconds.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> s_cuda = torch.Stream(device='cuda')
| >>> e1_cuda = s_cuda.record_event()
| >>> e2_cuda = s_cuda.record_event()
| >>> ms = e1_cuda.elapsed_time(e2_cuda)
|
| ipc_handle(...)
|
| query(...)
| Event.query() -> bool
|
| Check if the stream where this event was recorded already moved past the point where the event was recorded.
| Always returns ``True`` if the Event was not recorded.
|
| Returns:
| bool: A boolean indicating if all work currently captured by event has completed.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> s_cuda = torch.Stream(device='cuda')
| >>> e_cuda = s_cuda.record_event()
| >>> e_cuda.query()
| True
|
| record(...)
| Event.record(stream=None) -> None
|
| Record the event in a given stream. The stream's device must match the event's device.
| This function is equivalent to ``stream.record_event(self)``.
|
| Arguments:
| stream (:class:`torch.Stream`, optional): A stream to be recorded.
| If not given, the current stream will be used.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> e_cuda = torch.Event(device='cuda')
| >>> e_cuda.record()
|
| synchronize(...)
| Event.synchronize() -> None
|
| Wait for the event to complete. This prevents the CPU thread from proceeding until the event completes.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> s_cuda = torch.Stream(device='cuda')
| >>> e_cuda = s_cuda.record_event()
| >>> e_cuda.synchronize()
|
| wait(...)
| Event.wait(stream=None) -> None
|
| Make all future work submitted to the given stream wait for this event.
|
| Arguments:
| stream (:class:`torch.Stream`, optional): A stream to synchronize.
| If not given, the current stream will be used.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> s1_cuda = torch.Stream(device='cuda')
| >>> s2_cuda = torch.Stream(device='cuda')
| >>> e_cuda = s1_cuda.record()
| >>> e_cuda.wait(s2)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_ipc_handle(...)
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| device
|
| event_id
class ExcludeDispatchKeyGuard(pybind11_builtins.pybind11_object)
| Method resolution order:
| ExcludeDispatchKeyGuard
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __enter__(...)
| __enter__(self: torch._C.ExcludeDispatchKeyGuard) -> None
|
| __exit__(...)
| __exit__(self: torch._C.ExcludeDispatchKeyGuard, arg0: object, arg1: object, arg2: object) -> None
|
| __init__(...)
| __init__(self: torch._C.ExcludeDispatchKeyGuard, arg0: torch._C.DispatchKeySet) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ExecutionPlan(pybind11_builtins.pybind11_object)
| Method resolution order:
| ExecutionPlan
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| code
|
| graph
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class FatalError(builtins.Exception)
| Method resolution order:
| FatalError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class FileCheck(pybind11_builtins.pybind11_object)
| Method resolution order:
| FileCheck
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.FileCheck) -> None
|
| check(...)
| check(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck
|
| check_count(...)
| check_count(*args, **kwargs)
| Overloaded function.
|
| 1. check_count(self: torch._C.FileCheck, arg0: str, arg1: typing.SupportsInt | typing.SupportsIndex, arg2: bool) -> torch._C.FileCheck
|
| 2. check_count(self: torch._C.FileCheck, str: str, count: typing.SupportsInt | typing.SupportsIndex, exactly: bool = False) -> torch._C.FileCheck
|
| Check Count
|
| check_dag(...)
| check_dag(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck
|
| check_next(...)
| check_next(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck
|
| check_not(...)
| check_not(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck
|
| check_regex(...)
| check_regex(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck
|
| check_same(...)
| check_same(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck
|
| check_source_highlighted(...)
| check_source_highlighted(self: torch._C.FileCheck, arg0: str) -> torch._C.FileCheck
|
| run(...)
| run(*args, **kwargs)
| Overloaded function.
|
| 1. run(self: torch._C.FileCheck, arg0: str) -> None
|
| 2. run(self: torch._C.FileCheck, arg0: torch._C.Graph) -> None
|
| 3. run(self: torch._C.FileCheck, checks_file: str, test_file: str) -> None
|
| Run
|
| 4. run(self: torch._C.FileCheck, checks_file: str, graph: torch._C.Graph) -> None
|
| Run
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class FloatStorage(torch.storage._LegacyStorage)
| FloatStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| FloatStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.float32
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class FloatTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.float32
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class FloatType(Type)
| Method resolution order:
| FloatType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.FloatType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class FunctionSchema(pybind11_builtins.pybind11_object)
| Method resolution order:
| FunctionSchema
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __eq__(...)
| __eq__(self: torch._C.FunctionSchema, arg0: torch._C.FunctionSchema) -> bool
|
| __getstate__(...)
| __getstate__(self: torch._C.FunctionSchema, /) -> str
|
| __hash__(...)
| __hash__(self: torch._C.FunctionSchema) -> int
|
| __init__(...)
| __init__(self: torch._C.FunctionSchema, arg0: str, arg1: str, arg2: collections.abc.Sequence[c10::Argument], arg3: collections.abc.Sequence[c10::Argument], arg4: bool, arg5: bool) -> None
|
| __repr__(...)
| __repr__(self: torch._C.FunctionSchema) -> str
|
| __setstate__(...)
| __setstate__(self: torch._C.FunctionSchema, arg0: str) -> None
|
| __str__(...)
| __str__(self: torch._C.FunctionSchema) -> str
|
| check_forward_compatible_with(...)
| check_forward_compatible_with(self: torch._C.FunctionSchema, arg0: torch._C.FunctionSchema) -> tuple[bool, str]
|
| is_backward_compatible_with(...)
| is_backward_compatible_with(self: torch._C.FunctionSchema, arg0: torch._C.FunctionSchema) -> bool
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| arguments
|
| is_mutable
|
| name
|
| overload_name
|
| returns
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Future(pybind11_builtins.pybind11_object)
| Method resolution order:
| Future
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __getstate__(...)
| __getstate__(self: torch._C.Future, /) -> tuple
|
| __init__(...)
| __init__(self: torch._C.Future, arg0: collections.abc.Sequence[torch.device]) -> None
|
| __setstate__(...)
| __setstate__(self: torch._C.Future, arg0: tuple) -> None
|
| add_done_callback(...)
| add_done_callback(self: torch._C.Future, arg0: collections.abc.Callable) -> None
|
| done(...)
| done(self: torch._C.Future) -> bool
|
| set_result(...)
| set_result(self: torch._C.Future, arg0: object) -> None
|
| then(...)
| then(self: torch._C.Future, arg0: collections.abc.Callable) -> torch._C.Future
|
| value(...)
| value(self: torch._C.Future) -> object
|
| wait(...)
| wait(self: torch._C.Future) -> object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class FutureType(Type)
| Method resolution order:
| FutureType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.FutureType, arg0: torch._C.Type) -> None
|
| getElementType(...)
| getElementType(self: torch._C.FutureType) -> torch._C.Type
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Generator(builtins.object)
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __setstate__(...)
|
| clone_state(...)
| Generator.clone_state() -> torch.Generator
|
| Clones the current state of the generator and returns a new generator pointing to this cloned state.
| This method is beneficial for preserving a particular state of a generator to restore at a later point.
|
| Returns:
| torch.Generator: A Generator pointing to the newly cloned state.
|
| Example:
| >>> g_cuda = torch.Generator(device='cuda')
| >>> cloned_state = g_cuda.clone_state()
|
| get_offset(...)
|
| get_state(...)
| Generator.get_state() -> Tensor
|
| Returns the Generator state as a ``torch.ByteTensor``.
|
| Returns:
| Tensor: A ``torch.ByteTensor`` which contains all the necessary bits
| to restore a Generator to a specific point in time.
|
| Example::
|
| >>> g_cpu = torch.Generator()
| >>> g_cpu.get_state()
|
| graphsafe_get_state(...)
| Generator.graphsafe_get_state() -> torch.Generator
|
| Retrieves the current state of the generator in a manner that is safe for graph capture.
| This method is crucial for ensuring that the generator's state can be captured in the CUDA graph.
|
| Returns:
| torch.Generator: A Generator point to the current state of the generator
|
| Example:
| >>> g_cuda = torch.Generator(device='cuda')
| >>> current_state = g_cuda.graphsafe_get_state()
|
| graphsafe_set_state(...)
| Generator.graphsafe_set_state(state) -> None
|
| Sets the state of the generator to the specified state in a manner that is safe for use in graph capture.
| This method is crucial for ensuring that the generator's state can be captured in the CUDA graph.
|
| Arguments:
| state (torch.Generator): A Generator point to the new state for the generator, typically obtained from `graphsafe_get_state`.
|
| Example:
| >>> g_cuda = torch.Generator(device='cuda')
| >>> g_cuda_other = torch.Generator(device='cuda')
| >>> current_state = g_cuda_other.graphsafe_get_state()
| >>> g_cuda.graphsafe_set_state(current_state)
|
| initial_seed(...)
| Generator.initial_seed() -> int
|
| Returns the initial seed for generating random numbers.
|
| Example::
|
| >>> g_cpu = torch.Generator()
| >>> g_cpu.initial_seed()
| 2147483647
|
| manual_seed(...)
| Generator.manual_seed(seed) -> Generator
|
| Sets the seed for generating random numbers. Returns a `torch.Generator` object. Any 32-bit integer is a valid seed.
|
| Arguments:
| seed (int): The desired seed. Value must be within the inclusive range
| `[-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]`. Otherwise, a RuntimeError
| is raised. Negative inputs are remapped to positive values with the formula
| `0xffff_ffff_ffff_ffff + seed`.
|
| Returns:
| Generator: An torch.Generator object.
|
| Example::
|
| >>> g_cpu = torch.Generator()
| >>> g_cpu.manual_seed(2147483647)
|
| seed(...)
| Generator.seed() -> int
|
| Gets a non-deterministic random number from std::random_device or the current
| time and uses it to seed a Generator.
|
| Example::
|
| >>> g_cpu = torch.Generator()
| >>> g_cpu.seed()
| 1516516984916
|
| set_offset(...)
|
| set_state(...)
| Generator.set_state(new_state) -> void
|
| Sets the Generator state.
|
| Arguments:
| new_state (torch.ByteTensor): The desired state.
|
| Example::
|
| >>> g_cpu = torch.Generator()
| >>> g_cpu_other = torch.Generator()
| >>> g_cpu.set_state(g_cpu_other.get_state())
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| device
| Generator.device -> device
|
| Gets the current device of the generator.
|
| Example::
|
| >>> g_cpu = torch.Generator()
| >>> g_cpu.device
| device(type='cpu')
class GradScaler(builtins.object)
| GradScaler(device: 'str' = 'cuda', init_scale: 'float' = 65536.0, growth_factor: 'float' = 2.0, backoff_factor: 'float' = 0.5, growth_interval: 'int' = 2000, enabled: 'bool' = True) -> 'None'
|
| An instance ``scaler`` of :class:`GradScaler`.
|
| Helps perform the steps of gradient scaling
| conveniently.
|
| * ``scaler.scale(loss)`` multiplies a given loss by ``scaler``'s current scale factor.
| * ``scaler.step(optimizer)`` safely unscales gradients and calls ``optimizer.step()``.
| * ``scaler.update()`` updates ``scaler``'s scale factor.
|
| Example::
|
| # Creates a GradScaler once at the beginning of training.
| scaler = GradScaler()
|
| for epoch in epochs:
| for input, target in data:
| optimizer.zero_grad()
| output = model(input)
| loss = loss_fn(output, target)
|
| # Scales loss. Calls backward() on scaled loss to create scaled gradients.
| scaler.scale(loss).backward()
|
| # scaler.step() first unscales gradients of the optimizer's params.
| # If gradients don't contain infs/NaNs, optimizer.step() is then called,
| # otherwise, optimizer.step() is skipped.
| scaler.step(optimizer)
|
| # Updates the scale for next iteration.
| scaler.update()
|
| See the :ref:`Automatic Mixed Precision examples<amp-examples>` for usage
| (along with autocasting) in more complex cases like gradient clipping, gradient accumulation, gradient penalty,
| and multiple losses/optimizers.
|
| ``scaler`` dynamically estimates the scale factor each iteration. To minimize gradient underflow,
| a large scale factor should be used. However, ``float16`` values can "overflow" (become inf or NaN) if
| the scale factor is too large. Therefore, the optimal scale factor is the largest factor that can be used
| without incurring inf or NaN gradient values.
| ``scaler`` approximates the optimal scale factor over time by checking the gradients for infs and NaNs during every
| ``scaler.step(optimizer)`` (or optional separate ``scaler.unscale_(optimizer)``, see :meth:`unscale_`).
|
| * If infs/NaNs are found, ``scaler.step(optimizer)`` skips the underlying ``optimizer.step()`` (so the params
| themselves remain uncorrupted) and ``update()`` multiplies the scale by ``backoff_factor``.
|
| * If no infs/NaNs are found, ``scaler.step(optimizer)`` runs the underlying ``optimizer.step()`` as usual.
| If ``growth_interval`` unskipped iterations occur consecutively, ``update()`` multiplies the scale by
| ``growth_factor``.
|
| The scale factor often causes infs/NaNs to appear in gradients for the first few iterations as its
| value calibrates. ``scaler.step`` will skip the underlying ``optimizer.step()`` for these
| iterations. After that, step skipping should occur rarely (once every few hundred or thousand iterations).
|
| Args:
| device (str, optional, default="cuda"): Device type to use. Possible values are: 'cuda' and 'cpu'.
| The type is the same as the `type` attribute of a :class:`torch.device`.
| Thus, you may obtain the device type of a tensor using `Tensor.device.type`.
| init_scale (float, optional, default=2.**16): Initial scale factor.
| growth_factor (float, optional, default=2.0): Factor by which the scale is multiplied during
| :meth:`update` if no inf/NaN gradients occur for ``growth_interval`` consecutive iterations.
| backoff_factor (float, optional, default=0.5): Factor by which the scale is multiplied during
| :meth:`update` if inf/NaN gradients occur in an iteration.
| growth_interval (int, optional, default=2000): Number of consecutive iterations without inf/NaN gradients
| that must occur for the scale to be multiplied by ``growth_factor``.
| enabled (bool, optional): If ``False``, disables gradient scaling. :meth:`step` simply
| invokes the underlying ``optimizer.step()``, and other methods become no-ops.
| Default: ``True``
|
| Methods defined here:
|
| __getstate__(self) -> 'dict[str, Any]'
| Helper for pickle.
|
| __init__(self, device: 'str' = 'cuda', init_scale: 'float' = 65536.0, growth_factor: 'float' = 2.0, backoff_factor: 'float' = 0.5, growth_interval: 'int' = 2000, enabled: 'bool' = True) -> 'None'
| Initialize self. See help(type(self)) for accurate signature.
|
| __setstate__(self, state: 'dict[str, Any]') -> 'None'
|
| get_backoff_factor(self) -> 'float'
| Return a Python float containing the scale backoff factor.
|
| get_growth_factor(self) -> 'float'
| Return a Python float containing the scale growth factor.
|
| get_growth_interval(self) -> 'int'
| Return a Python int containing the growth interval.
|
| get_scale(self) -> 'float'
| Return a Python float containing the current scale, or 1.0 if scaling is disabled.
|
| .. warning::
| :meth:`get_scale` incurs a CPU-GPU sync.
|
| is_enabled(self) -> 'bool'
| Return a bool indicating whether this instance is enabled.
|
| load_state_dict(self, state_dict: 'dict[str, Any]') -> 'None'
| Load the scaler state.
|
| If this instance is disabled, :meth:`load_state_dict` is a no-op.
|
| Args:
| state_dict(dict): scaler state. Should be an object returned from a call to :meth:`state_dict`.
|
| scale(self, outputs: 'torch.Tensor | Iterable[torch.Tensor]') -> 'torch.Tensor | Iterable[torch.Tensor]'
| Multiplies ('scales') a tensor or list of tensors by the scale factor.
|
| Returns scaled outputs. If this instance of :class:`GradScaler` is not enabled, outputs are returned
| unmodified.
|
| Args:
| outputs (Tensor or iterable of Tensors): Outputs to scale.
|
| set_backoff_factor(self, new_factor: 'float') -> 'None'
| Set a new scale backoff factor.
|
| Args:
| new_scale (float): Value to use as the new scale backoff factor.
|
| set_growth_factor(self, new_factor: 'float') -> 'None'
| Set a new scale growth factor.
|
| Args:
| new_scale (float): Value to use as the new scale growth factor.
|
| set_growth_interval(self, new_interval: 'int') -> 'None'
| Set a new growth interval.
|
| Args:
| new_interval (int): Value to use as the new growth interval.
|
| state_dict(self) -> 'dict[str, Any]'
| Return the state of the scaler as a :class:`dict`.
|
| It contains five entries:
|
| * ``"scale"`` - a Python float containing the current scale
| * ``"growth_factor"`` - a Python float containing the current growth factor
| * ``"backoff_factor"`` - a Python float containing the current backoff factor
| * ``"growth_interval"`` - a Python int containing the current growth interval
| * ``"_growth_tracker"`` - a Python int containing the number of recent consecutive unskipped steps.
|
| If this instance is not enabled, returns an empty dict.
|
| .. note::
| If you wish to checkpoint the scaler's state after a particular iteration, :meth:`state_dict`
| should be called after :meth:`update`.
|
| step(self, optimizer: 'torch.optim.Optimizer', *args: 'Any', **kwargs: 'Any') -> 'float | None'
| Invoke ``unscale_(optimizer)`` followed by parameter update, if gradients are not infs/NaN.
|
| :meth:`step` carries out the following two operations:
|
| 1. Internally invokes ``unscale_(optimizer)`` (unless :meth:`unscale_` was explicitly called for ``optimizer``
| earlier in the iteration). As part of the :meth:`unscale_`, gradients are checked for infs/NaNs.
| 2. If no inf/NaN gradients are found, invokes ``optimizer.step()`` using the unscaled
| gradients. Otherwise, ``optimizer.step()`` is skipped to avoid corrupting the params.
|
| ``*args`` and ``**kwargs`` are forwarded to ``optimizer.step()``.
|
| Returns the return value of ``optimizer.step(*args, **kwargs)``.
|
| Args:
| optimizer (torch.optim.Optimizer): Optimizer that applies the gradients.
| args: Any arguments.
| kwargs: Any keyword arguments.
|
| .. warning::
| Closure use is not currently supported.
|
| unscale_(self, optimizer: 'torch.optim.Optimizer') -> 'None'
| Divides ("unscales") the optimizer's gradient tensors by the scale factor.
|
| :meth:`unscale_` is optional, serving cases where you need to
| :ref:`modify or inspect gradients<working-with-unscaled-gradients>`
| between the backward pass(es) and :meth:`step`.
| If :meth:`unscale_` is not called explicitly, gradients will be unscaled automatically during :meth:`step`.
|
| Simple example, using :meth:`unscale_` to enable clipping of unscaled gradients::
|
| ...
| scaler.scale(loss).backward()
| scaler.unscale_(optimizer)
| torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm)
| scaler.step(optimizer)
| scaler.update()
|
| Args:
| optimizer (torch.optim.Optimizer): Optimizer that owns the gradients to be unscaled.
|
| .. note::
| :meth:`unscale_` does not incur a CPU-GPU sync.
|
| .. warning::
| :meth:`unscale_` should only be called once per optimizer per :meth:`step` call,
| and only after all gradients for that optimizer's assigned parameters have been accumulated.
| Calling :meth:`unscale_` twice for a given optimizer between each :meth:`step` triggers a RuntimeError.
|
| .. warning::
| :meth:`unscale_` may unscale sparse gradients out of place, replacing the ``.grad`` attribute.
|
| update(self, new_scale: 'float | torch.Tensor | None' = None) -> 'None'
| Update the scale factor.
|
| If any optimizer steps were skipped the scale is multiplied by ``backoff_factor``
| to reduce it. If ``growth_interval`` unskipped iterations occurred consecutively,
| the scale is multiplied by ``growth_factor`` to increase it.
|
| Passing ``new_scale`` sets the new scale value manually. (``new_scale`` is not
| used directly, it's used to fill GradScaler's internal scale tensor. So if
| ``new_scale`` was a tensor, later in-place changes to that tensor will not further
| affect the scale GradScaler uses internally.)
|
| Args:
| new_scale (float or :class:`torch.Tensor`, optional, default=None): New scale factor.
|
| .. warning::
| :meth:`update` should only be called at the end of the iteration, after ``scaler.step(optimizer)`` has
| been invoked for all optimizers used this iteration.
|
| .. warning::
| For performance reasons, we do not check the scale factor value to avoid synchronizations,
| so the scale factor is not guaranteed to be above 1. If the scale falls below 1 and/or
| you are seeing NaNs in your gradients or loss, something is likely wrong. For example,
| bf16-pretrained models are often incompatible with AMP/fp16 due to differing dynamic ranges.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Gradient(pybind11_builtins.pybind11_object)
| Method resolution order:
| Gradient
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| df
|
| df_input_captured_inputs
|
| df_input_captured_outputs
|
| df_input_vjps
|
| df_output_vjps
|
| f
|
| f_real_outputs
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Graph(pybind11_builtins.pybind11_object)
| Method resolution order:
| Graph
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.Graph) -> None
|
| __repr__(...)
| __repr__(self: torch._C.Graph) -> str
|
| addInput(...)
| addInput(self: torch._C.Graph, name: str = '') -> torch::jit::Value
|
| Add input to graph with optional name seed
|
| alias_db(...)
| alias_db(self: torch._C.Graph, isFrozen: bool = False, descend_function_calls: bool = False) -> torch._C.AliasDb
|
| appendNode(...)
| appendNode(self: torch._C.Graph, arg0: torch::jit::Node) -> torch::jit::Node
|
| block(...)
| block(self: torch._C.Graph) -> torch::jit::Block
|
| copy(...)
| copy(self: torch._C.Graph) -> torch._C.Graph
|
| create(...)
| create(*args, **kwargs)
| Overloaded function.
|
| 1. create(self: torch._C.Graph, arg0: str) -> torch::jit::Node
|
| 2. create(self: torch._C.Graph, arg0: str, arg1: typing.SupportsInt | typing.SupportsIndex) -> torch::jit::Node
|
| 3. create(self: torch._C.Graph, arg0: str, arg1: collections.abc.Sequence[torch::jit::Value]) -> torch::jit::Node
|
| 4. create(self: torch._C.Graph, arg0: str, arg1: collections.abc.Sequence[torch::jit::Value], arg2: typing.SupportsInt | typing.SupportsIndex) -> torch::jit::Node
|
| createClone(...)
| createClone(self: torch._C.Graph, arg0: torch::jit::Node, arg1: object) -> torch::jit::Node
|
| createCudaFusionGroup(...)
| createCudaFusionGroup(self: torch._C.Graph) -> torch::jit::Node
|
| createFusionGroup(...)
| createFusionGroup(self: torch._C.Graph) -> torch::jit::Node
|
| dump_alias_db(...)
| dump_alias_db(self: torch._C.Graph) -> None
|
| eraseInput(...)
| eraseInput(self: torch._C.Graph, arg0: typing.SupportsInt | typing.SupportsIndex) -> None
|
| eraseOutput(...)
| eraseOutput(self: torch._C.Graph, arg0: typing.SupportsInt | typing.SupportsIndex) -> None
|
| findAllNodes(...)
| findAllNodes(self: torch._C.Graph, kind: str, recurse: bool = True) -> list[torch::jit::Node]
|
| Find all nodes
|
| findNode(...)
| findNode(self: torch._C.Graph, kind: str, recurse: bool = True) -> torch::jit::Node
|
| Find Node
|
| inputs(...)
| inputs(self: torch._C.Graph) -> collections.abc.Iterator[torch::jit::Value]
|
| insert(...)
| insert(self: torch._C.Graph, arg0: Symbol, arg1: collections.abc.Sequence[torch::jit::Value]) -> torch::jit::Value
|
| insertConstant(...)
| insertConstant(self: torch._C.Graph, arg0: IValue) -> torch::jit::Value
|
| insertGraph(...)
| insertGraph(*args, **kwargs)
| Overloaded function.
|
| 1. insertGraph(self: torch._C.Graph, arg0: torch._C.Graph, arg1: collections.abc.Sequence[torch::jit::Value]) -> list[torch::jit::Value]
|
| 2. insertGraph(self: torch._C.Graph, arg0: torch._C.Graph, arg1: collections.abc.Sequence[torch::jit::Value], arg2: collections.abc.Mapping[torch::jit::Value, torch::jit::Value]) -> list[torch::jit::Value]
|
| insertNode(...)
| insertNode(self: torch._C.Graph, arg0: torch::jit::Node) -> torch::jit::Node
|
| insertPoint(...)
| insertPoint(self: torch._C.Graph) -> torch::jit::Node
|
| insert_point_guard(...)
| insert_point_guard(*args, **kwargs)
| Overloaded function.
|
| 1. insert_point_guard(self: torch._C.Graph, arg0: torch::jit::Node) -> object
|
| 2. insert_point_guard(self: torch._C.Graph, arg0: torch::jit::Block) -> object
|
| lint(...)
| lint(self: torch._C.Graph) -> None
|
| makeMultiOutputIntoTuple(...)
| makeMultiOutputIntoTuple(self: torch._C.Graph) -> None
|
| nodes(...)
| nodes(self: torch._C.Graph) -> collections.abc.Iterator[torch::jit::Node]
|
| outputs(...)
| outputs(self: torch._C.Graph) -> collections.abc.Iterator[torch::jit::Value]
|
| param_node(...)
| param_node(self: torch._C.Graph) -> torch::jit::Node
|
| permuteInputs(...)
| permuteInputs(self: torch._C.Graph, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> None
|
| prependNode(...)
| prependNode(self: torch._C.Graph, arg0: torch::jit::Node) -> torch::jit::Node
|
| registerOutput(...)
| registerOutput(self: torch._C.Graph, arg0: torch::jit::Value) -> int
|
| return_node(...)
| return_node(self: torch._C.Graph) -> torch::jit::Node
|
| setInsertPoint(...)
| setInsertPoint(*args, **kwargs)
| Overloaded function.
|
| 1. setInsertPoint(self: torch._C.Graph, arg0: torch::jit::Node) -> None
|
| 2. setInsertPoint(self: torch._C.Graph, arg0: torch::jit::Block) -> None
|
| str(...)
| str(self: torch._C.Graph, print_source_ranges: bool = True) -> str
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| set_global_print_source_ranges(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| set_global_print_source_ranges(enabled: bool = True) -> None
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| global_print_source_ranges
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class GraphExecutorState(pybind11_builtins.pybind11_object)
| Method resolution order:
| GraphExecutorState
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| execution_plans
|
| fallback
|
| graph
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class IODescriptor(pybind11_builtins.pybind11_object)
| Method resolution order:
| IODescriptor
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class InferredType(pybind11_builtins.pybind11_object)
| Method resolution order:
| InferredType
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(*args, **kwargs)
| Overloaded function.
|
| 1. __init__(self: torch._C.InferredType, arg0: torch._C.Type) -> None
|
| 2. __init__(self: torch._C.InferredType, arg0: str) -> None
|
| reason(...)
| reason(self: torch._C.InferredType) -> str
|
| success(...)
| success(self: torch._C.InferredType) -> bool
|
| type(...)
| type(self: torch._C.InferredType) -> torch._C.Type
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class IntStorage(torch.storage._LegacyStorage)
| IntStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| IntStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.int32
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class IntTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.int32
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class IntType(Type)
| Method resolution order:
| IntType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.IntType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class InterfaceType(Type)
| Method resolution order:
| InterfaceType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.InterfaceType, arg0: str) -> None
|
| getMethod(...)
| getMethod(self: torch._C.InterfaceType, arg0: str) -> torch._C.FunctionSchema
|
| getMethodNames(...)
| getMethodNames(self: torch._C.InterfaceType) -> list[str]
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
JITException = class Error(builtins.Exception)
| Method resolution order:
| Error
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ListType(Type)
| Method resolution order:
| ListType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.ListType, arg0: torch._C.Type) -> None
|
| getElementType(...)
| getElementType(self: torch._C.ListType) -> torch._C.Type
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| ofBools(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| ofBools() -> torch._C.ListType
|
| ofComplexDoubles(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| ofComplexDoubles() -> torch._C.ListType
|
| ofFloats(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| ofFloats() -> torch._C.ListType
|
| ofInts(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| ofInts() -> torch._C.ListType
|
| ofStrings(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| ofStrings() -> torch._C.ListType
|
| ofTensors(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| ofTensors() -> torch._C.ListType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class LiteScriptModule(pybind11_builtins.pybind11_object)
| Method resolution order:
| LiteScriptModule
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.LiteScriptModule, arg0: c10::ivalue::Object, arg1: torch::jit::mobile::CompilationUnit) -> None
|
| find_method(...)
| find_method(self: torch._C.LiteScriptModule, method_name: str) -> bool
|
| forward(...)
| forward(self: torch._C.LiteScriptModule, input_tuple: tuple) -> IValue
|
| run_method(...)
| run_method(self: torch._C.LiteScriptModule, method_name: str, input_tuple: tuple) -> IValue
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class LockingLogger(torch._C.LoggerBase)
| Method resolution order:
| LockingLogger
| torch._C.LoggerBase
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.LockingLogger) -> None
|
| get_counter_val(...)
| get_counter_val(self: torch._C.LockingLogger, arg0: str) -> int
|
| set_aggregation_type(...)
| set_aggregation_type(self: torch._C.LockingLogger, arg0: str, arg1: torch._C.AggregationType) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class LongStorage(torch.storage._LegacyStorage)
| LongStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| LongStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.int64
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class LongTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.int64
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class ModuleDict(pybind11_builtins.pybind11_object)
| Method resolution order:
| ModuleDict
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.ModuleDict, arg0: torch._C.ScriptModule) -> None
|
| contains(...)
| contains(self: torch._C.ModuleDict, arg0: str) -> bool
|
| getattr(...)
| getattr(self: torch._C.ModuleDict, arg0: str) -> object
|
| items(...)
| items(self: torch._C.ModuleDict) -> list[tuple[str, object]]
|
| setattr(...)
| setattr(self: torch._C.ModuleDict, arg0: str, arg1: object) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Node(pybind11_builtins.pybind11_object)
| Method resolution order:
| Node
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(...)
| __repr__(self: torch._C.Node) -> str
|
| addBlock(...)
| addBlock(self: torch._C.Node) -> torch._C.Block
|
| addInput(...)
| addInput(self: torch._C.Node, arg0: torch._C.Value) -> torch._C.Value
|
| addOutput(...)
| addOutput(self: torch._C.Node) -> torch._C.Value
|
| attributeNames(...)
| attributeNames(self: torch._C.Node) -> list[str]
|
| blocks(...)
| blocks(self: torch._C.Node) -> collections.abc.Iterator[torch._C.Block]
|
| c(...)
| c(self: torch._C.Node, arg0: str) -> complex
|
| c_(...)
| c_(self: torch._C.Node, arg0: str, arg1: complex) -> torch._C.Node
|
| cconv(...)
| cconv(self: torch._C.Node) -> str
|
| copyAttributes(...)
| copyAttributes(self: torch._C.Node, arg0: torch._C.Node) -> torch._C.Node
|
| copyMetadata(...)
| copyMetadata(self: torch._C.Node, arg0: torch._C.Node) -> torch._C.Node
|
| destroy(...)
| destroy(self: torch._C.Node) -> None
|
| eraseOutput(...)
| eraseOutput(self: torch._C.Node, arg0: typing.SupportsInt | typing.SupportsIndex) -> None
|
| f(...)
| f(self: torch._C.Node, arg0: str) -> float
|
| f_(...)
| f_(self: torch._C.Node, arg0: str, arg1: typing.SupportsFloat | typing.SupportsIndex) -> torch._C.Node
|
| findAllNodes(...)
| findAllNodes(self: torch._C.Node, kind: str, recurse: bool = True) -> list[torch._C.Node]
|
| Find all nodes
|
| findNode(...)
| findNode(self: torch._C.Node, kind: str, recurse: bool = True) -> torch._C.Node
|
| Find Node
|
| fs(...)
| fs(self: torch._C.Node, arg0: str) -> list[float]
|
| fs_(...)
| fs_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex]) -> torch._C.Node
|
| g(...)
| g(self: torch._C.Node, arg0: str) -> torch._C.Graph
|
| g_(...)
| g_(self: torch._C.Node, arg0: str, arg1: torch._C.Graph) -> torch._C.Node
|
| getModuleHierarchy(...)
| getModuleHierarchy(self: torch._C.Node) -> str
|
| gs(...)
| gs(self: torch._C.Node, arg0: str) -> list[torch._C.Graph]
|
| gs_(...)
| gs_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[torch._C.Graph]) -> torch._C.Node
|
| hasAttribute(...)
| hasAttribute(self: torch._C.Node, arg0: str) -> bool
|
| hasAttributes(...)
| hasAttributes(self: torch._C.Node) -> bool
|
| hasMultipleOutputs(...)
| hasMultipleOutputs(self: torch._C.Node) -> bool
|
| hasUses(...)
| hasUses(self: torch._C.Node) -> bool
|
| i(...)
| i(self: torch._C.Node, arg0: str) -> int
|
| i_(...)
| i_(self: torch._C.Node, arg0: str, arg1: typing.SupportsInt | typing.SupportsIndex) -> torch._C.Node
|
| input(...)
| input(self: torch._C.Node) -> torch._C.Value
|
| inputs(...)
| inputs(self: torch._C.Node) -> collections.abc.Iterator[torch._C.Value]
|
| inputsAt(...)
| inputsAt(self: torch._C.Node, arg0: typing.SupportsInt | typing.SupportsIndex) -> torch._C.Value
|
| inputsSize(...)
| inputsSize(self: torch._C.Node) -> int
|
| insertAfter(...)
| insertAfter(self: torch._C.Node, arg0: torch._C.Node) -> torch._C.Node
|
| insertBefore(...)
| insertBefore(self: torch._C.Node, arg0: torch._C.Node) -> torch._C.Node
|
| is(...)
| is(self: torch._C.Node, arg0: str) -> list[int]
|
| isAfter(...)
| isAfter(self: torch._C.Node, arg0: torch._C.Node) -> bool
|
| isBefore(...)
| isBefore(self: torch._C.Node, arg0: torch._C.Node) -> bool
|
| isNondeterministic(...)
| isNondeterministic(self: torch._C.Node) -> bool
|
| is_(...)
| is_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> torch._C.Node
|
| ival(...)
| ival(self: torch._C.Node, arg0: str) -> IValue
|
| ival_(...)
| ival_(self: torch._C.Node, arg0: str, arg1: IValue) -> torch._C.Node
|
| kind(...)
| kind(self: torch._C.Node) -> Symbol
|
| kindOf(...)
| kindOf(self: torch._C.Node, arg0: str) -> AttributeKind
|
| matches(...)
| matches(self: torch._C.Node, arg0: str) -> bool
|
| moveAfter(...)
| moveAfter(self: torch._C.Node, arg0: torch._C.Node) -> None
|
| moveBefore(...)
| moveBefore(self: torch._C.Node, arg0: torch._C.Node) -> None
|
| mustBeNone(...)
| mustBeNone(self: torch._C.Node) -> bool
|
| namedInput(...)
| namedInput(self: torch._C.Node, arg0: str) -> torch._C.Value
|
| output(...)
| output(self: torch._C.Node) -> torch._C.Value
|
| outputs(...)
| outputs(self: torch._C.Node) -> collections.abc.Iterator[torch._C.Value]
|
| outputsAt(...)
| outputsAt(self: torch._C.Node, arg0: typing.SupportsInt | typing.SupportsIndex) -> torch._C.Value
|
| outputsSize(...)
| outputsSize(self: torch._C.Node) -> int
|
| owningBlock(...)
| owningBlock(self: torch._C.Node) -> torch._C.Block
|
| prev(...)
| prev(self: torch._C.Node) -> torch._C.Node
|
| pyname(...)
| pyname(self: torch._C.Node) -> str
|
| pyobj(...)
| pyobj(self: torch._C.Node) -> object
|
| removeAllInputs(...)
| removeAllInputs(self: torch._C.Node) -> None
|
| removeAttribute(...)
| removeAttribute(self: torch._C.Node, arg0: str) -> torch._C.Node
|
| removeInput(...)
| removeInput(self: torch._C.Node, arg0: typing.SupportsInt | typing.SupportsIndex) -> None
|
| replaceAllUsesWith(...)
| replaceAllUsesWith(self: torch._C.Node, arg0: torch._C.Node) -> None
|
| replaceInput(...)
| replaceInput(self: torch._C.Node, arg0: typing.SupportsInt | typing.SupportsIndex, arg1: torch._C.Value) -> torch._C.Value
|
| replaceInputWith(...)
| replaceInputWith(self: torch._C.Node, arg0: torch._C.Value, arg1: torch._C.Value) -> None
|
| s(...)
| s(self: torch._C.Node, arg0: str) -> str
|
| s_(...)
| s_(self: torch._C.Node, arg0: str, arg1: str) -> torch._C.Node
|
| scalar_args(...)
| scalar_args(self: torch._C.Node) -> list
|
| schema(...)
| schema(self: torch._C.Node) -> str
|
| scopeName(...)
| scopeName(self: torch._C.Node) -> str
|
| sourceRange(...)
| sourceRange(self: torch._C.Node) -> str
|
| ss(...)
| ss(self: torch._C.Node, arg0: str) -> list[str]
|
| ss_(...)
| ss_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[str]) -> torch._C.Node
|
| t(...)
| t(self: torch._C.Node, arg0: str) -> torch.Tensor
|
| t_(...)
| t_(self: torch._C.Node, arg0: str, arg1: torch.Tensor) -> torch._C.Node
|
| ts(...)
| ts(self: torch._C.Node, arg0: str) -> list[torch.Tensor]
|
| ts_(...)
| ts_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[torch.Tensor]) -> torch._C.Node
|
| ty(...)
| ty(self: torch._C.Node, arg0: str) -> c10::Type
|
| ty_(...)
| ty_(self: torch._C.Node, arg0: str, arg1: c10::Type) -> torch._C.Node
|
| tys(...)
| tys(self: torch._C.Node, arg0: str) -> list[c10::Type]
|
| tys_(...)
| tys_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[c10::Type]) -> torch._C.Node
|
| z(...)
| z(self: torch._C.Node, arg0: str) -> torch.Tensor
|
| z_(...)
| z_(self: torch._C.Node, arg0: str, arg1: torch.Tensor) -> torch._C.Node
|
| zs(...)
| zs(self: torch._C.Node, arg0: str) -> list[torch.Tensor]
|
| zs_(...)
| zs_(self: torch._C.Node, arg0: str, arg1: collections.abc.Sequence[torch.Tensor]) -> torch._C.Node
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class NoneType(Type)
| Method resolution order:
| NoneType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.NoneType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class NoopLogger(torch._C.LoggerBase)
| Method resolution order:
| NoopLogger
| torch._C.LoggerBase
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.NoopLogger) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class NumberType(Type)
| Method resolution order:
| NumberType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.NumberType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class OperatorInfo(pybind11_builtins.pybind11_object)
| Method resolution order:
| OperatorInfo
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| num_schema_args
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class OptionalType(Type)
| Method resolution order:
| OptionalType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.OptionalType, arg0: torch._C.Type) -> None
|
| getElementType(...)
| getElementType(self: torch._C.OptionalType) -> torch._C.Type
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| ofTensor(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| ofTensor() -> torch._C.Type
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class OutOfMemoryError(builtins.RuntimeError)
| Exception raised when device is out of memory
|
| Method resolution order:
| OutOfMemoryError
| builtins.RuntimeError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.RuntimeError:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.RuntimeError:
|
| __new__(*args, **kwargs) class method of builtins.RuntimeError
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ParameterDict(pybind11_builtins.pybind11_object)
| Method resolution order:
| ParameterDict
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.ParameterDict, arg0: torch._C.ScriptModule) -> None
|
| contains(...)
| contains(self: torch._C.ParameterDict, arg0: str) -> bool
|
| getattr(...)
| getattr(self: torch._C.ParameterDict, arg0: str) -> object
|
| items(...)
| items(self: torch._C.ParameterDict) -> list[tuple[str, object]]
|
| setattr(...)
| setattr(self: torch._C.ParameterDict, arg0: str, arg1: object) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class PyObjectType(Type)
| Method resolution order:
| PyObjectType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.PyObjectType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class PyTorchFileReader(pybind11_builtins.pybind11_object)
| Method resolution order:
| PyTorchFileReader
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(*args, **kwargs)
| Overloaded function.
|
| 1. __init__(self: torch._C.PyTorchFileReader, arg0: str) -> None
|
| 2. __init__(self: torch._C.PyTorchFileReader, arg0: object) -> None
|
| get_all_records(...)
| get_all_records(self: torch._C.PyTorchFileReader) -> list[str]
|
| get_record(...)
| get_record(self: torch._C.PyTorchFileReader, arg0: str) -> bytes
|
| get_record_header_offset(...)
| get_record_header_offset(self: torch._C.PyTorchFileReader, arg0: str) -> int
|
| get_record_offset(...)
| get_record_offset(self: torch._C.PyTorchFileReader, arg0: str) -> int
|
| get_record_offset_no_read(...)
| get_record_offset_no_read(self: torch._C.PyTorchFileReader, arg0: typing.SupportsInt | typing.SupportsIndex, arg1: str, arg2: typing.SupportsInt | typing.SupportsIndex, arg3: typing.SupportsInt | typing.SupportsIndex) -> int
|
| get_record_size(...)
| get_record_size(self: torch._C.PyTorchFileReader, arg0: str) -> int
|
| get_storage_from_record(...)
| get_storage_from_record(self: torch._C.PyTorchFileReader, arg0: str, arg1: typing.SupportsInt | typing.SupportsIndex, arg2: object) -> torch.Tensor
|
| has_record(...)
| has_record(self: torch._C.PyTorchFileReader, arg0: str) -> bool
|
| serialization_id(...)
| serialization_id(self: torch._C.PyTorchFileReader) -> str
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class PyTorchFileWriter(pybind11_builtins.pybind11_object)
| Method resolution order:
| PyTorchFileWriter
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(*args, **kwargs)
| Overloaded function.
|
| 1. __init__(self: torch._C.PyTorchFileWriter, file_name: str, compute_crc32: bool = True, storage_alignment: typing.SupportsInt | typing.SupportsIndex = 64) -> None
|
| 2. __init__(self: torch._C.PyTorchFileWriter, buffer: object, compute_crc32: bool = True, storage_alignment: typing.SupportsInt | typing.SupportsIndex = 64) -> None
|
| 3. __init__(self: torch._C.PyTorchFileWriter, writer_func: collections.abc.Callable[[typing_extensions.CapsuleType, typing.SupportsInt | typing.SupportsIndex], int], compute_crc32: bool = True, storage_alignment: typing.SupportsInt | typing.SupportsIndex = 64) -> None
|
| archive_name(...)
| archive_name(self: torch._C.PyTorchFileWriter) -> str
|
| get_all_written_records(...)
| get_all_written_records(self: torch._C.PyTorchFileWriter) -> set[str]
|
| serialization_id(...)
| serialization_id(self: torch._C.PyTorchFileWriter) -> str
|
| set_min_version(...)
| set_min_version(self: torch._C.PyTorchFileWriter, arg0: typing.SupportsInt | typing.SupportsIndex) -> None
|
| write_end_of_file(...)
| write_end_of_file(self: torch._C.PyTorchFileWriter) -> None
|
| write_record(...)
| write_record(*args, **kwargs)
| Overloaded function.
|
| 1. write_record(self: torch._C.PyTorchFileWriter, arg0: str, arg1: str, arg2: typing.SupportsInt | typing.SupportsIndex) -> None
|
| 2. write_record(self: torch._C.PyTorchFileWriter, arg0: str, arg1: bytes, arg2: typing.SupportsInt | typing.SupportsIndex) -> None
|
| 3. write_record(self: torch._C.PyTorchFileWriter, arg0: str, arg1: torch.StorageBase, arg2: typing.SupportsInt | typing.SupportsIndex) -> None
|
| 4. write_record(self: torch._C.PyTorchFileWriter, arg0: str, arg1: typing.SupportsInt | typing.SupportsIndex, arg2: typing.SupportsInt | typing.SupportsIndex) -> None
|
| write_record_metadata(...)
| write_record_metadata(self: torch._C.PyTorchFileWriter, arg0: str, arg1: typing.SupportsInt | typing.SupportsIndex) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class RRefType(Type)
| Method resolution order:
| RRefType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.RRefType, arg0: torch._C.Type) -> None
|
| getElementType(...)
| getElementType(self: torch._C.RRefType) -> torch._C.Type
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptClass(pybind11_builtins.pybind11_object)
| Method resolution order:
| ScriptClass
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __call__(...)
| __call__(self: torch._C.ScriptClass, *args, **kwargs) -> object
|
| __getattr__(...)
| __getattr__(self: torch._C.ScriptClass, arg0: str) -> torch._C.ScriptClassFunction
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptClassFunction(pybind11_builtins.pybind11_object)
| Method resolution order:
| ScriptClassFunction
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __call__(...)
| __call__(*args, **kwargs) -> object
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptDict(pybind11_builtins.pybind11_object)
| Method resolution order:
| ScriptDict
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __bool__(...)
| __bool__(self: torch._C.ScriptDict) -> object
|
| __contains__(...)
| __contains__(self: torch._C.ScriptDict, arg0: object) -> object
|
| __delitem__(...)
| __delitem__(self: torch._C.ScriptDict, arg0: object) -> None
|
| __getitem__(...)
| __getitem__(self: torch._C.ScriptDict, arg0: object) -> object
|
| __init__(...)
| __init__(self: torch._C.ScriptDict, arg0: dict) -> None
|
| __iter__(...)
| __iter__(self: torch._C.ScriptDict) -> torch._C.ScriptDictKeyIterator
|
| __len__(...)
| __len__(self: torch._C.ScriptDict) -> object
|
| __repr__(...)
| __repr__(self: torch._C.ScriptDict) -> object
|
| __setitem__(...)
| __setitem__(self: torch._C.ScriptDict, arg0: object, arg1: object) -> None
|
| items(...)
| items(self: torch._C.ScriptDict) -> torch._C.ScriptDictIterator
|
| keys(...)
| keys(self: torch._C.ScriptDict) -> torch._C.ScriptDictKeyIterator
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptDictIterator(pybind11_builtins.pybind11_object)
| Method resolution order:
| ScriptDictIterator
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(...)
| __iter__(self: torch._C.ScriptDictIterator) -> torch._C.ScriptDictIterator
|
| __next__(...)
| __next__(self: torch._C.ScriptDictIterator) -> object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptDictKeyIterator(pybind11_builtins.pybind11_object)
| Method resolution order:
| ScriptDictKeyIterator
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(...)
| __iter__(self: torch._C.ScriptDictKeyIterator) -> torch._C.ScriptDictKeyIterator
|
| __next__(...)
| __next__(self: torch._C.ScriptDictKeyIterator) -> object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptFunction(pybind11_builtins.pybind11_object)
| Functionally equivalent to a :class:`ScriptModule`, but represents a single
| function and does not have any attributes or Parameters.
|
| Method resolution order:
| ScriptFunction
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __call__(...)
| __call__(*args, **kwargs) -> object
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce__ = _reduce(cls) from torch.jit._script
| # Throws an error if a jit function is pickled.
| # Helps to avoid Python crashes for Python versions 3.9.5 + when protocol 0 or 1 is given as an argument.
|
| get_debug_state(...)
| get_debug_state(self: torch._C.ScriptFunction) -> torch._C.GraphExecutorState
|
| graph_for = _graph_for(self, *args, **kwargs) from torch.jit._fuser
|
| save(...)
| save(self: torch._C.ScriptFunction, filename: str, _extra_files: collections.abc.Mapping[str, str] = {}) -> None
|
| save_to_buffer(...)
| save_to_buffer(self: torch._C.ScriptFunction, _extra_files: collections.abc.Mapping[str, str] = {}) -> bytes
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| code
|
| graph
|
| inlined_graph
|
| name
|
| qualified_name
|
| schema
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptList(pybind11_builtins.pybind11_object)
| Method resolution order:
| ScriptList
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __bool__(...)
| __bool__(self: torch._C.ScriptList) -> object
|
| __contains__(...)
| __contains__(self: torch._C.ScriptList, arg0: object) -> object
|
| __delitem__(...)
| __delitem__(self: torch._C.ScriptList, arg0: typing.SupportsInt | typing.SupportsIndex) -> None
|
| __getitem__(...)
| __getitem__(*args, **kwargs)
| Overloaded function.
|
| 1. __getitem__(self: torch._C.ScriptList, arg0: typing.SupportsInt | typing.SupportsIndex) -> object
|
| 2. __getitem__(self: torch._C.ScriptList, arg0: slice) -> torch._C.ScriptList
|
| __getstate__(...)
| __getstate__(self: torch._C.ScriptList, /) -> list
|
| __init__(...)
| __init__(self: torch._C.ScriptList, arg0: list) -> None
|
| __iter__(...)
| __iter__(self: torch._C.ScriptList) -> torch._C.ScriptListIterator
|
| __len__(...)
| __len__(self: torch._C.ScriptList) -> object
|
| __repr__(...)
| __repr__(self: torch._C.ScriptList) -> object
|
| __setitem__(...)
| __setitem__(*args, **kwargs)
| Overloaded function.
|
| 1. __setitem__(self: torch._C.ScriptList, arg0: typing.SupportsInt | typing.SupportsIndex, arg1: object) -> None
|
| 2. __setitem__(self: torch._C.ScriptList, arg0: slice, arg1: list) -> None
|
| __setstate__(...)
| __setstate__(self: torch._C.ScriptList, arg0: list) -> None
|
| append(...)
| append(self: torch._C.ScriptList, arg0: object) -> None
|
| clear(...)
| clear(self: torch._C.ScriptList) -> None
|
| count(...)
| count(self: torch._C.ScriptList, arg0: object) -> int
|
| extend(...)
| extend(*args, **kwargs)
| Overloaded function.
|
| 1. extend(self: torch._C.ScriptList, arg0: list) -> None
|
| 2. extend(self: torch._C.ScriptList, arg0: collections.abc.Iterable) -> None
|
| insert(...)
| insert(self: torch._C.ScriptList, arg0: typing.SupportsInt | typing.SupportsIndex, arg1: object) -> None
|
| pop(...)
| pop(*args, **kwargs)
| Overloaded function.
|
| 1. pop(self: torch._C.ScriptList) -> object
|
| 2. pop(self: torch._C.ScriptList, arg0: typing.SupportsInt | typing.SupportsIndex) -> object
|
| remove(...)
| remove(self: torch._C.ScriptList, arg0: object) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptListIterator(pybind11_builtins.pybind11_object)
| Method resolution order:
| ScriptListIterator
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(...)
| __iter__(self: torch._C.ScriptListIterator) -> torch._C.ScriptListIterator
|
| __next__(...)
| __next__(self: torch._C.ScriptListIterator) -> object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptMethod(pybind11_builtins.pybind11_object)
| Method resolution order:
| ScriptMethod
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __call__(...)
| __call__(*args, **kwargs) -> object
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| graph_for = _script_method_graph_for(self, parent, *args, **kwargs) from torch.jit._fuser
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| code
|
| code_with_constants
|
| graph
|
| inlined_graph
|
| name
|
| owner
|
| raw_owner
|
| schema
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptModule(ScriptObject)
| Method resolution order:
| ScriptModule
| ScriptObject
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __copy__(...)
| __copy__(self: torch._C.ScriptModule) -> torch._C.ScriptModule
|
| __deepcopy__(...)
| __deepcopy__(self: torch._C.ScriptModule, arg0: dict) -> torch._C.ScriptModule
|
| __eq__(...)
| __eq__(self: torch._C.ScriptModule, arg0: object) -> bool
|
| __hash__(...)
| __hash__(self: torch._C.ScriptModule) -> int
|
| __init__(...)
| __init__(self: torch._C.ScriptModule, arg0: str, arg1: torch::jit::CompilationUnit, arg2: bool) -> None
|
| apply(...)
| apply(self: torch._C.ScriptModule, arg0: collections.abc.Callable[[torch._C.ScriptModule], None]) -> None
|
| children(...)
| children(self: torch._C.ScriptModule) -> torch::jit::slot_list_impl<torch::jit::detail::ModulePolicy>
|
| dump(...)
| dump(self: torch._C.ScriptModule, code: bool = True, attrs: bool = True, params: bool = True) -> None
|
| dump_to_str(...)
| dump_to_str(self: torch._C.ScriptModule, code: bool = True, attrs: bool = True, params: bool = True) -> str
|
| get_debug_state(...)
| get_debug_state(self: torch._C.ScriptModule) -> torch._C.GraphExecutorState
|
| save(...)
| save(self: torch._C.ScriptModule, filename: str, _extra_files: collections.abc.Mapping[str, str] = {}) -> None
|
| save_to_buffer(...)
| save_to_buffer(self: torch._C.ScriptModule, _extra_files: collections.abc.Mapping[str, str] = {}) -> bytes
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| code
|
| code_with_constants
|
| qualified_name
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from ScriptObject:
|
| __abs__(...)
| __abs__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __add__(...)
| __add__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __and__(...)
| __and__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __concat__(...)
| __concat__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __contains__(...)
| __contains__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __delitem__(...)
| __delitem__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __floordiv__(...)
| __floordiv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ge__(...)
| __ge__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __getattr__(...)
| __getattr__(self: torch._C.ScriptObject, arg0: str) -> object
|
| __getitem__(...)
| __getitem__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __getstate__(...)
| __getstate__(self: torch._C.ScriptObject, /) -> tuple[object, str]
|
| __gt__(...)
| __gt__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __iadd__(...)
| __iadd__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __iand__(...)
| __iand__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __iconcat__(...)
| __iconcat__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ifloordiv__(...)
| __ifloordiv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ilshift__(...)
| __ilshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __imatmul__(...)
| __imatmul__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __imod__(...)
| __imod__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __imul__(...)
| __imul__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __index__(...)
| __index__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __inv__(...)
| __inv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __invert__(...)
| __invert__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ior__(...)
| __ior__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ipow__(...)
| __ipow__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __irshift__(...)
| __irshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __isub__(...)
| __isub__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __itruediv__(...)
| __itruediv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ixor__(...)
| __ixor__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __le__(...)
| __le__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __len__(...)
| __len__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __lshift__(...)
| __lshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __lt__(...)
| __lt__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __matmul__(...)
| __matmul__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __mod__(...)
| __mod__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __mul__(...)
| __mul__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ne__(...)
| __ne__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __neg__(...)
| __neg__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __not__(...)
| __not__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __or__(...)
| __or__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __pos__(...)
| __pos__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __pow__(...)
| __pow__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __repr__(...)
| __repr__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __rshift__(...)
| __rshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __setattr__(...)
| __setattr__(self: torch._C.ScriptObject, arg0: str, arg1: object) -> None
|
| __setitem__(...)
| __setitem__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __setstate__(...)
| __setstate__(self: torch._C.ScriptObject, arg0: tuple[object, str]) -> None
|
| __str__(...)
| __str__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __sub__(...)
| __sub__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __truediv__(...)
| __truediv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __xor__(...)
| __xor__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| getattr(...)
| getattr(self: torch._C.ScriptObject, arg0: str) -> object
|
| hasattr(...)
| hasattr(self: torch._C.ScriptObject, arg0: str) -> bool
|
| setattr(...)
| setattr(self: torch._C.ScriptObject, arg0: str, arg1: object) -> None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptModuleSerializer(pybind11_builtins.pybind11_object)
| Method resolution order:
| ScriptModuleSerializer
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.ScriptModuleSerializer, arg0: torch._C.PyTorchFileWriter) -> None
|
| serialize(...)
| serialize(self: torch._C.ScriptModuleSerializer, arg0: torch::jit::Module, arg1: typing.SupportsInt | typing.SupportsIndex) -> None
|
| storage_context(...)
| storage_context(self: torch._C.ScriptModuleSerializer) -> torch::jit::SerializationStorageContext
|
| write_files(...)
| write_files(self: torch._C.ScriptModuleSerializer, code_dir: str = '.data/ts_code/code/') -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptObject(pybind11_builtins.pybind11_object)
| Method resolution order:
| ScriptObject
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __abs__(...)
| __abs__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __add__(...)
| __add__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __and__(...)
| __and__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __concat__(...)
| __concat__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __contains__(...)
| __contains__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __copy__(...)
| __copy__(self: torch._C.ScriptObject) -> torch._C.ScriptObject
|
| __deepcopy__(...)
| __deepcopy__(*args, **kwargs)
| Overloaded function.
|
| 1. __deepcopy__(self: torch._C.ScriptObject, arg0: dict) -> torch._C.ScriptObject
|
| 2. __deepcopy__(self: torch._C.ScriptObject, arg0: dict) -> torch._C.ScriptObject
|
| __delitem__(...)
| __delitem__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __eq__(...)
| __eq__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __floordiv__(...)
| __floordiv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ge__(...)
| __ge__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __getattr__(...)
| __getattr__(self: torch._C.ScriptObject, arg0: str) -> object
|
| __getitem__(...)
| __getitem__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __getstate__(...)
| __getstate__(self: torch._C.ScriptObject, /) -> tuple[object, str]
|
| __gt__(...)
| __gt__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __hash__(...)
| __hash__(self: torch._C.ScriptObject) -> int
|
| __iadd__(...)
| __iadd__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __iand__(...)
| __iand__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __iconcat__(...)
| __iconcat__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ifloordiv__(...)
| __ifloordiv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ilshift__(...)
| __ilshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __imatmul__(...)
| __imatmul__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __imod__(...)
| __imod__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __imul__(...)
| __imul__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __index__(...)
| __index__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __inv__(...)
| __inv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __invert__(...)
| __invert__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ior__(...)
| __ior__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ipow__(...)
| __ipow__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __irshift__(...)
| __irshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __isub__(...)
| __isub__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __itruediv__(...)
| __itruediv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ixor__(...)
| __ixor__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __le__(...)
| __le__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __len__(...)
| __len__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __lshift__(...)
| __lshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __lt__(...)
| __lt__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __matmul__(...)
| __matmul__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __mod__(...)
| __mod__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __mul__(...)
| __mul__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __ne__(...)
| __ne__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __neg__(...)
| __neg__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __not__(...)
| __not__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __or__(...)
| __or__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __pos__(...)
| __pos__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __pow__(...)
| __pow__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __repr__(...)
| __repr__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __rshift__(...)
| __rshift__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __setattr__(...)
| __setattr__(self: torch._C.ScriptObject, arg0: str, arg1: object) -> None
|
| __setitem__(...)
| __setitem__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __setstate__(...)
| __setstate__(self: torch._C.ScriptObject, arg0: tuple[object, str]) -> None
|
| __str__(...)
| __str__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __sub__(...)
| __sub__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __truediv__(...)
| __truediv__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| __xor__(...)
| __xor__(self: torch._C.ScriptObject, *args, **kwargs) -> object
|
| getattr(...)
| getattr(self: torch._C.ScriptObject, arg0: str) -> object
|
| hasattr(...)
| hasattr(self: torch._C.ScriptObject, arg0: str) -> bool
|
| setattr(...)
| setattr(self: torch._C.ScriptObject, arg0: str, arg1: object) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ScriptObjectProperty(pybind11_builtins.pybind11_object)
| Method resolution order:
| ScriptObjectProperty
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| getter
|
| name
|
| setter
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class SerializationStorageContext(pybind11_builtins.pybind11_object)
| Method resolution order:
| SerializationStorageContext
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| get_or_add_storage(...)
| get_or_add_storage(self: torch._C.SerializationStorageContext, arg0: torch.StorageBase) -> int
|
| has_storage(...)
| has_storage(self: torch._C.SerializationStorageContext, arg0: torch.StorageBase) -> bool
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ShortStorage(torch.storage._LegacyStorage)
| ShortStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Method resolution order:
| ShortStorage
| torch.storage._LegacyStorage
| torch.storage.TypedStorage
| builtins.object
|
| Data and other attributes defined here:
|
| dtype = torch.int16
|
| ----------------------------------------------------------------------
| Methods inherited from torch.storage.TypedStorage:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.storage.TypedStorage:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.storage.TypedStorage:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from torch.storage.TypedStorage:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.storage.TypedStorage:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.storage.TypedStorage:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class ShortTensor(builtins.object)
| Methods defined here:
|
| __abs__ = abs(...)
|
| __add__(...) from torch._C.TensorBase
|
| __and__(...) from torch._C.TensorBase
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __bool__(...) from torch._C.TensorBase
|
| __complex__(...) from torch._C.TensorBase
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __delitem__(self, key, /) from torch._C.TensorBase
| Delete self[key].
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __div__(...) from torch._C.TensorBase
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __eq__(...) from torch._C.TensorBase
| Return self==value.
|
| __float__(...) from torch._C.TensorBase
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __ge__(...) from torch._C.TensorBase
| Return self>=value.
|
| __getitem__(self, key, /) from torch._C.TensorBase
| Return self[key].
|
| __gt__(...) from torch._C.TensorBase
| Return self>value.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __iadd__(...) from torch._C.TensorBase
|
| __iand__(...) from torch._C.TensorBase
|
| __idiv__(...) from torch._C.TensorBase
|
| __ifloordiv__(...) from torch._C.TensorBase
|
| __ilshift__(...) from torch._C.TensorBase
|
| __imod__(...) from torch._C.TensorBase
|
| __imul__(...) from torch._C.TensorBase
|
| __index__(...) from torch._C.TensorBase
|
| __int__(...) from torch._C.TensorBase
|
| __invert__(...) from torch._C.TensorBase
|
| __ior__(...) from torch._C.TensorBase
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __irshift__(...) from torch._C.TensorBase
|
| __isub__(...) from torch._C.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __ixor__(...) from torch._C.TensorBase
|
| __le__(...) from torch._C.TensorBase
| Return self<=value.
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __long__(...) from torch._C.TensorBase
|
| __lshift__(...) from torch._C.TensorBase
|
| __lt__(...) from torch._C.TensorBase
| Return self<value.
|
| __matmul__(...) from torch._C.TensorBase
|
| __mod__(...) from torch._C.TensorBase
|
| __mul__(...) from torch._C.TensorBase
|
| __ne__(...) from torch._C.TensorBase
| Return self!=value.
|
| __neg__ = neg(...)
|
| __nonzero__(...) from torch._C.TensorBase
|
| __or__(...) from torch._C.TensorBase
| Return self|value.
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __radd__(...) from torch._C.TensorBase
|
| __rand__(...) from torch._C.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmul__(...) from torch._C.TensorBase
|
| __ror__(...) from torch._C.TensorBase
| Return value|self.
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rshift__(...) from torch._C.TensorBase
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __rxor__(...) from torch._C.TensorBase
|
| __setitem__(self, key, value, /) from torch._C.TensorBase
| Set self[key] to value.
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| __sub__(...) from torch._C.TensorBase
|
| __truediv__(...) from torch._C.TensorBase
|
| __xor__(...) from torch._C.TensorBase
|
| abs(...) from torch._C.TensorBase
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...) from torch._C.TensorBase
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...) from torch._C.TensorBase
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...) from torch._C.TensorBase
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...) from torch._C.TensorBase
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...) from torch._C.TensorBase
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...) from torch._C.TensorBase
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...) from torch._C.TensorBase
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...) from torch._C.TensorBase
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...) from torch._C.TensorBase
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...) from torch._C.TensorBase
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...) from torch._C.TensorBase
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...) from torch._C.TensorBase
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...) from torch._C.TensorBase
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...) from torch._C.TensorBase
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...) from torch._C.TensorBase
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...) from torch._C.TensorBase
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...) from torch._C.TensorBase
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...) from torch._C.TensorBase
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...) from torch._C.TensorBase
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...) from torch._C.TensorBase
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...) from torch._C.TensorBase
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...) from torch._C.TensorBase
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...) from torch._C.TensorBase
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...) from torch._C.TensorBase
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...) from torch._C.TensorBase
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...) from torch._C.TensorBase
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...) from torch._C.TensorBase
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...) from torch._C.TensorBase
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...) from torch._C.TensorBase
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...) from torch._C.TensorBase
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...) from torch._C.TensorBase
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...) from torch._C.TensorBase
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...) from torch._C.TensorBase
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...) from torch._C.TensorBase
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...) from torch._C.TensorBase
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...) from torch._C.TensorBase
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...) from torch._C.TensorBase
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...) from torch._C.TensorBase
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...) from torch._C.TensorBase
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...) from torch._C.TensorBase
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...) from torch._C.TensorBase
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...) from torch._C.TensorBase
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...) from torch._C.TensorBase
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...) from torch._C.TensorBase
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...) from torch._C.TensorBase
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...) from torch._C.TensorBase
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...) from torch._C.TensorBase
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...) from torch._C.TensorBase
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...) from torch._C.TensorBase
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...) from torch._C.TensorBase
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...) from torch._C.TensorBase
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...) from torch._C.TensorBase
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...) from torch._C.TensorBase
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...) from torch._C.TensorBase
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...) from torch._C.TensorBase
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...) from torch._C.TensorBase
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...) from torch._C.TensorBase
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...) from torch._C.TensorBase
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...) from torch._C.TensorBase
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| baddbmm(...) from torch._C.TensorBase
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...) from torch._C.TensorBase
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...) from torch._C.TensorBase
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...) from torch._C.TensorBase
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...) from torch._C.TensorBase
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...) from torch._C.TensorBase
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...) from torch._C.TensorBase
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...) from torch._C.TensorBase
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...) from torch._C.TensorBase
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...) from torch._C.TensorBase
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...) from torch._C.TensorBase
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...) from torch._C.TensorBase
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...) from torch._C.TensorBase
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...) from torch._C.TensorBase
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...) from torch._C.TensorBase
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...) from torch._C.TensorBase
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...) from torch._C.TensorBase
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...) from torch._C.TensorBase
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...) from torch._C.TensorBase
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...) from torch._C.TensorBase
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...) from torch._C.TensorBase
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...) from torch._C.TensorBase
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...) from torch._C.TensorBase
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...) from torch._C.TensorBase
|
| cdouble(...) from torch._C.TensorBase
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...) from torch._C.TensorBase
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...) from torch._C.TensorBase
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...) from torch._C.TensorBase
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...) from torch._C.TensorBase
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...) from torch._C.TensorBase
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...) from torch._C.TensorBase
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...) from torch._C.TensorBase
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...) from torch._C.TensorBase
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...) from torch._C.TensorBase
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...) from torch._C.TensorBase
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...) from torch._C.TensorBase
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...) from torch._C.TensorBase
|
| clamp_max_(...) from torch._C.TensorBase
|
| clamp_min(...) from torch._C.TensorBase
|
| clamp_min_(...) from torch._C.TensorBase
|
| clip(...) from torch._C.TensorBase
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...) from torch._C.TensorBase
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...) from torch._C.TensorBase
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...) from torch._C.TensorBase
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...) from torch._C.TensorBase
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...) from torch._C.TensorBase
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...) from torch._C.TensorBase
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...) from torch._C.TensorBase
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...) from torch._C.TensorBase
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...) from torch._C.TensorBase
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...) from torch._C.TensorBase
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...) from torch._C.TensorBase
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...) from torch._C.TensorBase
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...) from torch._C.TensorBase
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...) from torch._C.TensorBase
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...) from torch._C.TensorBase
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...) from torch._C.TensorBase
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...) from torch._C.TensorBase
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...) from torch._C.TensorBase
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...) from torch._C.TensorBase
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...) from torch._C.TensorBase
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...) from torch._C.TensorBase
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...) from torch._C.TensorBase
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...) from torch._C.TensorBase
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...) from torch._C.TensorBase
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...) from torch._C.TensorBase
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...) from torch._C.TensorBase
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...) from torch._C.TensorBase
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...) from torch._C.TensorBase
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...) from torch._C.TensorBase
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...) from torch._C.TensorBase
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...) from torch._C.TensorBase
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...) from torch._C.TensorBase
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...) from torch._C.TensorBase
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...) from torch._C.TensorBase
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...) from torch._C.TensorBase
| det() -> Tensor
|
| See :func:`torch.det`
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| diag(...) from torch._C.TensorBase
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...) from torch._C.TensorBase
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...) from torch._C.TensorBase
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...) from torch._C.TensorBase
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...) from torch._C.TensorBase
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...) from torch._C.TensorBase
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...) from torch._C.TensorBase
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...) from torch._C.TensorBase
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...) from torch._C.TensorBase
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| dist(...) from torch._C.TensorBase
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...) from torch._C.TensorBase
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...) from torch._C.TensorBase
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...) from torch._C.TensorBase
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...) from torch._C.TensorBase
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...) from torch._C.TensorBase
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...) from torch._C.TensorBase
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...) from torch._C.TensorBase
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| element_size(...) from torch._C.TensorBase
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...) from torch._C.TensorBase
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...) from torch._C.TensorBase
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...) from torch._C.TensorBase
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...) from torch._C.TensorBase
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...) from torch._C.TensorBase
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...) from torch._C.TensorBase
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...) from torch._C.TensorBase
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...) from torch._C.TensorBase
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...) from torch._C.TensorBase
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...) from torch._C.TensorBase
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...) from torch._C.TensorBase
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...) from torch._C.TensorBase
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...) from torch._C.TensorBase
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...) from torch._C.TensorBase
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...) from torch._C.TensorBase
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...) from torch._C.TensorBase
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...) from torch._C.TensorBase
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...) from torch._C.TensorBase
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...) from torch._C.TensorBase
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...) from torch._C.TensorBase
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...) from torch._C.TensorBase
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...) from torch._C.TensorBase
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...) from torch._C.TensorBase
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...) from torch._C.TensorBase
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...) from torch._C.TensorBase
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...) from torch._C.TensorBase
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...) from torch._C.TensorBase
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...) from torch._C.TensorBase
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...) from torch._C.TensorBase
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...) from torch._C.TensorBase
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...) from torch._C.TensorBase
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...) from torch._C.TensorBase
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...) from torch._C.TensorBase
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...) from torch._C.TensorBase
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...) from torch._C.TensorBase
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...) from torch._C.TensorBase
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...) from torch._C.TensorBase
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...) from torch._C.TensorBase
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...) from torch._C.TensorBase
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...) from torch._C.TensorBase
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...) from torch._C.TensorBase
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...) from torch._C.TensorBase
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...) from torch._C.TensorBase
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...) from torch._C.TensorBase
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...) from torch._C.TensorBase
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...) from torch._C.TensorBase
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...) from torch._C.TensorBase
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...) from torch._C.TensorBase
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...) from torch._C.TensorBase
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...) from torch._C.TensorBase
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...) from torch._C.TensorBase
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...) from torch._C.TensorBase
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...) from torch._C.TensorBase
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...) from torch._C.TensorBase
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...) from torch._C.TensorBase
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...) from torch._C.TensorBase
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...) from torch._C.TensorBase
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...) from torch._C.TensorBase
|
| heaviside(...) from torch._C.TensorBase
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...) from torch._C.TensorBase
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...) from torch._C.TensorBase
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...) from torch._C.TensorBase
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...) from torch._C.TensorBase
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...) from torch._C.TensorBase
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...) from torch._C.TensorBase
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...) from torch._C.TensorBase
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...) from torch._C.TensorBase
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...) from torch._C.TensorBase
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...) from torch._C.TensorBase
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...) from torch._C.TensorBase
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...) from torch._C.TensorBase
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| index_add(...) from torch._C.TensorBase
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...) from torch._C.TensorBase
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...) from torch._C.TensorBase
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...) from torch._C.TensorBase
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...) from torch._C.TensorBase
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...) from torch._C.TensorBase
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...) from torch._C.TensorBase
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...) from torch._C.TensorBase
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...) from torch._C.TensorBase
|
| index_reduce_(...) from torch._C.TensorBase
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...) from torch._C.TensorBase
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...) from torch._C.TensorBase
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...) from torch._C.TensorBase
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...) from torch._C.TensorBase
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...) from torch._C.TensorBase
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...) from torch._C.TensorBase
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...) from torch._C.TensorBase
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...) from torch._C.TensorBase
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...) from torch._C.TensorBase
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...) from torch._C.TensorBase
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...) from torch._C.TensorBase
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...) from torch._C.TensorBase
|
| is_floating_point(...) from torch._C.TensorBase
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...) from torch._C.TensorBase
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...) from torch._C.TensorBase
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...) from torch._C.TensorBase
|
| is_pinned(...) from torch._C.TensorBase
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...) from torch._C.TensorBase
|
| is_set_to(...) from torch._C.TensorBase
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| is_signed(...) from torch._C.TensorBase
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...) from torch._C.TensorBase
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...) from torch._C.TensorBase
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...) from torch._C.TensorBase
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...) from torch._C.TensorBase
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...) from torch._C.TensorBase
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...) from torch._C.TensorBase
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...) from torch._C.TensorBase
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| item(...) from torch._C.TensorBase
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...) from torch._C.TensorBase
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...) from torch._C.TensorBase
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...) from torch._C.TensorBase
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...) from torch._C.TensorBase
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...) from torch._C.TensorBase
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...) from torch._C.TensorBase
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...) from torch._C.TensorBase
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...) from torch._C.TensorBase
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...) from torch._C.TensorBase
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...) from torch._C.TensorBase
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...) from torch._C.TensorBase
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...) from torch._C.TensorBase
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...) from torch._C.TensorBase
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...) from torch._C.TensorBase
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...) from torch._C.TensorBase
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...) from torch._C.TensorBase
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...) from torch._C.TensorBase
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...) from torch._C.TensorBase
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...) from torch._C.TensorBase
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...) from torch._C.TensorBase
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...) from torch._C.TensorBase
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...) from torch._C.TensorBase
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...) from torch._C.TensorBase
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...) from torch._C.TensorBase
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...) from torch._C.TensorBase
|
| logaddexp(...) from torch._C.TensorBase
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...) from torch._C.TensorBase
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...) from torch._C.TensorBase
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...) from torch._C.TensorBase
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...) from torch._C.TensorBase
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...) from torch._C.TensorBase
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...) from torch._C.TensorBase
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...) from torch._C.TensorBase
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...) from torch._C.TensorBase
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...) from torch._C.TensorBase
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...) from torch._C.TensorBase
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...) from torch._C.TensorBase
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...) from torch._C.TensorBase
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...) from torch._C.TensorBase
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...) from torch._C.TensorBase
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...) from torch._C.TensorBase
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lt(...) from torch._C.TensorBase
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...) from torch._C.TensorBase
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| lu_solve(...) from torch._C.TensorBase
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...) from torch._C.TensorBase
|
| map_(...) from torch._C.TensorBase
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...) from torch._C.TensorBase
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...) from torch._C.TensorBase
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...) from torch._C.TensorBase
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...) from torch._C.TensorBase
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...) from torch._C.TensorBase
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...) from torch._C.TensorBase
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...) from torch._C.TensorBase
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...) from torch._C.TensorBase
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...) from torch._C.TensorBase
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...) from torch._C.TensorBase
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...) from torch._C.TensorBase
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...) from torch._C.TensorBase
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...) from torch._C.TensorBase
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...) from torch._C.TensorBase
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...) from torch._C.TensorBase
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...) from torch._C.TensorBase
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| moveaxis(...) from torch._C.TensorBase
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...) from torch._C.TensorBase
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...) from torch._C.TensorBase
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...) from torch._C.TensorBase
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...) from torch._C.TensorBase
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...) from torch._C.TensorBase
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...) from torch._C.TensorBase
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...) from torch._C.TensorBase
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...) from torch._C.TensorBase
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...) from torch._C.TensorBase
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...) from torch._C.TensorBase
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...) from torch._C.TensorBase
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...) from torch._C.TensorBase
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...) from torch._C.TensorBase
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...) from torch._C.TensorBase
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...) from torch._C.TensorBase
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...) from torch._C.TensorBase
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...) from torch._C.TensorBase
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...) from torch._C.TensorBase
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...) from torch._C.TensorBase
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...) from torch._C.TensorBase
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...) from torch._C.TensorBase
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...) from torch._C.TensorBase
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...) from torch._C.TensorBase
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...) from torch._C.TensorBase
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...) from torch._C.TensorBase
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...) from torch._C.TensorBase
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...) from torch._C.TensorBase
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...) from torch._C.TensorBase
|
| new_empty(...) from torch._C.TensorBase
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...) from torch._C.TensorBase
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...) from torch._C.TensorBase
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...) from torch._C.TensorBase
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...) from torch._C.TensorBase
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...) from torch._C.TensorBase
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...) from torch._C.TensorBase
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...) from torch._C.TensorBase
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...) from torch._C.TensorBase
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...) from torch._C.TensorBase
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| normal_(...) from torch._C.TensorBase
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...) from torch._C.TensorBase
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...) from torch._C.TensorBase
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...) from torch._C.TensorBase
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...) from torch._C.TensorBase
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...) from torch._C.TensorBase
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...) from torch._C.TensorBase
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...) from torch._C.TensorBase
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...) from torch._C.TensorBase
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...) from torch._C.TensorBase
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...) from torch._C.TensorBase
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...) from torch._C.TensorBase
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...) from torch._C.TensorBase
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...) from torch._C.TensorBase
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...) from torch._C.TensorBase
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...) from torch._C.TensorBase
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...) from torch._C.TensorBase
|
| prod(...) from torch._C.TensorBase
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...) from torch._C.TensorBase
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...) from torch._C.TensorBase
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...) from torch._C.TensorBase
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...) from torch._C.TensorBase
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...) from torch._C.TensorBase
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...) from torch._C.TensorBase
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...) from torch._C.TensorBase
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...) from torch._C.TensorBase
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...) from torch._C.TensorBase
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...) from torch._C.TensorBase
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...) from torch._C.TensorBase
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...) from torch._C.TensorBase
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...) from torch._C.TensorBase
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...) from torch._C.TensorBase
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...) from torch._C.TensorBase
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...) from torch._C.TensorBase
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...) from torch._C.TensorBase
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| relu(...) from torch._C.TensorBase
|
| relu_(...) from torch._C.TensorBase
|
| remainder(...) from torch._C.TensorBase
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...) from torch._C.TensorBase
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...) from torch._C.TensorBase
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...) from torch._C.TensorBase
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...) from torch._C.TensorBase
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...) from torch._C.TensorBase
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...) from torch._C.TensorBase
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...) from torch._C.TensorBase
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...) from torch._C.TensorBase
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_(...) from torch._C.TensorBase
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| resize_as_(...) from torch._C.TensorBase
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...) from torch._C.TensorBase
|
| resolve_conj(...) from torch._C.TensorBase
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...) from torch._C.TensorBase
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...) from torch._C.TensorBase
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...) from torch._C.TensorBase
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...) from torch._C.TensorBase
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...) from torch._C.TensorBase
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...) from torch._C.TensorBase
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...) from torch._C.TensorBase
|
| rsqrt(...) from torch._C.TensorBase
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...) from torch._C.TensorBase
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...) from torch._C.TensorBase
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...) from torch._C.TensorBase
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...) from torch._C.TensorBase
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...) from torch._C.TensorBase
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...) from torch._C.TensorBase
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...) from torch._C.TensorBase
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...) from torch._C.TensorBase
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...) from torch._C.TensorBase
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...) from torch._C.TensorBase
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...) from torch._C.TensorBase
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...) from torch._C.TensorBase
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| short(...) from torch._C.TensorBase
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...) from torch._C.TensorBase
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...) from torch._C.TensorBase
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...) from torch._C.TensorBase
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...) from torch._C.TensorBase
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...) from torch._C.TensorBase
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...) from torch._C.TensorBase
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...) from torch._C.TensorBase
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...) from torch._C.TensorBase
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...) from torch._C.TensorBase
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...) from torch._C.TensorBase
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...) from torch._C.TensorBase
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...) from torch._C.TensorBase
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...) from torch._C.TensorBase
|
| slice_scatter(...) from torch._C.TensorBase
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...) from torch._C.TensorBase
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...) from torch._C.TensorBase
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...) from torch._C.TensorBase
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| solve(self, other) from torch._tensor.Tensor
|
| sort(...) from torch._C.TensorBase
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...) from torch._C.TensorBase
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...) from torch._C.TensorBase
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...) from torch._C.TensorBase
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...) from torch._C.TensorBase
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| split_with_sizes(...) from torch._C.TensorBase
|
| sqrt(...) from torch._C.TensorBase
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...) from torch._C.TensorBase
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...) from torch._C.TensorBase
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...) from torch._C.TensorBase
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...) from torch._C.TensorBase
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...) from torch._C.TensorBase
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...) from torch._C.TensorBase
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...) from torch._C.TensorBase
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_offset(...) from torch._C.TensorBase
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| stride(...) from torch._C.TensorBase
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...) from torch._C.TensorBase
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...) from torch._C.TensorBase
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...) from torch._C.TensorBase
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...) from torch._C.TensorBase
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...) from torch._C.TensorBase
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...) from torch._C.TensorBase
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...) from torch._C.TensorBase
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...) from torch._C.TensorBase
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...) from torch._C.TensorBase
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...) from torch._C.TensorBase
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...) from torch._C.TensorBase
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| t(...) from torch._C.TensorBase
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...) from torch._C.TensorBase
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...) from torch._C.TensorBase
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...) from torch._C.TensorBase
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...) from torch._C.TensorBase
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...) from torch._C.TensorBase
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...) from torch._C.TensorBase
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...) from torch._C.TensorBase
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...) from torch._C.TensorBase
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...) from torch._C.TensorBase
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...) from torch._C.TensorBase
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...) from torch._C.TensorBase
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...) from torch._C.TensorBase
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...) from torch._C.TensorBase
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...) from torch._C.TensorBase
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...) from torch._C.TensorBase
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...) from torch._C.TensorBase
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| to_sparse_csc(...) from torch._C.TensorBase
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...) from torch._C.TensorBase
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...) from torch._C.TensorBase
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...) from torch._C.TensorBase
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...) from torch._C.TensorBase
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...) from torch._C.TensorBase
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...) from torch._C.TensorBase
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...) from torch._C.TensorBase
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...) from torch._C.TensorBase
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...) from torch._C.TensorBase
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...) from torch._C.TensorBase
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...) from torch._C.TensorBase
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...) from torch._C.TensorBase
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...) from torch._C.TensorBase
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...) from torch._C.TensorBase
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...) from torch._C.TensorBase
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...) from torch._C.TensorBase
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...) from torch._C.TensorBase
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...) from torch._C.TensorBase
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unfold(...) from torch._C.TensorBase
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...) from torch._C.TensorBase
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| unsafe_chunk(...) from torch._C.TensorBase
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...) from torch._C.TensorBase
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...) from torch._C.TensorBase
|
| unsqueeze(...) from torch._C.TensorBase
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...) from torch._C.TensorBase
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...) from torch._C.TensorBase
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...) from torch._C.TensorBase
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...) from torch._C.TensorBase
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...) from torch._C.TensorBase
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...) from torch._C.TensorBase
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...) from torch._C.TensorBase
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...) from torch._C.TensorBase
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...) from torch._C.TensorBase
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...) from torch._C.TensorBase
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...) from torch._C.TensorBase
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...) from torch._C.TensorBase
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...) from torch._C.TensorBase
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| dtype = torch.int16
|
| is_cuda = False
|
| is_sparse = False
|
| is_sparse_csr = False
|
| is_xpu = False
|
| layout = torch.strided
class Size(builtins.tuple)
| Size(iterable=(), /)
|
| Method resolution order:
| Size
| builtins.tuple
| builtins.object
|
| Methods defined here:
|
| __add__(self, value, /)
| Return self+value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __mul__(self, value, /)
| Return self*value.
|
| __radd__(self, value, /)
| Return value+self.
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __rmul__(self, value, /)
| Return value*self.
|
| numel(...)
| numel() -> int
|
| Returns the number of elements a :class:`torch.Tensor` with the given size would contain.
|
| More formally, for a tensor ``x = tensor.ones(10, 10)`` with size ``s = torch.Size([10, 10])``,
| ``x.numel() == x.size().numel() == s.numel() == 100`` holds true.
|
| Example::
|
| >>> x=torch.ones(10, 10)
| >>> s=x.size()
| >>> s
| torch.Size([10, 10])
| >>> s.numel()
| 100
| >>> x.numel() == s.numel()
| True
|
|
| .. warning::
|
| This function does not return the number of dimensions described by :class:`torch.Size`, but instead the number
| of elements a :class:`torch.Tensor` with that size would contain.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.tuple:
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.tuple:
|
| __class_getitem__(...)
| See PEP 585
class StaticModule(pybind11_builtins.pybind11_object)
| Method resolution order:
| StaticModule
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __call__(...)
| __call__(self: torch._C.StaticModule, *args, **kwargs) -> object
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| benchmark(...)
| benchmark(self: torch._C.StaticModule, arg0: collections.abc.Sequence[torch.Tensor], arg1: collections.abc.Mapping[str, torch.Tensor], arg2: typing.SupportsInt | typing.SupportsIndex, arg3: typing.SupportsInt | typing.SupportsIndex) -> None
|
| benchmark_individual_ops(...)
| benchmark_individual_ops(self: torch._C.StaticModule, arg0: collections.abc.Sequence[torch.Tensor], arg1: collections.abc.Mapping[str, torch.Tensor], arg2: typing.SupportsInt | typing.SupportsIndex, arg3: typing.SupportsInt | typing.SupportsIndex) -> torch._C.StaticModule.IndividualMetrics
|
| runAsync(...)
| runAsync(self: torch._C.StaticModule, arg0: tuple, arg1: dict) -> object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| IndividualMetrics = <class 'torch._C.StaticModule.IndividualMetrics'>
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Stream(builtins.object)
| Stream(device, *, priority) -> Stream
|
| An in-order queue of executing the respective tasks asynchronously in first in first out (FIFO) order.
| It can control or synchronize the execution of other Stream or block the current host thread to ensure
| the correct task sequencing. It supports with statement as a context manager to ensure the operators
| within the with block are running on the corresponding stream.
|
| See in-depth description of the CUDA behavior at :ref:`cuda-semantics` for details
| on the exact semantic that applies to all devices.
|
| Arguments:
| device (:class:`torch.device`, optional): the desired device for the Stream.
| If not given, the current :ref:`accelerator<accelerators>` type will be used.
| priority (int, optional): priority of the stream, should be 0 or negative, where negative
| numbers indicate higher priority. By default, streams have priority 0.
|
| Returns:
| Stream: An torch.Stream object.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> with torch.Stream(device='cuda') as s_cuda:
| >>> a = torch.randn(10, 5, device='cuda')
| >>> b = torch.randn(5, 10, device='cuda')
| >>> c = torch.mm(a, b)
|
| Methods defined here:
|
| __enter__(...)
|
| __eq__(self, value, /)
| Return self==value.
|
| __exit__(...)
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| is_capturing(...)
| Stream.is_capturing() -> bool
|
| Return true if this stream is currently recording work for graph capture.
|
| Returns:
| bool: A boolean indicating if the stream is capturing.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> s_cuda = torch.Stream(device='cuda')
| >>> s_cuda.is_capturing()
|
| query(...)
| Stream.query() -> bool
|
| Check if all the work submitted has been completed.
|
| Returns:
| bool: A boolean indicating if all kernels in this stream are completed.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> s_cuda = torch.Stream(device='cuda')
| >>> s_cuda.query()
| True
|
| record_event(...)
| Stream.record_event(event) -> Event
|
| Record an event. En-queuing it into the Stream to allow further synchronization from the current point in the FIFO queue.
|
| Arguments:
| event (:class:`torch.Event`, optional): event to record. If not given, a new one will be allocated.
|
| Returns:
| Event: Recorded event.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> s_cuda = torch.Stream(device='cuda')
| >>> e_cuda = s_cuda.record_event()
|
| synchronize(...)
| Stream.synchronize() -> None
|
| Wait for all the kernels in this stream to complete.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> s_cuda = torch.Stream(device='cuda')
| >>> s_cuda.synchronize()
|
| wait_event(...)
| Stream.wait_event(event) -> None
|
| Make all future work submitted to the stream wait for an event.
|
| Arguments:
| event (:class:`torch.Event`): an event to wait for.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> s1_cuda = torch.Stream(device='cuda')
| >>> s2_cuda = torch.Stream(device='cuda')
| >>> e_cuda = s1_cuda.record_event()
| >>> s2_cuda.wait_event(e_cuda)
|
| wait_stream(...)
| Stream.wait_stream(stream) -> None
|
| Synchronize with another stream. All future work submitted to this stream will wait until all kernels
| already submitted to the given stream are completed.
|
| Arguments:
| stream (:class:`torch.Stream`): a stream to synchronize.
|
| Example::
|
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
| >>> s1_cuda = torch.Stream(device='cuda')
| >>> s2_cuda = torch.Stream(device='cuda')
| >>> s2_cuda.wait_stream(s1_cuda)
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| device
|
| device_index
|
| device_type
|
| native_handle
|
| stream_id
class StreamObjType(Type)
| Method resolution order:
| StreamObjType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.StreamObjType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class StringType(Type)
| Method resolution order:
| StringType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.StringType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class SymBool(builtins.object)
| SymBool(node)
|
| Like a bool (including magic methods), but redirects all operations on the
| wrapped node. This is used in particular to symbolically record operations
| in the symbolic shape workflow.
|
| Unlike regular bools, regular boolean operators will force extra guards instead
| of symbolically evaluate. Use the bitwise operators instead to handle this.
|
| Methods defined here:
|
| __add__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __and__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __bool__(self)
|
| __eq__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, node)
| Initialize self. See help(type(self)) for accurate signature.
|
| __int__(self)
|
| __mul__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __or__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __radd__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rand__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __repr__(self)
| Return repr(self).
|
| __rmul__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __ror__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rsub__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __sub__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __sym_float__(self)
| Provides a SymFloat representation (0.0 or 1.0) for this SymBool.
| Called by torch.sym_float() when casting SymBool to float.
|
| __sym_ite__ = sym_ite_magic_impl(pred: 'SymBool', then_val: 'object', else_val: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __sym_not__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class SymBoolType(Type)
| Method resolution order:
| SymBoolType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.SymBoolType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class SymFloat(builtins.object)
| SymFloat(node)
|
| Like a float (including magic methods), but redirects all operations on the
| wrapped node. This is used in particular to symbolically record operations
| in the symbolic shape workflow.
|
| Methods defined here:
|
| __abs__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __add__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __bool__(self)
|
| __ceil__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __eq__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __float__(self)
|
| __float_pow__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __float_truediv__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __floor__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __floordiv__(self, other)
|
| __ge__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __gt__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __hash__(self)
| Return hash(self).
|
| __init__(self, node)
| Initialize self. See help(type(self)) for accurate signature.
|
| __int__(self)
|
| __int_floordiv__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __int_truediv__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __le__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __lshift__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __lt__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __mod__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __mul__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __ne__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __neg__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __pos__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __pow__(self, other)
| # Symbolic power does NOT work with negative base, this is to avoid
| # potential complex outputs
|
| __pow_by_natural__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __radd__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __repr__(self)
| Return repr(self).
|
| __rfloat_pow__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rfloat_truediv__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rfloordiv__(self, other)
|
| __rint_floordiv__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rint_truediv__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rlshift__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rmod__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rmul__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __round__ = round_magic_impl(self: 'SymFloat', ndigits: 'int | None' = None) -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rpow__(self, other)
|
| __rpow_by_natural__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rrshift__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rshift__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rsub__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rtruediv__(self, other)
|
| __sub__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __sym_acos__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_asin__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_atan__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_cos__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_cosh__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_float__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_int__(self)
|
| __sym_log2__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_max__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __sym_min__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __sym_sin__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_sinh__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_sqrt__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_tan__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_tanh__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __truediv__(self, other)
|
| __trunc__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| as_integer_ratio(self) -> tuple[int, int]
| Represent this float as an exact integer ratio
|
| conjugate(self) -> 'SymFloat'
| Returns the complex conjugate of the float.
|
| hex(self) -> str
| Returns the hexadecimal representation of the float.
|
| is_integer(self)
| Return True if the float is an integer.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class SymInt(builtins.object)
| SymInt(node)
|
| Like an int (including magic methods), but redirects all operations on the
| wrapped node. This is used in particular to symbolically record operations
| in the symbolic shape workflow.
|
| Methods defined here:
|
| __abs__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __add__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __and__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __bool__(self)
|
| __ceil__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __eq__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __float_pow__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __float_truediv__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __floor__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __floordiv__(self, other)
|
| __ge__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __gt__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __hash__(self) -> int
| Return hash(self).
|
| __index__(self)
|
| __init__(self, node)
| Initialize self. See help(type(self)) for accurate signature.
|
| __int__(self)
|
| __int_floordiv__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __int_truediv__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __le__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __lshift__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __lt__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __mod__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __mul__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __ne__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __neg__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __or__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __pos__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __pow__(self, other)
| # nb: complex is impossible to handle correctly lol, with
| # negative base and integral float need to diverge semantics and
| # just always return complex. Neener neener pretend this problem
| # doesn't exist
|
| __pow_by_natural__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __radd__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rand__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __repr__(self)
| Return repr(self).
|
| __rfloat_pow__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rfloat_truediv__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rfloordiv__(self, other)
|
| __rint_floordiv__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rint_truediv__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rlshift__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rmod__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rmul__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __ror__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __round__(self, ndigits=None)
|
| __rpow__(self, other)
|
| __rpow_by_natural__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rrshift__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rshift__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rsub__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __rtruediv__(self, other)
|
| __rxor__ = rbinary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __sub__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __sym_acos__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_asin__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_atan__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_cos__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_cosh__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_float__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_max__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __sym_min__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| __sym_sin__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_sinh__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_sqrt__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_tan__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __sym_tanh__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __truediv__(self, other)
|
| __trunc__ = unary_magic_impl(self: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
| # Before and after performing the operation, check if any operands are constant.
| # If so, extract out the constant values first. If `self` itself is a
| # constant, then "redispatch" by calling back into the operator. Sometimes
| # this means that operations involving SymBool return plain bools.
| # Alternatively, we could also rewrap into constant Symbool (i.e. by
| # implementing wrap_bool in ConstantSymNodeImpl), but we're not doing that
| # today for no particular reason.
|
| __xor__ = binary_magic_impl(self: 'object', other: 'object') -> 'Any' from torch.fx.experimental.sym_node._make_user_magic.<locals>
|
| as_integer_ratio(self) -> tuple['SymInt', int]
| Represent this int as an exact integer ratio
|
| bit_length(self) -> int
|
| conjugate(self) -> 'SymInt'
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class SymIntType(Type)
| Method resolution order:
| SymIntType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.SymIntType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Tag(pybind11_builtins.pybind11_object)
| Method resolution order:
| Tag
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __eq__(...)
| __eq__(self: object, other: object, /) -> bool
|
| __getstate__(...)
| __getstate__(self: object, /) -> int
|
| __hash__(...)
| __hash__(self: object, /) -> int
|
| __index__(...)
| __index__(self: torch._C.Tag, /) -> int
|
| __init__(...)
| __init__(self: torch._C.Tag, value: typing.SupportsInt | typing.SupportsIndex) -> None
|
| __int__(...)
| __int__(self: torch._C.Tag, /) -> int
|
| __ne__(...)
| __ne__(self: object, other: object, /) -> bool
|
| __repr__(...)
| __repr__(self: object, /) -> str
|
| __setstate__(...)
| __setstate__(self: torch._C.Tag, state: typing.SupportsInt | typing.SupportsIndex, /) -> None
|
| __str__(...)
| __str__(self: object, /) -> str
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __members__
|
| name
| name(self: object, /) -> str
|
| value
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| core = <Tag.core: 0>
|
| cudagraph_unsafe = <Tag.cudagraph_unsafe: 1>
|
| data_dependent_output = <Tag.data_dependent_output: 2>
|
| dynamic_output_shape = <Tag.dynamic_output_shape: 3>
|
| flexible_layout = <Tag.flexible_layout: 4>
|
| generated = <Tag.generated: 5>
|
| inplace = <Tag.inplace: 6>
|
| inplace_view = <Tag.inplace_view: 7>
|
| maybe_aliasing_or_mutating = <Tag.maybe_aliasing_or_mutating: 8>
|
| needs_contiguous_strides = <Tag.needs_contiguous_strides: 9>
|
| needs_exact_strides = <Tag.needs_exact_strides: 10>
|
| needs_fixed_stride_order = <Tag.needs_fixed_stride_order: 11>
|
| nondeterministic_bitwise = <Tag.nondeterministic_bitwise: 12>
|
| nondeterministic_seeded = <Tag.nondeterministic_seeded: 13>
|
| out = <Tag.out: 14>
|
| out_variant = <Tag.out_variant: 15>
|
| pointwise = <Tag.pointwise: 16>
|
| pt2_compliant_tag = <Tag.pt2_compliant_tag: 17>
|
| reduction = <Tag.reduction: 18>
|
| view_copy = <Tag.view_copy: 19>
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Tensor(torch._C.TensorBase)
| Method resolution order:
| Tensor
| torch._C.TensorBase
| builtins.object
|
| Methods defined here:
|
| __abs__ = abs(...)
|
| __array__(self, dtype=None) from torch._tensor.Tensor
|
| __array_wrap__(self, array) from torch._tensor.Tensor
| # Wrap Numpy array again in a suitable tensor when done, to support e.g.
| # `numpy.sin(tensor) -> tensor` or `numpy.greater(tensor, 0) -> ByteTensor`
|
| __contains__(self, element: Any, /) -> bool from torch._tensor.Tensor
| Check if `element` is present in tensor
|
| Args:
| element (Tensor or scalar): element to be checked
| for presence in current tensor"
|
| __deepcopy__(self, memo) from torch._tensor.Tensor
|
| __dir__(self) from torch._tensor.Tensor
| Default dir() implementation.
|
| __dlpack__(self, *, stream: typing.Any | None = -1, max_version: tuple[int, int] | None = None, dl_device: tuple[enum.IntEnum, int] | None = None, copy: bool | None = None) from torch._tensor.Tensor
| Creates a DLpack `capsule https://data-apis.org/array-api/latest/design_topics/data_interchange.html#data-interchange`_
| of the current tensor to be exported to other libraries.
|
| This function will be called from the `from_dlpack` method
| of the library that will consume the capsule. `from_dlpack` passes the current
| stream to this method as part of the specification.
|
| Args:
| stream (integer or None): An optional Python integer representing a
| pointer to a CUDA stream. The current stream is synchronized with
| this stream before the capsule is created, and since the capsule
| shares its storage with the tensor this make it safe to access from
| both streams. If -1 is passed then no synchronization is performed.
| If 1 (on CUDA) or 0 (on ROCM) then the default stream is used for
| synchronization. This API intentionally slightly deviates from the DLPack
| guidance: the default stream is -1 (stream-preserving; no cross-stream sync),
| because many from_dlpack implementations intend stream preservation.
| For non-CUDA devices, -1 is treated the same as None.
|
| max_version (tuple[int, int] or None): An optional Python tuple with
| 2 integers, representing the maximum version the caller supports. If
| None (default), PyTorch will fallback to DLPack 0.8.
|
| dl_device (tuple[DLDeviceType, int] or None): An optional tuple specifying
| in which device the exported DLPack capsule should be on. If None (default),
| the exported DLPack capsule will be on the same device as ``self``.
|
| copy (bool or None): An optional boolean indicating whether or not to copy
| ``self``. If None, PyTorch will copy only if necessary.
|
| __dlpack_device__(self) -> tuple[enum.IntEnum, int] from torch._tensor.Tensor
|
| __floordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __format__(self, format_spec) from torch._tensor.Tensor
| Default object formatter.
|
| Return str(self) if format_spec is empty. Raise TypeError otherwise.
|
| __hash__(self) from torch._tensor.Tensor
| Return hash(self).
|
| __ipow__ = pow_(...) from torch._tensor.TensorBase
|
| __iter__(self) from torch._tensor.Tensor
|
| __itruediv__ = __idiv__(...)
|
| __len__(self) from torch._tensor.Tensor
| Return len(self).
|
| __neg__ = neg(...)
|
| __pos__ = positive(...)
|
| __pow__ = pow(...) from torch._tensor.TensorBase
|
| __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __reduce_ex__(self, proto) from torch._tensor.Tensor
| Helper for pickle.
|
| __repr__(self, *, tensor_contents=None) from torch._tensor.Tensor
| Return repr(self).
|
| __reversed__(self) from torch._tensor.Tensor
| Reverses the tensor along dimension 0.
|
| __rfloordiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool]) -> 'Tensor' from torch._tensor.Tensor
|
| __rlshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rmatmul__(self, other: 'Tensor') -> 'Tensor' from torch._tensor.Tensor
|
| __rmod__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rpow__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rrshift__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rsub__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor' from torch._tensor.Tensor
|
| __rtruediv__ = __rdiv__(self, other: Union[ForwardRef('Tensor'), int, float, bool, complex]) -> 'Tensor'
|
| __setstate__(self, state) from torch._tensor.Tensor
|
| backward(self, gradient=None, retain_graph=None, create_graph=False, inputs=None) from torch._tensor.Tensor
| Computes the gradient of current tensor wrt graph leaves.
|
| The graph is differentiated using the chain rule. If the tensor is
| non-scalar (i.e. its data has more than one element) and requires
| gradient, the function additionally requires specifying a ``gradient``.
| It should be a tensor of matching type and shape, that represents
| the gradient of the differentiated function w.r.t. ``self``.
|
| This function accumulates gradients in the leaves - you might need to zero
| ``.grad`` attributes or set them to ``None`` before calling it.
| See :ref:`Default gradient layouts<default-grad-layouts>`
| for details on the memory layout of accumulated gradients.
|
| .. note::
|
| If you run any forward ops, create ``gradient``, and/or call ``backward``
| in a user-specified CUDA stream context, see
| :ref:`Stream semantics of backward passes<bwd-cuda-stream-semantics>`.
|
| .. note::
|
| When ``inputs`` are provided and a given input is not a leaf,
| the current implementation will call its grad_fn (though it is not strictly needed to get this gradients).
| It is an implementation detail on which the user should not rely.
| See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| Args:
| gradient (Tensor, optional): The gradient of the function
| being differentiated w.r.t. ``self``.
| This argument can be omitted if ``self`` is a scalar. Defaults to ``None``.
| retain_graph (bool, optional): If ``False``, the graph used to compute the grads will be freed;
| If ``True``, it will be retained. The default is ``None``, in which case the value is inferred from ``create_graph``
| (i.e., the graph is retained only when higher-order derivative tracking is requested). Note that in nearly all cases
| setting this option to True is not needed and often can be worked around in a much more efficient way.
| create_graph (bool, optional): If ``True``, graph of the derivative will
| be constructed, allowing to compute higher order derivative
| products. Defaults to ``False``.
| inputs (Sequence[Tensor] or dict[str, Tensor], optional): Inputs w.r.t. which
| the gradient will be accumulated into ``.grad``. All other tensors will be
| ignored. If not provided, the gradient is accumulated into all the leaf
| Tensors that were used to compute the :attr:`tensors`. A dict of tensors
| (e.g. ``dict(model.named_parameters())``) is also accepted.
| Defaults to ``None``.
|
| detach(...) from torch._C.TensorBase
| Returns a new Tensor, detached from the current graph.
|
| The result will never require gradient.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| .. note::
|
| Returned Tensor shares the same storage with the original one.
| In-place modifications on either of them will be seen, and may trigger
| errors in correctness checks.
|
| detach_(...) from torch._C.TensorBase
| Detaches the Tensor from the graph that created it, making it a leaf.
| Views cannot be detached in-place.
|
| This method also affects forward mode AD gradients and the result will never
| have forward mode AD gradients.
|
| dim_order(self, *, ambiguity_check: bool | list[torch.memory_format] = False) from torch._tensor.Tensor
| dim_order(ambiguity_check=False) -> tuple
|
| Returns the uniquely determined tuple of int describing the dim order or
| physical layout of :attr:`self`.
|
| The dim order represents how dimensions are laid out in memory of dense tensors,
| starting from the outermost to the innermost dimension.
|
| Note that the dim order may not always be uniquely determined.
| If `ambiguity_check` is True, this function raises a RuntimeError when the dim order cannot be uniquely determined;
| If `ambiguity_check` is a list of memory formats, this function raises a RuntimeError when tensor can not be interpreted
| into exactly one of the given memory formats, or it cannot be uniquely determined.
| If `ambiguity_check` is False, it will return one of legal dim order(s) without checking its uniqueness.
| Otherwise, it will raise TypeError.
|
| Args:
| ambiguity_check (bool or List[torch.memory_format]): The check method for ambiguity of dim order.
|
| Examples::
|
| >>> torch.empty((2, 3, 5, 7)).dim_order()
| (0, 1, 2, 3)
| >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order()
| (0, 2, 1, 3)
| >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order()
| (0, 2, 3, 1)
| >>> torch.empty((1, 2, 3, 4)).dim_order()
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True)
| ... except RuntimeError as e:
| ... print(e)
| The tensor does not have unique dim order, or cannot map to exact one of the given memory formats.
| >>> torch.empty((1, 2, 3, 4)).dim_order(
| ... ambiguity_check=[torch.contiguous_format, torch.channels_last]
| ... ) # It can be mapped to contiguous format
| (0, 1, 2, 3)
| >>> try:
| ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") # type: ignore[arg-type]
| ... except TypeError as e:
| ... print(e)
| The ambiguity_check argument must be a bool or a list of memory formats.
|
| .. warning::
| The dim_order tensor API is experimental and subject to change.
|
| eig(self, eigenvectors=False) from torch._tensor.Tensor
|
| index(self, positions, dims) from torch._tensor.Tensor
| Index a regular tensor by binding specified positions to dims.
|
| This converts a regular tensor to a first-class tensor by binding
| the specified positional dimensions to Dim objects.
|
| Args:
| positions: Tuple of dimension positions to bind
| dims: Dim objects or tuple of Dim objects to bind to
|
| Returns:
| First-class tensor with specified dimensions bound
|
| is_shared(self) from torch._tensor.Tensor
| Checks if tensor is in shared memory.
|
| This is always ``True`` for CUDA tensors.
|
| istft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, normalized: bool = False, onesided: bool | None = None, length: int | None = None, return_complex: bool = False) from torch._tensor.Tensor
| See :func:`torch.istft`
|
| lstsq(self, other) from torch._tensor.Tensor
|
| lu(self, pivot=True, get_infos=False) from torch._tensor.Tensor
| See :func:`torch.lu`
|
| module_load(self, other, assign=False) from torch._tensor.Tensor
| Defines how to transform ``other`` when loading it into ``self`` in :meth:`~nn.Module.load_state_dict`.
|
| Used when :func:`~torch.__future__.get_swap_module_params_on_conversion` is ``True``.
|
| It is expected that ``self`` is a parameter or buffer in an ``nn.Module`` and ``other`` is the
| value in the state dictionary with the corresponding key, this method defines
| how ``other`` is remapped before being swapped with ``self`` via
| :func:`~torch.utils.swap_tensors` in :meth:`~nn.Module.load_state_dict`.
|
| .. note::
| This method should always return a new object that is not ``self`` or ``other``.
| For example, the default implementation returns ``self.copy_(other).detach()``
| if ``assign`` is ``False`` or ``other.detach()`` if ``assign`` is ``True``.
|
| Args:
| other (Tensor): value in state dict with key corresponding to ``self``
| assign (bool): the assign argument passed to :meth:`nn.Module.load_state_dict`
|
| norm(self, p: float | str | None = 'fro', dim=None, keepdim=False, dtype=None) from torch._tensor.Tensor
| See :func:`torch.linalg.norm`
|
| register_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook.
|
| The hook will be called every time a gradient with respect to the
| Tensor is computed. The hook should have the following signature::
|
| hook(grad) -> Tensor or None
|
|
| The hook should not modify its argument, but it can optionally return
| a new gradient which will be used in place of :attr:`grad`.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> h = v.register_hook(lambda grad: grad * 2) # double the gradient
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v.grad
|
| 2
| 4
| 6
| [torch.FloatTensor of size (3,)]
|
| >>> h.remove() # removes the hook
|
| register_post_accumulate_grad_hook(self, hook) from torch._tensor.Tensor
| Registers a backward hook that runs after grad accumulation.
|
| The hook will be called after all gradients for a tensor have been accumulated,
| meaning that the .grad field has been updated on that tensor. The post
| accumulate grad hook is ONLY applicable for leaf tensors (tensors without a
| .grad_fn field). Registering this hook on a non-leaf tensor will error!
|
| The hook should have the following signature::
|
| hook(param: Tensor) -> None
|
| Note that, unlike other autograd hooks, this hook operates on the tensor
| that requires grad and not the grad itself. The hook can in-place modify
| and access its Tensor argument, including its .grad field.
|
| This function returns a handle with a method ``handle.remove()``
| that removes the hook from the module.
|
| .. note::
| See :ref:`backward-hooks-execution` for more information on how when this hook
| is executed, and how its execution is ordered relative to other hooks. Since
| this hook runs during the backward pass, it will run in no_grad mode (unless
| create_graph is True). You can use torch.enable_grad() to re-enable autograd
| within the hook if you need it.
|
| Example::
|
| >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
| >>> lr = 0.01
| >>> # simulate a simple SGD update
| >>> h = v.register_post_accumulate_grad_hook(lambda p: p.add_(p.grad, alpha=-lr))
| >>> v.backward(torch.tensor([1., 2., 3.]))
| >>> v
| tensor([-0.0100, -0.0200, -0.0300], requires_grad=True)
|
| >>> h.remove() # removes the hook
|
| reinforce(self, reward) from torch._tensor.Tensor
|
| resize(self, *sizes) from torch._tensor.Tensor
|
| resize_as(self, tensor) from torch._tensor.Tensor
|
| share_memory_(self) from torch._tensor.Tensor
| Moves the underlying storage to shared memory.
|
| This is a no-op if the underlying storage is already in shared memory
| and for CUDA tensors. Tensors in shared memory cannot be resized.
|
| See :meth:`torch.UntypedStorage.share_memory_` for more details.
|
| solve(self, other) from torch._tensor.Tensor
|
| split(self, split_size, dim=0) from torch._tensor.Tensor
| See :func:`torch.split`
|
| stft(self, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: 'Tensor | None' = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) from torch._tensor.Tensor
| See :func:`torch.stft`
|
| .. warning::
| This function changed signature at version 0.4.1. Calling with
| the previous signature may cause error or return incorrect result.
|
| storage(self) from torch._tensor.Tensor
| storage() -> torch.TypedStorage
|
| Returns the underlying :class:`TypedStorage`.
|
| .. warning::
|
| :class:`TypedStorage` is deprecated. It will be removed in the future, and
| :class:`UntypedStorage` will be the only storage class. To access the
| :class:`UntypedStorage` directly, use :attr:`Tensor.untyped_storage()`.
|
| storage_type(self) from torch._tensor.Tensor
| storage_type() -> type
|
| Returns the type of the underlying storage.
|
| symeig(self, eigenvectors=False) from torch._tensor.Tensor
|
| to_sparse_coo(self) from torch._tensor.Tensor
| Convert a tensor to :ref:`coordinate format <sparse-coo-docs>`.
|
| Examples::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_coo()
| >>> sparse._nnz()
| 25
|
| unflatten(self, dim, sizes) from torch._tensor.Tensor
| unflatten(dim, sizes) -> Tensor
|
| See :func:`torch.unflatten`.
|
| unique(self, sorted=True, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Returns the unique elements of the input tensor.
|
| See :func:`torch.unique`
|
| unique_consecutive(self, return_inverse=False, return_counts=False, dim=None) from torch._tensor.Tensor
| Eliminates all but the first element from every consecutive group of equivalent elements.
|
| See :func:`torch.unique_consecutive`
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| __torch_function__(func, types, args=(), kwargs=None) from torch._tensor.Tensor
| This __torch_function__ implementation wraps subclasses such that
| methods called on subclasses return a subclass instance instead of
| a ``torch.Tensor`` instance.
|
| One corollary to this is that you need coverage for torch.Tensor
| methods if implementing __torch_function__ for subclasses.
|
| We recommend always calling ``super().__torch_function__`` as the base
| case when doing the above.
|
| While not mandatory, we recommend making `__torch_function__` a classmethod.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __torch_dispatch__ = _disabled_torch_dispatch_impl(...)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __cuda_array_interface__
| Array view description for cuda tensors.
|
| See:
| https://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'__dlpack_c_exchange_api__': <class 'object'>, '_is...
|
| __array_priority__ = 1000
|
| __dlpack_c_exchange_api__ = <capsule object "dlpack_exchange_api">
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C.TensorBase:
|
| __add__(...)
|
| __and__(...)
|
| __bool__(...)
|
| __complex__(...)
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __div__(...)
|
| __eq__(...)
| Return self==value.
|
| __float__(...)
|
| __ge__(...)
| Return self>=value.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __gt__(...)
| Return self>value.
|
| __iadd__(...)
|
| __iand__(...)
|
| __idiv__(...)
|
| __ifloordiv__(...)
|
| __ilshift__(...)
|
| __imod__(...)
|
| __imul__(...)
|
| __index__(...)
|
| __int__(...)
|
| __invert__(...)
|
| __ior__(...)
|
| __irshift__(...)
|
| __isub__(...)
|
| __ixor__(...)
|
| __le__(...)
| Return self<=value.
|
| __long__(...)
|
| __lshift__(...)
|
| __lt__(...)
| Return self<value.
|
| __matmul__(...)
|
| __mod__(...)
|
| __mul__(...)
|
| __ne__(...)
| Return self!=value.
|
| __nonzero__(...)
|
| __or__(...)
| Return self|value.
|
| __radd__(...)
|
| __rand__(...)
|
| __rmul__(...)
|
| __ror__(...)
| Return value|self.
|
| __rshift__(...)
|
| __rxor__(...)
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sub__(...)
|
| __truediv__(...)
|
| __xor__(...)
|
| abs(...)
| abs() -> Tensor
|
| See :func:`torch.abs`
|
| abs_(...)
| abs_() -> Tensor
|
| In-place version of :meth:`~Tensor.abs`
|
| absolute(...)
| absolute() -> Tensor
|
| Alias for :func:`abs`
|
| absolute_(...)
| absolute_() -> Tensor
|
| In-place version of :meth:`~Tensor.absolute`
| Alias for :func:`abs_`
|
| acos(...)
| acos() -> Tensor
|
| See :func:`torch.acos`
|
| acos_(...)
| acos_() -> Tensor
|
| In-place version of :meth:`~Tensor.acos`
|
| acosh(...)
| acosh() -> Tensor
|
| See :func:`torch.acosh`
|
| acosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.acosh`
|
| add(...)
| add(other, *, alpha=1) -> Tensor
|
| Add a scalar or tensor to :attr:`self` tensor. If both :attr:`alpha`
| and :attr:`other` are specified, each element of :attr:`other` is scaled by
| :attr:`alpha` before being used.
|
| When :attr:`other` is a tensor, the shape of :attr:`other` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor
|
| See :func:`torch.add`
|
| add_(...)
| add_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.add`
|
| addbmm(...)
| addbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addbmm`
|
| addbmm_(...)
| addbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addbmm`
|
| addcdiv(...)
| addcdiv(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcdiv`
|
| addcdiv_(...)
| addcdiv_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcdiv`
|
| addcmul(...)
| addcmul(tensor1, tensor2, *, value=1) -> Tensor
|
| See :func:`torch.addcmul`
|
| addcmul_(...)
| addcmul_(tensor1, tensor2, *, value=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addcmul`
|
| addmm(...)
| addmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmm`
|
| addmm_(...)
| addmm_(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmm`
|
| addmv(...)
| addmv(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addmv`
|
| addmv_(...)
| addmv_(mat, vec, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addmv`
|
| addr(...)
| addr(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.addr`
|
| addr_(...)
| addr_(vec1, vec2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.addr`
|
| adjoint(...)
| adjoint() -> Tensor
|
| Alias for :func:`adjoint`
|
| all(...)
| all(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.all`
|
| allclose(...)
| allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.allclose`
|
| amax(...)
| amax(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amax`
|
| amin(...)
| amin(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.amin`
|
| aminmax(...)
| aminmax(*, dim=None, keepdim=False) -> (Tensor min, Tensor max)
|
| See :func:`torch.aminmax`
|
| angle(...)
| angle() -> Tensor
|
| See :func:`torch.angle`
|
| any(...)
| any(dim=None, keepdim=False) -> Tensor
|
| See :func:`torch.any`
|
| apply_(...)
| apply_(callable) -> Tensor
|
| Applies the function :attr:`callable` to each element in the tensor, replacing
| each element with the value returned by :attr:`callable`.
|
| .. note::
|
| This function only works with CPU tensors and should not be used in code
| sections that require high performance.
|
| arccos(...)
| arccos() -> Tensor
|
| See :func:`torch.arccos`
|
| arccos_(...)
| arccos_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccos`
|
| arccosh(...)
| acosh() -> Tensor
|
| See :func:`torch.arccosh`
|
| arccosh_(...)
| acosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arccosh`
|
| arcsin(...)
| arcsin() -> Tensor
|
| See :func:`torch.arcsin`
|
| arcsin_(...)
| arcsin_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsin`
|
| arcsinh(...)
| arcsinh() -> Tensor
|
| See :func:`torch.arcsinh`
|
| arcsinh_(...)
| arcsinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.arcsinh`
|
| arctan(...)
| arctan() -> Tensor
|
| See :func:`torch.arctan`
|
| arctan2(...)
| arctan2(other) -> Tensor
|
| See :func:`torch.arctan2`
|
| arctan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctan2`
|
| arctan_(...)
| arctan_() -> Tensor
|
| In-place version of :meth:`~Tensor.arctan`
|
| arctanh(...)
| arctanh() -> Tensor
|
| See :func:`torch.arctanh`
|
| arctanh_(...)
| arctanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.arctanh`
|
| argmax(...)
| argmax(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmax`
|
| argmin(...)
| argmin(dim=None, keepdim=False) -> LongTensor
|
| See :func:`torch.argmin`
|
| argsort(...)
| argsort(dim=-1, descending=False) -> LongTensor
|
| See :func:`torch.argsort`
|
| argwhere(...)
| argwhere() -> Tensor
|
| See :func:`torch.argwhere`
|
| as_strided(...)
| as_strided(size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided`
|
| as_strided_(...)
| as_strided_(size, stride, storage_offset=None) -> Tensor
|
| In-place version of :meth:`~Tensor.as_strided`
|
| as_strided_scatter(...)
| as_strided_scatter(src, size, stride, storage_offset=None) -> Tensor
|
| See :func:`torch.as_strided_scatter`
|
| as_subclass(...)
| as_subclass(cls) -> Tensor
|
| Makes a ``cls`` instance with the same data pointer as ``self``. Changes
| in the output mirror changes in ``self``, and the output stays attached
| to the autograd graph. ``cls`` must be a subclass of ``Tensor``.
|
| asin(...)
| asin() -> Tensor
|
| See :func:`torch.asin`
|
| asin_(...)
| asin_() -> Tensor
|
| In-place version of :meth:`~Tensor.asin`
|
| asinh(...)
| asinh() -> Tensor
|
| See :func:`torch.asinh`
|
| asinh_(...)
| asinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.asinh`
|
| atan(...)
| atan() -> Tensor
|
| See :func:`torch.atan`
|
| atan2(...)
| atan2(other) -> Tensor
|
| See :func:`torch.atan2`
|
| atan2_(...)
| atan2_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atan2`
|
| atan_(...)
| atan_() -> Tensor
|
| In-place version of :meth:`~Tensor.atan`
|
| atanh(...)
| atanh() -> Tensor
|
| See :func:`torch.atanh`
|
| atanh_(...)
| atanh_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.atanh`
|
| baddbmm(...)
| baddbmm(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.baddbmm`
|
| baddbmm_(...)
| baddbmm_(batch1, batch2, *, beta=1, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.baddbmm`
|
| bernoulli(...)
| bernoulli(*, generator=None) -> Tensor
|
| Returns a result tensor where each :math:`\texttt{result[i]}` is independently
| sampled from :math:`\text{Bernoulli}(\texttt{self[i]})`. :attr:`self` must have
| floating point ``dtype``, and the result will have the same ``dtype``.
|
| See :func:`torch.bernoulli`
|
| bernoulli_(...)
| bernoulli_(p=0.5, *, generator=None) -> Tensor
|
| Fills each location of :attr:`self` with an independent sample from
| :math:`\text{Bernoulli}(\texttt{p})`. :attr:`self` can have integral
| ``dtype``.
|
| :attr:`p` should either be a scalar or tensor containing probabilities to be
| used for drawing the binary random number.
|
| If it is a tensor, the :math:`\text{i}^{th}` element of :attr:`self` tensor
| will be set to a value sampled from
| :math:`\text{Bernoulli}(\texttt{p\_tensor[i]})`. In this case `p` must have
| floating point ``dtype``.
|
| See also :meth:`~Tensor.bernoulli` and :func:`torch.bernoulli`
|
| bfloat16(...)
| bfloat16(memory_format=torch.preserve_format) -> Tensor
| ``self.bfloat16()`` is equivalent to ``self.to(torch.bfloat16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| bincount(...)
| bincount(weights=None, minlength=0) -> Tensor
|
| See :func:`torch.bincount`
|
| bitwise_and(...)
| bitwise_and() -> Tensor
|
| See :func:`torch.bitwise_and`
|
| bitwise_and_(...)
| bitwise_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_and`
|
| bitwise_left_shift(...)
| bitwise_left_shift(other) -> Tensor
|
| See :func:`torch.bitwise_left_shift`
|
| bitwise_left_shift_(...)
| bitwise_left_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_left_shift`
|
| bitwise_not(...)
| bitwise_not() -> Tensor
|
| See :func:`torch.bitwise_not`
|
| bitwise_not_(...)
| bitwise_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_not`
|
| bitwise_or(...)
| bitwise_or() -> Tensor
|
| See :func:`torch.bitwise_or`
|
| bitwise_or_(...)
| bitwise_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_or`
|
| bitwise_right_shift(...)
| bitwise_right_shift(other) -> Tensor
|
| See :func:`torch.bitwise_right_shift`
|
| bitwise_right_shift_(...)
| bitwise_right_shift_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_right_shift`
|
| bitwise_xor(...)
| bitwise_xor() -> Tensor
|
| See :func:`torch.bitwise_xor`
|
| bitwise_xor_(...)
| bitwise_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.bitwise_xor`
|
| bmm(...)
| bmm(batch2) -> Tensor
|
| See :func:`torch.bmm`
|
| bool(...)
| bool(memory_format=torch.preserve_format) -> Tensor
|
| ``self.bool()`` is equivalent to ``self.to(torch.bool)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| broadcast_to(...)
| broadcast_to(shape) -> Tensor
|
| See :func:`torch.broadcast_to`.
|
| byte(...)
| byte(memory_format=torch.preserve_format) -> Tensor
|
| ``self.byte()`` is equivalent to ``self.to(torch.uint8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cauchy_(...)
| cauchy_(median=0, sigma=1, *, generator=None) -> Tensor
|
| Fills the tensor with numbers drawn from the Cauchy distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{\pi} \dfrac{\sigma}{(x - \text{median})^2 + \sigma^2}
|
| .. note::
| Sigma (:math:`\sigma`) is used to denote the scale parameter in Cauchy distribution.
|
| ccol_indices(...)
|
| cdouble(...)
| cdouble(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cdouble()`` is equivalent to ``self.to(torch.complex128)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| ceil(...)
| ceil() -> Tensor
|
| See :func:`torch.ceil`
|
| ceil_(...)
| ceil_() -> Tensor
|
| In-place version of :meth:`~Tensor.ceil`
|
| cfloat(...)
| cfloat(memory_format=torch.preserve_format) -> Tensor
|
| ``self.cfloat()`` is equivalent to ``self.to(torch.complex64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| chalf(...)
| chalf(memory_format=torch.preserve_format) -> Tensor
|
| ``self.chalf()`` is equivalent to ``self.to(torch.complex32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| char(...)
| char(memory_format=torch.preserve_format) -> Tensor
|
| ``self.char()`` is equivalent to ``self.to(torch.int8)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cholesky(...)
| cholesky(upper=False) -> Tensor
|
| See :func:`torch.cholesky`
|
| cholesky_inverse(...)
| cholesky_inverse(upper=False) -> Tensor
|
| See :func:`torch.cholesky_inverse`
|
| cholesky_solve(...)
| cholesky_solve(input2, upper=False) -> Tensor
|
| See :func:`torch.cholesky_solve`
|
| chunk(...)
| chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.chunk`
|
| clamp(...)
| clamp(min=None, max=None) -> Tensor
|
| See :func:`torch.clamp`
|
| clamp_(...)
| clamp_(min=None, max=None) -> Tensor
|
| In-place version of :meth:`~Tensor.clamp`
|
| clamp_max(...)
|
| clamp_max_(...)
|
| clamp_min(...)
|
| clamp_min_(...)
|
| clip(...)
| clip(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp`.
|
| clip_(...)
| clip_(min=None, max=None) -> Tensor
|
| Alias for :meth:`~Tensor.clamp_`.
|
| clone(...)
| clone(*, memory_format=torch.preserve_format) -> Tensor
|
| See :func:`torch.clone`
|
| coalesce(...)
| coalesce() -> Tensor
|
| Returns a coalesced copy of :attr:`self` if :attr:`self` is an
| :ref:`uncoalesced tensor <sparse-uncoalesced-coo-docs>`.
|
| Returns :attr:`self` if :attr:`self` is a coalesced tensor.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| col_indices(...)
| col_indices() -> IntTensor
|
| Returns the tensor containing the column indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``col_indices`` tensor is strictly of shape (:attr:`self`.nnz())
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.col_indices()
| tensor([0, 1, 2, 3, 4], dtype=torch.int32)
|
| conj(...)
| conj() -> Tensor
|
| See :func:`torch.conj`
|
| conj_physical(...)
| conj_physical() -> Tensor
|
| See :func:`torch.conj_physical`
|
| conj_physical_(...)
| conj_physical_() -> Tensor
|
| In-place version of :meth:`~Tensor.conj_physical`
|
| const_data_ptr(...)
| const_data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| Unlike :meth:`data_ptr`, this is guaranteed to be a read-only access
| that will not trigger copy-on-write materialization. For regular
| (non-COW) tensors, the return value is identical to :meth:`data_ptr`.
|
| .. warning::
|
| The returned pointer must not be used to mutate the tensor data.
| Use :meth:`data_ptr` when write access is needed.
|
| contiguous(...)
| contiguous(memory_format=torch.contiguous_format) -> Tensor
|
| Returns a contiguous in memory tensor containing the same data as :attr:`self` tensor. If
| :attr:`self` tensor is already in the specified memory format, this function returns the
| :attr:`self` tensor.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.contiguous_format``.
|
| copy_(...)
| copy_(src, non_blocking=False) -> Tensor
|
| Copies the elements from :attr:`src` into :attr:`self` tensor and returns
| :attr:`self`.
|
| The :attr:`src` tensor must be :ref:`broadcastable <broadcasting-semantics>`
| with the :attr:`self` tensor. It may be of a different data type or reside on a
| different device.
|
| Args:
| src (Tensor): the source tensor to copy from
| non_blocking (bool, optional): if ``True`` and this copy is between CPU and GPU,
| the copy may occur asynchronously with respect to the host. For other
| cases, this argument has no effect. Default: ``False``
|
| copysign(...)
| copysign(other) -> Tensor
|
| See :func:`torch.copysign`
|
| copysign_(...)
| copysign_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.copysign`
|
| corrcoef(...)
| corrcoef() -> Tensor
|
| See :func:`torch.corrcoef`
|
| cos(...)
| cos() -> Tensor
|
| See :func:`torch.cos`
|
| cos_(...)
| cos_() -> Tensor
|
| In-place version of :meth:`~Tensor.cos`
|
| cosh(...)
| cosh() -> Tensor
|
| See :func:`torch.cosh`
|
| cosh_(...)
| cosh_() -> Tensor
|
| In-place version of :meth:`~Tensor.cosh`
|
| count_nonzero(...)
| count_nonzero(dim=None) -> Tensor
|
| See :func:`torch.count_nonzero`
|
| cov(...)
| cov(*, correction=1, fweights=None, aweights=None) -> Tensor
|
| See :func:`torch.cov`
|
| cpu(...)
| cpu(memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CPU memory.
|
| If this object is already in CPU memory,
| then no copy is performed and the original object is returned.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cross(...)
| cross(other, dim=None) -> Tensor
|
| See :func:`torch.cross`
|
| crow_indices(...)
| crow_indices() -> IntTensor
|
| Returns the tensor containing the compressed row indices of the :attr:`self`
| tensor when :attr:`self` is a sparse CSR tensor of layout ``sparse_csr``.
| The ``crow_indices`` tensor is strictly of shape (:attr:`self`.size(0) + 1)
| and of type ``int32`` or ``int64``. When using MKL routines such as sparse
| matrix multiplication, it is necessary to use ``int32`` indexing in order
| to avoid downcasting and potentially losing information.
|
| Example::
|
| >>> csr = torch.eye(5,5).to_sparse_csr()
| >>> csr.crow_indices()
| tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)
|
| cuda(...)
| cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination GPU device.
| Defaults to the current CUDA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| cummax(...)
| cummax(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummax`
|
| cummin(...)
| cummin(dim) -> (Tensor, Tensor)
|
| See :func:`torch.cummin`
|
| cumprod(...)
| cumprod(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumprod`
|
| cumprod_(...)
| cumprod_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumprod`
|
| cumsum(...)
| cumsum(dim, dtype=None) -> Tensor
|
| See :func:`torch.cumsum`
|
| cumsum_(...)
| cumsum_(dim, dtype=None) -> Tensor
|
| In-place version of :meth:`~Tensor.cumsum`
|
| data_ptr(...)
| data_ptr() -> int
|
| Returns the address of the first element of :attr:`self` tensor.
|
| .. note::
|
| If the tensor is a copy-on-write tensor (e.g. created via
| :meth:`_lazy_clone`), calling this method will materialize the
| copy. Use :meth:`const_data_ptr` if you only need read-only access
| to the data pointer.
|
| deg2rad(...)
| deg2rad() -> Tensor
|
| See :func:`torch.deg2rad`
|
| deg2rad_(...)
| deg2rad_() -> Tensor
|
| In-place version of :meth:`~Tensor.deg2rad`
|
| dense_dim(...)
| dense_dim() -> int
|
| Return the number of dense dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``len(self.shape)`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.sparse_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| dequantize(...)
| dequantize() -> Tensor
|
| Given a quantized Tensor, dequantize it and return the dequantized float Tensor.
|
| det(...)
| det() -> Tensor
|
| See :func:`torch.det`
|
| diag(...)
| diag(diagonal=0) -> Tensor
|
| See :func:`torch.diag`
|
| diag_embed(...)
| diag_embed(offset=0, dim1=-2, dim2=-1) -> Tensor
|
| See :func:`torch.diag_embed`
|
| diagflat(...)
| diagflat(offset=0) -> Tensor
|
| See :func:`torch.diagflat`
|
| diagonal(...)
| diagonal(offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal`
|
| diagonal_scatter(...)
| diagonal_scatter(src, offset=0, dim1=0, dim2=1) -> Tensor
|
| See :func:`torch.diagonal_scatter`
|
| diff(...)
| diff(n=1, dim=-1, prepend=None, append=None) -> Tensor
|
| See :func:`torch.diff`
|
| digamma(...)
| digamma() -> Tensor
|
| See :func:`torch.digamma`
|
| digamma_(...)
| digamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.digamma`
|
| dim(...)
| dim() -> int
|
| Returns the number of dimensions of :attr:`self` tensor.
|
| dist(...)
| dist(other, p=2) -> Tensor
|
| See :func:`torch.dist`
|
| div(...)
| div(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.div`
|
| div_(...)
| div_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.div`
|
| divide(...)
| divide(value, *, rounding_mode=None) -> Tensor
|
| See :func:`torch.divide`
|
| divide_(...)
| divide_(value, *, rounding_mode=None) -> Tensor
|
| In-place version of :meth:`~Tensor.divide`
|
| dot(...)
| dot(other) -> Tensor
|
| See :func:`torch.dot`
|
| double(...)
| double(memory_format=torch.preserve_format) -> Tensor
|
| ``self.double()`` is equivalent to ``self.to(torch.float64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| dsplit(...)
| dsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.dsplit`
|
| element_size(...)
| element_size() -> int
|
| Returns the size in bytes of an individual element.
|
| Example::
|
| >>> torch.tensor([]).element_size()
| 4
| >>> torch.tensor([], dtype=torch.uint8).element_size()
| 1
|
| eq(...)
| eq(other) -> Tensor
|
| See :func:`torch.eq`
|
| eq_(...)
| eq_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.eq`
|
| equal(...)
| equal(other) -> bool
|
| See :func:`torch.equal`
|
| erf(...)
| erf() -> Tensor
|
| See :func:`torch.erf`
|
| erf_(...)
| erf_() -> Tensor
|
| In-place version of :meth:`~Tensor.erf`
|
| erfc(...)
| erfc() -> Tensor
|
| See :func:`torch.erfc`
|
| erfc_(...)
| erfc_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfc`
|
| erfinv(...)
| erfinv() -> Tensor
|
| See :func:`torch.erfinv`
|
| erfinv_(...)
| erfinv_() -> Tensor
|
| In-place version of :meth:`~Tensor.erfinv`
|
| exp(...)
| exp() -> Tensor
|
| See :func:`torch.exp`
|
| exp2(...)
| exp2() -> Tensor
|
| See :func:`torch.exp2`
|
| exp2_(...)
| exp2_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp2`
|
| exp_(...)
| exp_() -> Tensor
|
| In-place version of :meth:`~Tensor.exp`
|
| expand(...)
| expand(*size) -> Tensor
|
| Returns a new view of the :attr:`self` tensor with singleton dimensions expanded
| to a larger size.
|
| Passing -1 as the size for a dimension means not changing the size of
| that dimension.
|
| Tensor can be also expanded to a larger number of dimensions, and the
| new ones will be appended at the front. For the new dimensions, the
| size cannot be set to -1.
|
| Expanding a tensor does not allocate new memory, but only creates a
| new view on the existing tensor where a dimension of size one is
| expanded to a larger size by setting the ``stride`` to 0. Any dimension
| of size 1 can be expanded to an arbitrary value without allocating new
| memory.
|
| .. note::
|
| Operations on an expanded view may still allocate memory if they need to
| materialize the expanded values. For example, changing dtype after
| :meth:`expand` can allocate memory for the full expanded shape.
|
| Args:
| *size (torch.Size or int...): the desired expanded size
|
| .. warning::
|
| More than one element of an expanded tensor may refer to a single
| memory location. As a result, in-place operations (especially ones that
| are vectorized) may result in incorrect behavior. If you need to write
| to the tensors, please clone them first.
|
| Example::
|
| >>> x = torch.tensor([[1], [2], [3]])
| >>> x.size()
| torch.Size([3, 1])
| >>> x.expand(3, 4)
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
| >>> x.expand(-1, 4) # -1 means not changing the size of that dimension
| tensor([[ 1, 1, 1, 1],
| [ 2, 2, 2, 2],
| [ 3, 3, 3, 3]])
|
| expand_as(...)
| expand_as(other) -> Tensor
|
| Expand this tensor to the same size as :attr:`other`.
| ``self.expand_as(other)`` is equivalent to ``self.expand(other.size())``.
|
| Please see :meth:`~Tensor.expand` for more information about ``expand``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| expm1(...)
| expm1() -> Tensor
|
| See :func:`torch.expm1`
|
| expm1_(...)
| expm1_() -> Tensor
|
| In-place version of :meth:`~Tensor.expm1`
|
| exponential_(...)
| exponential_(lambd=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the PDF (probability density function):
|
| .. math::
|
| f(x) = \lambda e^{-\lambda x}, x > 0
|
| .. note::
| In probability theory, exponential distribution is supported on interval [0, :math:`\inf`) (i.e., :math:`x >= 0`)
| implying that zero can be sampled from the exponential distribution.
| However, :func:`torch.Tensor.exponential_` does not sample zero,
| which means that its actual support is the interval (0, :math:`\inf`).
|
| Note that :func:`torch.distributions.exponential.Exponential` is supported on the interval [0, :math:`\inf`) and can sample zero.
|
| fill_(...)
| fill_(value) -> Tensor
|
| Fills :attr:`self` tensor with the specified value.
|
| fill_diagonal_(...)
| fill_diagonal_(fill_value, wrap=False) -> Tensor
|
| Fill the main diagonal of a tensor that has at least 2-dimensions.
| When dims>2, all dimensions of input must be of equal length.
| This function modifies the input tensor in-place, and returns the input tensor.
|
| Arguments:
| fill_value (Scalar): the fill value
| wrap (bool, optional): the diagonal 'wrapped' after N columns for tall matrices. Default: ``False``
|
| Example::
|
| >>> a = torch.zeros(3, 3)
| >>> a.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
| >>> b = torch.zeros(7, 3)
| >>> b.fill_diagonal_(5)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.],
| [0., 0., 0.]])
| >>> c = torch.zeros(7, 3)
| >>> c.fill_diagonal_(5, wrap=True)
| tensor([[5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.],
| [0., 0., 0.],
| [5., 0., 0.],
| [0., 5., 0.],
| [0., 0., 5.]])
|
| fix(...)
| fix() -> Tensor
|
| See :func:`torch.fix`.
|
| fix_(...)
| fix_() -> Tensor
|
| In-place version of :meth:`~Tensor.fix`
|
| flatten(...)
| flatten(start_dim=0, end_dim=-1) -> Tensor
|
| See :func:`torch.flatten`
|
| flip(...)
| flip(dims) -> Tensor
|
| See :func:`torch.flip`
|
| fliplr(...)
| fliplr() -> Tensor
|
| See :func:`torch.fliplr`
|
| flipud(...)
| flipud() -> Tensor
|
| See :func:`torch.flipud`
|
| float(...)
| float(memory_format=torch.preserve_format) -> Tensor
|
| ``self.float()`` is equivalent to ``self.to(torch.float32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| float_power(...)
| float_power(exponent) -> Tensor
|
| See :func:`torch.float_power`
|
| float_power_(...)
| float_power_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.float_power`
|
| floor(...)
| floor() -> Tensor
|
| See :func:`torch.floor`
|
| floor_(...)
| floor_() -> Tensor
|
| In-place version of :meth:`~Tensor.floor`
|
| floor_divide(...)
| floor_divide(value) -> Tensor
|
| See :func:`torch.floor_divide`
|
| floor_divide_(...)
| floor_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.floor_divide`
|
| fmax(...)
| fmax(other) -> Tensor
|
| See :func:`torch.fmax`
|
| fmin(...)
| fmin(other) -> Tensor
|
| See :func:`torch.fmin`
|
| fmod(...)
| fmod(divisor) -> Tensor
|
| See :func:`torch.fmod`
|
| fmod_(...)
| fmod_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.fmod`
|
| frac(...)
| frac() -> Tensor
|
| See :func:`torch.frac`
|
| frac_(...)
| frac_() -> Tensor
|
| In-place version of :meth:`~Tensor.frac`
|
| frexp(...)
| frexp(input) -> (Tensor mantissa, Tensor exponent)
|
| See :func:`torch.frexp`
|
| gather(...)
| gather(dim, index) -> Tensor
|
| See :func:`torch.gather`
|
| gcd(...)
| gcd(other) -> Tensor
|
| See :func:`torch.gcd`
|
| gcd_(...)
| gcd_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gcd`
|
| ge(...)
| ge(other) -> Tensor
|
| See :func:`torch.ge`.
|
| ge_(...)
| ge_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ge`.
|
| geometric_(...)
| geometric_(p, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements drawn from the geometric distribution:
|
| .. math::
|
| P(X=k) = (1 - p)^{k - 1} p, k = 1, 2, ...
|
| .. note::
| :func:`torch.Tensor.geometric_` `k`-th trial is the first success hence draws samples in :math:`\{1, 2, \ldots\}`, whereas
| :func:`torch.distributions.geometric.Geometric` :math:`(k+1)`-th trial is the first success
| hence draws samples in :math:`\{0, 1, \ldots\}`.
|
| geqrf(...)
| geqrf() -> (Tensor, Tensor)
|
| See :func:`torch.geqrf`
|
| ger(...)
| ger(vec2) -> Tensor
|
| See :func:`torch.ger`
|
| get_device(...)
| get_device() -> Device ordinal (Integer)
|
| For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.
| For CPU tensors, this function returns `-1`.
|
| Example::
|
| >>> x = torch.randn(3, 4, 5, device='cuda:0')
| >>> x.get_device()
| 0
| >>> x.cpu().get_device()
| -1
|
| greater(...)
| greater(other) -> Tensor
|
| See :func:`torch.greater`.
|
| greater_(...)
| greater_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater`.
|
| greater_equal(...)
| greater_equal(other) -> Tensor
|
| See :func:`torch.greater_equal`.
|
| greater_equal_(...)
| greater_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.greater_equal`.
|
| gt(...)
| gt(other) -> Tensor
|
| See :func:`torch.gt`.
|
| gt_(...)
| gt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.gt`.
|
| half(...)
| half(memory_format=torch.preserve_format) -> Tensor
|
| ``self.half()`` is equivalent to ``self.to(torch.float16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| hardshrink(...)
| hardshrink(lambd=0.5) -> Tensor
|
| See :func:`torch.nn.functional.hardshrink`
|
| hash_tensor(...)
|
| heaviside(...)
| heaviside(values) -> Tensor
|
| See :func:`torch.heaviside`
|
| heaviside_(...)
| heaviside_(values) -> Tensor
|
| In-place version of :meth:`~Tensor.heaviside`
|
| histc(...)
| histc(bins=100, min=0, max=0) -> Tensor
|
| See :func:`torch.histc`
|
| histogram(...)
| histogram(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor)
|
| See :func:`torch.histogram`
|
| hsplit(...)
| hsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.hsplit`
|
| hypot(...)
| hypot(other) -> Tensor
|
| See :func:`torch.hypot`
|
| hypot_(...)
| hypot_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.hypot`
|
| i0(...)
| i0() -> Tensor
|
| See :func:`torch.i0`
|
| i0_(...)
| i0_() -> Tensor
|
| In-place version of :meth:`~Tensor.i0`
|
| igamma(...)
| igamma(other) -> Tensor
|
| See :func:`torch.igamma`
|
| igamma_(...)
| igamma_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.igamma`
|
| igammac(...)
| igammac(other) -> Tensor
| See :func:`torch.igammac`
|
| igammac_(...)
| igammac_(other) -> Tensor
| In-place version of :meth:`~Tensor.igammac`
|
| index_add(...)
| index_add(dim, index, source, *, alpha=1) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_add_`.
|
| index_add_(...)
| index_add_(dim, index, source, *, alpha=1) -> Tensor
|
| Accumulate the elements of :attr:`alpha` times ``source`` into the :attr:`self`
| tensor by adding to the indices in the order given in :attr:`index`. For example,
| if ``dim == 0``, ``index[i] == j``, and ``alpha=-1``, then the ``i``\ th row of
| ``source`` is subtracted from the ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor the output is given as::
|
| self[index[i], :, :] += alpha * src[i, :, :] # if dim == 0
| self[:, index[i], :] += alpha * src[:, i, :] # if dim == 1
| self[:, :, index[i]] += alpha * src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (Tensor): the tensor containing values to add
|
| Keyword args:
| alpha (Number): the scalar multiplier for ``source``
|
| Example::
|
| >>> x = torch.ones(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_add_(0, index, t)
| tensor([[ 2., 3., 4.],
| [ 1., 1., 1.],
| [ 8., 9., 10.],
| [ 1., 1., 1.],
| [ 5., 6., 7.]])
| >>> x.index_add_(0, index, t, alpha=-1)
| tensor([[ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.],
| [ 1., 1., 1.]])
|
| index_copy(...)
| index_copy(dim, index, tensor2) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_copy_`.
|
| index_copy_(...)
| index_copy_(dim, index, tensor) -> Tensor
|
| Copies the elements of :attr:`tensor` into the :attr:`self` tensor by selecting
| the indices in the order given in :attr:`index`. For example, if ``dim == 0``
| and ``index[i] == j``, then the ``i``\ th row of :attr:`tensor` is copied to the
| ``j``\ th row of :attr:`self`.
|
| The :attr:`dim`\ th dimension of :attr:`tensor` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| .. note::
| If :attr:`index` contains duplicate entries, multiple elements from
| :attr:`tensor` will be copied to the same index of :attr:`self`. The result
| is nondeterministic since it depends on which copy occurs last.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`tensor` to select from
| tensor (Tensor): the tensor containing values to copy
|
| Example::
|
| >>> x = torch.zeros(5, 3)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2])
| >>> x.index_copy_(0, index, t)
| tensor([[ 1., 2., 3.],
| [ 0., 0., 0.],
| [ 7., 8., 9.],
| [ 0., 0., 0.],
| [ 4., 5., 6.]])
|
| index_fill(...)
| index_fill(dim, index, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.index_fill_`.
|
| index_fill_(...)
| index_fill_(dim, index, value) -> Tensor
|
| Fills the elements of the :attr:`self` tensor with value :attr:`value` by
| selecting the indices in the order given in :attr:`index`.
|
| Args:
| dim (int): dimension along which to index
| index (LongTensor): indices of :attr:`self` tensor to fill in
| value (float): the value to fill with
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
| >>> index = torch.tensor([0, 2])
| >>> x.index_fill_(1, index, -1)
| tensor([[-1., 2., -1.],
| [-1., 5., -1.],
| [-1., 8., -1.]])
|
| index_put(...)
| index_put(indices, values, accumulate=False) -> Tensor
|
| Out-place version of :meth:`~Tensor.index_put_`.
|
| index_put_(...)
| index_put_(indices, values, accumulate=False) -> Tensor
|
| Puts values from the tensor :attr:`values` into the tensor :attr:`self` using
| the indices specified in :attr:`indices` (which is a tuple of Tensors). The
| expression ``tensor.index_put_(indices, values)`` is equivalent to
| ``tensor[indices] = values``. Returns :attr:`self`.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`values` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if indices
| contain duplicate elements.
|
| Args:
| indices (tuple of LongTensor): tensors used to index into `self`.
| values (Tensor): tensor of same dtype as `self`.
| accumulate (bool): whether to accumulate into self
|
| index_reduce(...)
|
| index_reduce_(...)
| index_reduce_(dim, index, source, reduce, *, include_self=True) -> Tensor
|
| Accumulate the elements of ``source`` into the :attr:`self`
| tensor by accumulating to the indices in the order given in :attr:`index`
| using the reduction given by the ``reduce`` argument. For example, if ``dim == 0``,
| ``index[i] == j``, ``reduce == prod`` and ``include_self == True`` then the ``i``\ th
| row of ``source`` is multiplied by the ``j``\ th row of :attr:`self`. If
| :obj:`include_self="True"`, the values in the :attr:`self` tensor are included
| in the reduction, otherwise, rows in the :attr:`self` tensor that are accumulated
| to are treated as if they were filled with the reduction identities.
|
| The :attr:`dim`\ th dimension of ``source`` must have the same size as the
| length of :attr:`index` (which must be a vector), and all other dimensions must
| match :attr:`self`, or an error will be raised.
|
| For a 3-D tensor with :obj:`reduce="prod"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i], :, :] *= src[i, :, :] # if dim == 0
| self[:, index[i], :] *= src[:, i, :] # if dim == 1
| self[:, :, index[i]] *= src[:, :, i] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| This function only supports floating point tensors.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): dimension along which to index
| index (Tensor): indices of ``source`` to select from,
| should have dtype either `torch.int64` or `torch.int32`
| source (FloatTensor): the tensor containing values to accumulate
| reduce (str): the reduction operation to apply
| (:obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
|
| Keyword args:
| include_self (bool): whether the elements from the ``self`` tensor are
| included in the reduction
|
| Example::
|
| >>> x = torch.empty(5, 3).fill_(2)
| >>> t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float)
| >>> index = torch.tensor([0, 4, 2, 0])
| >>> x.index_reduce_(0, index, t, 'prod')
| tensor([[20., 44., 72.],
| [ 2., 2., 2.],
| [14., 16., 18.],
| [ 2., 2., 2.],
| [ 8., 10., 12.]])
| >>> x = torch.empty(5, 3).fill_(2)
| >>> x.index_reduce_(0, index, t, 'prod', include_self=False)
| tensor([[10., 22., 36.],
| [ 2., 2., 2.],
| [ 7., 8., 9.],
| [ 2., 2., 2.],
| [ 4., 5., 6.]])
|
| index_select(...)
| index_select(dim, index) -> Tensor
|
| See :func:`torch.index_select`
|
| indices(...)
| indices() -> Tensor
|
| Return the indices tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.values`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| inner(...)
| inner(other) -> Tensor
|
| See :func:`torch.inner`.
|
| int(...)
| int(memory_format=torch.preserve_format) -> Tensor
|
| ``self.int()`` is equivalent to ``self.to(torch.int32)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| int_repr(...)
| int_repr() -> Tensor
|
| Given a quantized Tensor,
| ``self.int_repr()`` returns a CPU Tensor with uint8_t as data type that stores the
| underlying uint8_t values of the given Tensor.
|
| inverse(...)
| inverse() -> Tensor
|
| See :func:`torch.inverse`
|
| ipu(...)
| ipu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in IPU memory.
|
| If this object is already in IPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination IPU device.
| Defaults to the current IPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| is_coalesced(...)
| is_coalesced() -> bool
|
| Returns ``True`` if :attr:`self` is a :ref:`sparse COO tensor
| <sparse-coo-docs>` that is coalesced, ``False`` otherwise.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See :meth:`coalesce` and :ref:`uncoalesced tensors <sparse-uncoalesced-coo-docs>`.
|
| is_complex(...)
| is_complex() -> bool
|
| Returns True if the data type of :attr:`self` is a complex data type.
|
| is_conj(...)
| is_conj() -> bool
|
| Returns True if the conjugate bit of :attr:`self` is set to true.
|
| is_contiguous(...)
| is_contiguous(memory_format=torch.contiguous_format) -> bool
|
| Returns True if :attr:`self` tensor is contiguous in memory in the order specified
| by memory format.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): Specifies memory allocation
| order. Default: ``torch.contiguous_format``.
|
| is_distributed(...)
|
| is_floating_point(...)
| is_floating_point() -> bool
|
| Returns True if the data type of :attr:`self` is a floating point data type.
|
| is_inference(...)
| is_inference() -> bool
|
| See :func:`torch.is_inference`
|
| is_neg(...)
| is_neg() -> bool
|
| Returns True if the negative bit of :attr:`self` is set to true.
|
| is_nonzero(...)
|
| is_pinned(...)
| Returns true if this tensor resides in pinned memory.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| is_same_size(...)
|
| is_set_to(...)
| is_set_to(tensor) -> bool
|
| Returns True if both tensors are pointing to the exact same memory (same
| storage, offset, size and stride).
|
| is_signed(...)
| is_signed() -> bool
|
| Returns True if the data type of :attr:`self` is a signed data type.
|
| isclose(...)
| isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
|
| See :func:`torch.isclose`
|
| isfinite(...)
| isfinite() -> Tensor
|
| See :func:`torch.isfinite`
|
| isinf(...)
| isinf() -> Tensor
|
| See :func:`torch.isinf`
|
| isnan(...)
| isnan() -> Tensor
|
| See :func:`torch.isnan`
|
| isneginf(...)
| isneginf() -> Tensor
|
| See :func:`torch.isneginf`
|
| isposinf(...)
| isposinf() -> Tensor
|
| See :func:`torch.isposinf`
|
| isreal(...)
| isreal() -> Tensor
|
| See :func:`torch.isreal`
|
| item(...)
| item() -> number
|
| Returns the value of this tensor as a standard Python number. This only works
| for tensors with one element. For other cases, see :meth:`~Tensor.tolist`.
|
| This operation is not differentiable.
|
| Example::
|
| >>> x = torch.tensor([1.0])
| >>> x.item()
| 1.0
|
| kron(...)
| kron(other) -> Tensor
|
| See :func:`torch.kron`
|
| kthvalue(...)
| kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.kthvalue`
|
| lcm(...)
| lcm(other) -> Tensor
|
| See :func:`torch.lcm`
|
| lcm_(...)
| lcm_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lcm`
|
| ldexp(...)
| ldexp(other) -> Tensor
|
| See :func:`torch.ldexp`
|
| ldexp_(...)
| ldexp_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ldexp`
|
| le(...)
| le(other) -> Tensor
|
| See :func:`torch.le`.
|
| le_(...)
| le_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.le`.
|
| lerp(...)
| lerp(end, weight) -> Tensor
|
| See :func:`torch.lerp`
|
| lerp_(...)
| lerp_(end, weight) -> Tensor
|
| In-place version of :meth:`~Tensor.lerp`
|
| less(...)
| lt(other) -> Tensor
|
| See :func:`torch.less`.
|
| less_(...)
| less_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less`.
|
| less_equal(...)
| less_equal(other) -> Tensor
|
| See :func:`torch.less_equal`.
|
| less_equal_(...)
| less_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.less_equal`.
|
| lgamma(...)
| lgamma() -> Tensor
|
| See :func:`torch.lgamma`
|
| lgamma_(...)
| lgamma_() -> Tensor
|
| In-place version of :meth:`~Tensor.lgamma`
|
| log(...)
| log() -> Tensor
|
| See :func:`torch.log`
|
| log10(...)
| log10() -> Tensor
|
| See :func:`torch.log10`
|
| log10_(...)
| log10_() -> Tensor
|
| In-place version of :meth:`~Tensor.log10`
|
| log1p(...)
| log1p() -> Tensor
|
| See :func:`torch.log1p`
|
| log1p_(...)
| log1p_() -> Tensor
|
| In-place version of :meth:`~Tensor.log1p`
|
| log2(...)
| log2() -> Tensor
|
| See :func:`torch.log2`
|
| log2_(...)
| log2_() -> Tensor
|
| In-place version of :meth:`~Tensor.log2`
|
| log_(...)
| log_() -> Tensor
|
| In-place version of :meth:`~Tensor.log`
|
| log_normal_(...)
| log_normal_(mean=1, std=2, *, generator=None)
|
| Fills :attr:`self` tensor with numbers samples from the log-normal distribution
| parameterized by the given mean :math:`\mu` and standard deviation
| :math:`\sigma`. Note that :attr:`mean` and :attr:`std` are the mean and
| standard deviation of the underlying normal distribution, and not of the
| returned distribution:
|
| .. math::
|
| f(x) = \dfrac{1}{x \sigma \sqrt{2\pi}}\ e^{-\frac{(\ln x - \mu)^2}{2\sigma^2}}
|
| log_softmax(...)
|
| logaddexp(...)
| logaddexp(other) -> Tensor
|
| See :func:`torch.logaddexp`
|
| logaddexp2(...)
| logaddexp2(other) -> Tensor
|
| See :func:`torch.logaddexp2`
|
| logcumsumexp(...)
| logcumsumexp(dim) -> Tensor
|
| See :func:`torch.logcumsumexp`
|
| logdet(...)
| logdet() -> Tensor
|
| See :func:`torch.logdet`
|
| logical_and(...)
| logical_and() -> Tensor
|
| See :func:`torch.logical_and`
|
| logical_and_(...)
| logical_and_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_and`
|
| logical_not(...)
| logical_not() -> Tensor
|
| See :func:`torch.logical_not`
|
| logical_not_(...)
| logical_not_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_not`
|
| logical_or(...)
| logical_or() -> Tensor
|
| See :func:`torch.logical_or`
|
| logical_or_(...)
| logical_or_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_or`
|
| logical_xor(...)
| logical_xor() -> Tensor
|
| See :func:`torch.logical_xor`
|
| logical_xor_(...)
| logical_xor_() -> Tensor
|
| In-place version of :meth:`~Tensor.logical_xor`
|
| logit(...)
| logit() -> Tensor
|
| See :func:`torch.logit`
|
| logit_(...)
| logit_() -> Tensor
|
| In-place version of :meth:`~Tensor.logit`
|
| logsumexp(...)
| logsumexp(dim, keepdim=False) -> Tensor
|
| See :func:`torch.logsumexp`
|
| long(...)
| long(memory_format=torch.preserve_format) -> Tensor
|
| ``self.long()`` is equivalent to ``self.to(torch.int64)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| lt(...)
| lt(other) -> Tensor
|
| See :func:`torch.lt`.
|
| lt_(...)
| lt_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.lt`.
|
| lu_solve(...)
| lu_solve(LU_data, LU_pivots) -> Tensor
|
| See :func:`torch.lu_solve`
|
| map2_(...)
|
| map_(...)
| map_(tensor, callable)
|
| Applies :attr:`callable` for each element in :attr:`self` tensor and the given
| :attr:`tensor` and stores the results in :attr:`self` tensor. :attr:`self` tensor and
| the given :attr:`tensor` must be :ref:`broadcastable <broadcasting-semantics>`.
|
| The :attr:`callable` should have the signature::
|
| def callable(a, b) -> number
|
| masked_fill(...)
| masked_fill(mask, value) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_fill_`
|
| masked_fill_(...)
| masked_fill_(mask, value)
|
| Fills elements of :attr:`self` tensor with :attr:`value` where :attr:`mask` is
| True. The shape of :attr:`mask` must be
| :ref:`broadcastable <broadcasting-semantics>` with the shape of the underlying
| tensor.
|
| Args:
| mask (BoolTensor): the boolean mask
| value (float): the value to fill in with
|
| masked_scatter(...)
| masked_scatter(mask, tensor) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
|
| .. note::
|
| The inputs :attr:`self` and :attr:`mask`
| :ref:`broadcast <broadcasting-semantics>`.
|
| Example:
|
| >>> self = torch.tensor([0, 0, 0, 0, 0])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_scatter_(...)
| masked_scatter_(mask, source)
|
| Copies elements from :attr:`source` into :attr:`self` tensor at positions where
| the :attr:`mask` is True. Elements from :attr:`source` are copied into :attr:`self`
| starting at position 0 of :attr:`source` and continuing in order one-by-one for each
| occurrence of :attr:`mask` being True.
| The shape of :attr:`mask` must be :ref:`broadcastable <broadcasting-semantics>`
| with the shape of the underlying tensor. The :attr:`source` should have at least
| as many elements as the number of ones in :attr:`mask`.
|
| Args:
| mask (BoolTensor): the boolean mask
| source (Tensor): the tensor to copy from
|
| .. note::
|
| The :attr:`mask` operates on the :attr:`self` tensor, not on the given
| :attr:`source` tensor.
|
| Example:
|
| >>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
| >>> mask = torch.tensor(
| ... [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]],
| ... dtype=torch.bool,
| ... )
| >>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
| >>> self.masked_scatter_(mask, source)
| tensor([[0, 0, 0, 0, 1],
| [2, 3, 0, 4, 5]])
|
| masked_select(...)
| masked_select(mask) -> Tensor
|
| See :func:`torch.masked_select`
|
| matmul(...)
| matmul(tensor2) -> Tensor
|
| See :func:`torch.matmul`
|
| matrix_exp(...)
| matrix_exp() -> Tensor
|
| See :func:`torch.matrix_exp`
|
| matrix_power(...)
| matrix_power(n) -> Tensor
|
| .. note:: :meth:`~Tensor.matrix_power` is deprecated, use :func:`torch.linalg.matrix_power` instead.
|
| Alias for :func:`torch.linalg.matrix_power`
|
| max(...)
| max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.max`
|
| maximum(...)
| maximum(other) -> Tensor
|
| See :func:`torch.maximum`
|
| mean(...)
| mean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.mean`
|
| median(...)
| median(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.median`
|
| min(...)
| min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)
|
| See :func:`torch.min`
|
| minimum(...)
| minimum(other) -> Tensor
|
| See :func:`torch.minimum`
|
| mm(...)
| mm(mat2) -> Tensor
|
| See :func:`torch.mm`
|
| mode(...)
| mode(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.mode`
|
| moveaxis(...)
| moveaxis(source, destination) -> Tensor
|
| See :func:`torch.moveaxis`
|
| movedim(...)
| movedim(source, destination) -> Tensor
|
| See :func:`torch.movedim`
|
| msort(...)
| msort() -> Tensor
|
| See :func:`torch.msort`
|
| mtia(...)
| mtia(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in MTIA memory.
|
| If this object is already in MTIA memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination MTIA device.
| Defaults to the current MTIA device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| mul(...)
| mul(value) -> Tensor
|
| See :func:`torch.mul`.
|
| mul_(...)
| mul_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.mul`.
|
| multinomial(...)
| multinomial(num_samples, replacement=False, *, generator=None) -> Tensor
|
| See :func:`torch.multinomial`
|
| multiply(...)
| multiply(value) -> Tensor
|
| See :func:`torch.multiply`.
|
| multiply_(...)
| multiply_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.multiply`.
|
| mv(...)
| mv(vec) -> Tensor
|
| See :func:`torch.mv`
|
| mvlgamma(...)
| mvlgamma(p) -> Tensor
|
| See :func:`torch.mvlgamma`
|
| mvlgamma_(...)
| mvlgamma_(p) -> Tensor
|
| In-place version of :meth:`~Tensor.mvlgamma`
|
| nan_to_num(...)
| nan_to_num(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| See :func:`torch.nan_to_num`.
|
| nan_to_num_(...)
| nan_to_num_(nan=0.0, posinf=None, neginf=None) -> Tensor
|
| In-place version of :meth:`~Tensor.nan_to_num`.
|
| nanmean(...)
| nanmean(dim=None, keepdim=False, *, dtype=None) -> Tensor
|
| See :func:`torch.nanmean`
|
| nanmedian(...)
| nanmedian(dim=None, keepdim=False) -> (Tensor, LongTensor)
|
| See :func:`torch.nanmedian`
|
| nanquantile(...)
| nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.nanquantile`
|
| nansum(...)
| nansum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.nansum`
|
| narrow(...)
| narrow(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow`.
|
| narrow_copy(...)
| narrow_copy(dimension, start, length) -> Tensor
|
| See :func:`torch.narrow_copy`.
|
| ndimension(...)
| ndimension() -> int
|
| Alias for :meth:`~Tensor.dim()`
|
| ne(...)
| ne(other) -> Tensor
|
| See :func:`torch.ne`.
|
| ne_(...)
| ne_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.ne`.
|
| neg(...)
| neg() -> Tensor
|
| See :func:`torch.neg`
|
| neg_(...)
| neg_() -> Tensor
|
| In-place version of :meth:`~Tensor.neg`
|
| negative(...)
| negative() -> Tensor
|
| See :func:`torch.negative`
|
| negative_(...)
| negative_() -> Tensor
|
| In-place version of :meth:`~Tensor.negative`
|
| nelement(...)
| nelement() -> int
|
| Alias for :meth:`~Tensor.numel`
|
| new(...)
|
| new_empty(...)
| new_empty(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with uninitialized data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty((2, 3))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_empty_strided(...)
| new_empty_strided(size, stride, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` and strides :attr:`stride` filled with
| uninitialized data. By default, the returned Tensor has the same
| :class:`torch.dtype` and :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones(())
| >>> tensor.new_empty_strided((2, 3), (3, 1))
| tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30],
| [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])
|
| new_full(...)
| new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with :attr:`fill_value`.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| fill_value (scalar): the number to fill the output tensor with.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.float64)
| >>> tensor.new_full((3, 4), 3.141592)
| tensor([[ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416],
| [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)
|
| new_ones(...)
| new_ones(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``1``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.int32)
| >>> tensor.new_ones((2, 3))
| tensor([[ 1, 1, 1],
| [ 1, 1, 1]], dtype=torch.int32)
|
| new_tensor(...)
| new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a new Tensor with :attr:`data` as the tensor data.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| .. warning::
|
| :func:`new_tensor` always copies :attr:`data`. If you have a Tensor
| ``data`` and want to avoid a copy, use :func:`torch.Tensor.requires_grad_`
| or :func:`torch.Tensor.detach`.
| If you have a numpy array and want to avoid a copy, use
| :func:`torch.from_numpy`.
|
| .. warning::
|
| When data is a tensor `x`, :func:`new_tensor()` reads out 'the data' from whatever it is passed,
| and constructs a leaf variable. Therefore ``tensor.new_tensor(x)`` is equivalent to ``x.detach().clone()``
| and ``tensor.new_tensor(x, requires_grad=True)`` is equivalent to ``x.detach().clone().requires_grad_(True)``.
| The equivalents using ``detach()`` and ``clone()`` are recommended.
|
| Args:
| data (array_like): The returned Tensor copies :attr:`data`.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.ones((2,), dtype=torch.int8)
| >>> data = [[0, 1], [2, 3]]
| >>> tensor.new_tensor(data)
| tensor([[ 0, 1],
| [ 2, 3]], dtype=torch.int8)
|
| new_zeros(...)
| new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) -> Tensor
|
|
| Returns a Tensor of size :attr:`size` filled with ``0``.
| By default, the returned Tensor has the same :class:`torch.dtype` and
| :class:`torch.device` as this tensor.
|
| Args:
| size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
| shape of the output tensor.
|
| Keyword args:
| dtype (:class:`torch.dtype`, optional): the desired type of returned tensor.
| Default: if None, same :class:`torch.dtype` as this tensor.
| device (:class:`torch.device`, optional): the desired device of returned tensor.
| Default: if None, same :class:`torch.device` as this tensor.
| requires_grad (bool, optional): If autograd should record operations on the
| returned tensor. Default: ``False``.
| layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
| Default: ``torch.strided``.
| pin_memory (bool, optional): If set, returned tensor would be allocated in
| the pinned memory. Works only for CPU tensors. Default: ``False``.
|
| Example::
|
| >>> tensor = torch.tensor((), dtype=torch.float64)
| >>> tensor.new_zeros((2, 3))
| tensor([[ 0., 0., 0.],
| [ 0., 0., 0.]], dtype=torch.float64)
|
| nextafter(...)
| nextafter(other) -> Tensor
| See :func:`torch.nextafter`
|
| nextafter_(...)
| nextafter_(other) -> Tensor
| In-place version of :meth:`~Tensor.nextafter`
|
| nonzero(...)
| nonzero() -> LongTensor
|
| See :func:`torch.nonzero`
|
| nonzero_static(...)
| nonzero_static(*, size, fill_value=-1) -> LongTensor
|
| See :func:`torch.nonzero_static`
|
| normal_(...)
| normal_(mean=0, std=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with elements samples from the normal distribution
| parameterized by :attr:`mean` and :attr:`std`.
|
| not_equal(...)
| not_equal(other) -> Tensor
|
| See :func:`torch.not_equal`.
|
| not_equal_(...)
| not_equal_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.not_equal`.
|
| numel(...)
| numel() -> int
|
| See :func:`torch.numel`
|
| numpy(...)
| numpy(*, force=False) -> numpy.ndarray
|
| Returns the tensor as a NumPy :class:`ndarray`.
|
| If :attr:`force` is ``False`` (the default), the conversion
| is performed only if the tensor is on the CPU, does not require grad,
| does not have its conjugate bit set, and is a dtype and layout that
| NumPy supports. The returned ndarray and the tensor will share their
| storage, so changes to the tensor will be reflected in the ndarray
| and vice versa.
|
| If :attr:`force` is ``True`` this is equivalent to
| calling ``t.detach().cpu().resolve_conj().resolve_neg().numpy()``.
| If the tensor isn't on the CPU or the conjugate or negative bit is set,
| the tensor won't share its storage with the returned ndarray.
| Setting :attr:`force` to ``True`` can be a useful shorthand.
|
| Args:
| force (bool): if ``True``, the ndarray may be a copy of the tensor
| instead of always sharing memory, defaults to ``False``.
|
| orgqr(...)
| orgqr(input2) -> Tensor
|
| See :func:`torch.orgqr`
|
| ormqr(...)
| ormqr(input2, input3, left=True, transpose=False) -> Tensor
|
| See :func:`torch.ormqr`
|
| outer(...)
| outer(vec2) -> Tensor
|
| See :func:`torch.outer`.
|
| permute(...)
| permute(*dims) -> Tensor
|
| Returns a view of the tensor with its dimensions permuted.
|
| Args:
| dims (torch.Size, int..., tuple of int or list of int): the desired ordering of dimensions.
|
| Example:
| >>> x = torch.randn(2, 3, 5)
| >>> x.size()
| torch.Size([2, 3, 5])
| >>> x.permute(2, 0, 1).size()
| torch.Size([5, 2, 3])
|
| pin_memory(...)
| pin_memory() -> Tensor
|
| Copies the tensor to pinned memory, if it's not already pinned.
| By default, the device pinned memory on will be the current :ref:`accelerator<accelerators>`.
|
| pinverse(...)
| pinverse() -> Tensor
|
| See :func:`torch.pinverse`
|
| polygamma(...)
| polygamma(n) -> Tensor
|
| See :func:`torch.polygamma`
|
| polygamma_(...)
| polygamma_(n) -> Tensor
|
| In-place version of :meth:`~Tensor.polygamma`
|
| positive(...)
| positive() -> Tensor
|
| See :func:`torch.positive`
|
| pow(...)
| pow(exponent) -> Tensor
|
| See :func:`torch.pow`
|
| pow_(...)
| pow_(exponent) -> Tensor
|
| In-place version of :meth:`~Tensor.pow`
|
| prelu(...)
|
| prod(...)
| prod(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.prod`
|
| put(...)
| put(input, index, source, accumulate=False) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.put_`.
| `input` corresponds to `self` in :meth:`torch.Tensor.put_`.
|
| put_(...)
| put_(index, source, accumulate=False) -> Tensor
|
| Copies the elements from :attr:`source` into the positions specified by
| :attr:`index`. For the purpose of indexing, the :attr:`self` tensor is treated as if
| it were a 1-D tensor.
|
| :attr:`index` and :attr:`source` need to have the same number of elements, but not necessarily
| the same shape.
|
| If :attr:`accumulate` is ``True``, the elements in :attr:`source` are added to
| :attr:`self`. If accumulate is ``False``, the behavior is undefined if :attr:`index`
| contain duplicate elements.
|
| Args:
| index (LongTensor): the indices into self
| source (Tensor): the tensor containing values to copy from
| accumulate (bool, optional): whether to accumulate into self. Default: ``False``
|
| Example::
|
| >>> src = torch.tensor([[4, 3, 5],
| ... [6, 7, 8]])
| >>> src.put_(torch.tensor([1, 3]), torch.tensor([9, 10]))
| tensor([[ 4, 9, 5],
| [ 10, 7, 8]])
|
| q_per_channel_axis(...)
| q_per_channel_axis() -> int
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns the index of dimension on which per-channel quantization is applied.
|
| q_per_channel_scales(...)
| q_per_channel_scales() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a Tensor of scales of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_per_channel_zero_points(...)
| q_per_channel_zero_points() -> Tensor
|
| Given a Tensor quantized by linear (affine) per-channel quantization,
| returns a tensor of zero_points of the underlying quantizer. It has the number of
| elements that matches the corresponding dimensions (from q_per_channel_axis) of
| the tensor.
|
| q_scale(...)
| q_scale() -> float
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the scale of the underlying quantizer().
|
| q_zero_point(...)
| q_zero_point() -> int
|
| Given a Tensor quantized by linear(affine) quantization,
| returns the zero_point of the underlying quantizer().
|
| qr(...)
| qr(some=True) -> (Tensor, Tensor)
|
| See :func:`torch.qr`
|
| qscheme(...)
| qscheme() -> torch.qscheme
|
| Returns the quantization scheme of a given QTensor.
|
| quantile(...)
| quantile(q, dim=None, keepdim=False, *, interpolation='linear') -> Tensor
|
| See :func:`torch.quantile`
|
| rad2deg(...)
| rad2deg() -> Tensor
|
| See :func:`torch.rad2deg`
|
| rad2deg_(...)
| rad2deg_() -> Tensor
|
| In-place version of :meth:`~Tensor.rad2deg`
|
| random_(...)
| random_(from=0, to=None, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the discrete uniform
| distribution over ``[from, to - 1]``. If not specified, the values are usually
| only bounded by :attr:`self` tensor's data type. However, for floating point
| types, if unspecified, range will be ``[0, 2^mantissa]`` to ensure that every
| value is representable. For example, `torch.tensor(1, dtype=torch.double).random_()`
| will be uniform in ``[0, 2^53]``.
|
| ravel(...)
| ravel() -> Tensor
|
| see :func:`torch.ravel`
|
| reciprocal(...)
| reciprocal() -> Tensor
|
| See :func:`torch.reciprocal`
|
| reciprocal_(...)
| reciprocal_() -> Tensor
|
| In-place version of :meth:`~Tensor.reciprocal`
|
| record_stream(...)
| record_stream(stream)
|
| Marks the tensor as having been used by this stream. When the tensor
| is deallocated, ensure the tensor memory is not reused for another tensor
| until all work queued on :attr:`stream` at the time of deallocation is
| complete.
|
| .. note::
|
| The caching allocator is aware of only the stream where a tensor was
| allocated. Due to the awareness, it already correctly manages the life
| cycle of tensors on only one stream. But if a tensor is used on a stream
| different from the stream of origin, the allocator might reuse the memory
| unexpectedly. Calling this method lets the allocator know which streams
| have used the tensor.
|
| .. warning::
|
| This method is most suitable for use cases where you are providing a
| function that created a tensor on a side stream, and want users to be able
| to make use of the tensor without having to think carefully about stream
| safety when making use of them. These safety guarantees come at some
| performance and predictability cost (analogous to the tradeoff between GC
| and manual memory management), so if you are in a situation where
| you manage the full lifetime of your tensors, you may consider instead
| manually managing CUDA events so that calling this method is not necessary.
| In particular, when you call this method, on later allocations the
| allocator will poll the recorded stream to see if all operations have
| completed yet; you can potentially race with side stream computation and
| non-deterministically reuse or fail to reuse memory for an allocation.
|
| You can safely use tensors allocated on side streams without
| :meth:`~Tensor.record_stream`; you must manually ensure that
| any non-creation stream uses of a tensor are synced back to the creation
| stream before you deallocate the tensor. As the CUDA caching allocator
| guarantees that the memory will only be reused with the same creation stream,
| this is sufficient to ensure that writes to future reallocations of the
| memory will be delayed until non-creation stream uses are done.
| (Counterintuitively, you may observe that on the CPU side we have already
| reallocated the tensor, even though CUDA kernels on the old tensor are
| still in progress. This is fine, because CUDA operations on the new
| tensor will appropriately wait for the old operations to complete, as they
| are all on the same stream.)
|
| Concretely, this looks like this::
|
| with torch.cuda.stream(s0):
| x = torch.zeros(N)
|
| s1.wait_stream(s0)
| with torch.cuda.stream(s1):
| y = some_comm_op(x)
|
| ... some compute on s0 ...
|
| # synchronize creation stream s0 to side stream s1
| # before deallocating x
| s0.wait_stream(s1)
| del x
|
| Note that some discretion is required when deciding when to perform
| ``s0.wait_stream(s1)``. In particular, if we were to wait immediately
| after ``some_comm_op``, there wouldn't be any point in having the side
| stream; it would be equivalent to have run ``some_comm_op`` on ``s0``.
| Instead, the synchronization must be placed at some appropriate, later
| point in time where you expect the side stream ``s1`` to have finished
| work. This location is typically identified via profiling, e.g., using
| Chrome traces produced
| :meth:`torch.autograd.profiler.profile.export_chrome_trace`. If you
| place the wait too early, work on s0 will block until ``s1`` has finished,
| preventing further overlapping of communication and computation. If you
| place the wait too late, you will use more memory than is strictly
| necessary (as you are keeping ``x`` live for longer.) For a concrete
| example of how this guidance can be applied in practice, see this post:
| `FSDP and CUDACachingAllocator
| <https://dev-discuss.pytorch.org/t/fsdp-cudacachingallocator-an-outsider-newb-perspective/1486>`_.
|
| relu(...)
|
| relu_(...)
|
| remainder(...)
| remainder(divisor) -> Tensor
|
| See :func:`torch.remainder`
|
| remainder_(...)
| remainder_(divisor) -> Tensor
|
| In-place version of :meth:`~Tensor.remainder`
|
| renorm(...)
| renorm(p, dim, maxnorm) -> Tensor
|
| See :func:`torch.renorm`
|
| renorm_(...)
| renorm_(p, dim, maxnorm) -> Tensor
|
| In-place version of :meth:`~Tensor.renorm`
|
| repeat(...)
| repeat(*repeats) -> Tensor
|
| Repeats this tensor along the specified dimensions.
|
| Unlike :meth:`~Tensor.expand`, this function copies the tensor's data.
|
| .. warning::
|
| :meth:`~Tensor.repeat` behaves differently from
| `numpy.repeat <https://numpy.org/doc/stable/reference/generated/numpy.repeat.html>`_,
| but is more similar to
| `numpy.tile <https://numpy.org/doc/stable/reference/generated/numpy.tile.html>`_.
| For the operator similar to `numpy.repeat`, see :func:`torch.repeat_interleave`.
|
| Args:
| repeat (torch.Size, int..., tuple of int or list of int): The number of times to repeat this tensor along each dimension
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3])
| >>> x.repeat(4, 2)
| tensor([[ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3],
| [ 1, 2, 3, 1, 2, 3]])
| >>> x.repeat(4, 2, 1).size()
| torch.Size([4, 2, 3])
|
| repeat_interleave(...)
| repeat_interleave(repeats, dim=None, *, output_size=None) -> Tensor
|
| See :func:`torch.repeat_interleave`.
|
| requires_grad_(...)
| requires_grad_(requires_grad=True) -> Tensor
|
| Change if autograd should record operations on this tensor: sets this tensor's
| :attr:`requires_grad` attribute in-place. Returns this tensor.
|
| :func:`requires_grad_`'s main use case is to tell autograd to begin recording
| operations on a Tensor ``tensor``. If ``tensor`` has ``requires_grad=False``
| (because it was obtained through a DataLoader, or required preprocessing or
| initialization), ``tensor.requires_grad_()`` makes it so that autograd will
| begin to record operations on ``tensor``.
|
| Args:
| requires_grad (bool): If autograd should record operations on this tensor.
| Default: ``True``.
|
| Example::
|
| >>> # Let's say we want to preprocess some saved weights and use
| >>> # the result as new weights.
| >>> saved_weights = [0.1, 0.2, 0.3, 0.25]
| >>> loaded_weights = torch.tensor(saved_weights)
| >>> weights = preprocess(loaded_weights) # some function
| >>> weights
| tensor([-0.5503, 0.4926, -2.1158, -0.8303])
|
| >>> # Now, start to record operations done to weights
| >>> weights.requires_grad_()
| >>> out = weights.pow(2).sum()
| >>> out.backward()
| >>> weights.grad
| tensor([-1.1007, 0.9853, -4.2316, -1.6606])
|
| reshape(...)
| reshape(*shape) -> Tensor
|
| Returns a tensor with the same data and number of elements as :attr:`self`
| but with the specified shape. This method returns a view if :attr:`shape` is
| compatible with the current shape. See :meth:`torch.Tensor.view` on when it is
| possible to return a view.
|
| See :func:`torch.reshape`
|
| Args:
| shape (tuple of ints or int...): the desired shape
|
| reshape_as(...)
| reshape_as(other) -> Tensor
|
| Returns this tensor as the same shape as :attr:`other`.
| ``self.reshape_as(other)`` is equivalent to ``self.reshape(other.sizes())``.
| This method returns a view if ``other.sizes()`` is compatible with the current
| shape. See :meth:`torch.Tensor.view` on when it is possible to return a view.
|
| Please see :meth:`reshape` for more information about ``reshape``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same shape
| as :attr:`other`.
|
| resize_(...)
| resize_(*sizes, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes :attr:`self` tensor to the specified size. If the number of elements is
| larger than the current storage size, then the underlying storage is resized
| to fit the new number of elements. If the number of elements is smaller, the
| underlying storage is not changed. Existing elements are preserved but any new
| memory is uninitialized.
|
| .. warning::
|
| This is a low-level method. The storage is reinterpreted as C-contiguous,
| ignoring the current strides (unless the target size equals the current
| size, in which case the tensor is left unchanged). For most purposes, you
| will instead want to use :meth:`~Tensor.view()`, which checks for
| contiguity, or :meth:`~Tensor.reshape()`, which copies data if needed. To
| change the size in-place with custom strides, see :meth:`~Tensor.set_()`.
|
| .. note::
|
| If :func:`torch.use_deterministic_algorithms()` and
| :attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
| ``True``, new elements are initialized to prevent nondeterministic behavior
| from using the result as an input to an operation. Floating point and
| complex values are set to NaN, and integer values are set to the maximum
| value.
|
| Args:
| sizes (torch.Size or int...): the desired size
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``sizes``.
|
| Example::
|
| >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]])
| >>> x.resize_(2, 2)
| tensor([[ 1, 2],
| [ 3, 4]])
|
| resize_as_(...)
| resize_as_(tensor, memory_format=torch.contiguous_format) -> Tensor
|
| Resizes the :attr:`self` tensor to be the same size as the specified
| :attr:`tensor`. This is equivalent to ``self.resize_(tensor.size())``.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| Tensor. Default: ``torch.contiguous_format``. Note that memory format of
| :attr:`self` is going to be unaffected if ``self.size()`` matches ``tensor.size()``.
|
| resize_as_sparse_(...)
|
| resolve_conj(...)
| resolve_conj() -> Tensor
|
| See :func:`torch.resolve_conj`
|
| resolve_neg(...)
| resolve_neg() -> Tensor
|
| See :func:`torch.resolve_neg`
|
| retain_grad(...)
| retain_grad() -> None
|
| Enables this Tensor to have their :attr:`grad` populated during
| :func:`backward`. This is a no-op for leaf tensors.
|
| roll(...)
| roll(shifts, dims) -> Tensor
|
| See :func:`torch.roll`
|
| rot90(...)
| rot90(k, dims) -> Tensor
|
| See :func:`torch.rot90`
|
| round(...)
| round(decimals=0) -> Tensor
|
| See :func:`torch.round`
|
| round_(...)
| round_(decimals=0) -> Tensor
|
| In-place version of :meth:`~Tensor.round`
|
| row_indices(...)
|
| rsqrt(...)
| rsqrt() -> Tensor
|
| See :func:`torch.rsqrt`
|
| rsqrt_(...)
| rsqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.rsqrt`
|
| scatter(...)
| scatter(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_`
|
| scatter_(...)
| scatter_(dim, index, src, *, reduce=None) -> Tensor
|
| Writes all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. For each value in :attr:`src`, its output
| index is specified by its index in :attr:`src` for ``dimension != dim`` and by
| the corresponding value in :attr:`index` for ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] = src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] = src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2
|
| This is the reverse operation of the manner described in :meth:`~Tensor.gather`.
|
| It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``input`` and ``index`` do not broadcast against each other for NPUs,
| so when running on NPUs, :attr:`input` and :attr:`index` must have the same number of dimensions.
| Standard broadcasting occurs in all other cases.
|
| Moreover, as for :meth:`~Tensor.gather`, the values of :attr:`index` must be
| between ``0`` and ``self.size(dim) - 1`` inclusive.
|
| .. warning::
|
| When indices are not unique, the behavior is non-deterministic (one of the
| values from ``src`` will be picked arbitrarily) and the gradient will be
| incorrect (it will be propagated to all locations in the source that
| correspond to the same index)!
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Additionally accepts an optional :attr:`reduce` argument that allows
| specification of an optional reduction operation, which is applied to all
| values in the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index`. For each value in :attr:`src`, the reduction
| operation is applied to an index in :attr:`self` which is specified by
| its index in :attr:`src` for ``dimension != dim`` and by the corresponding
| value in :attr:`index` for ``dimension = dim``.
|
| Given a 3-D tensor and reduction using the multiplication operation, :attr:`self`
| is updated as::
|
| self[index[i][j][k]][j][k] *= src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] *= src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] *= src[i][j][k] # if dim == 2
|
| Reducing with the addition operation is the same as using
| :meth:`~torch.Tensor.scatter_add_`.
|
| .. warning::
| The reduce argument with Tensor ``src`` is deprecated and will be removed in
| a future PyTorch release. Please use :meth:`~torch.Tensor.scatter_reduce_`
| instead for more reduction options.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| src (Tensor): the source element(s) to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> src = torch.arange(1, 11).reshape((2, 5))
| >>> src
| tensor([[ 1, 2, 3, 4, 5],
| [ 6, 7, 8, 9, 10]])
| >>> index = torch.tensor([[0, 1, 2, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(0, index, src)
| tensor([[1, 0, 0, 4, 0],
| [0, 2, 0, 0, 0],
| [0, 0, 3, 0, 0]])
| >>> index = torch.tensor([[0, 1, 2], [0, 1, 4]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_(1, index, src)
| tensor([[1, 2, 3, 0, 0],
| [6, 7, 0, 0, 8],
| [0, 0, 0, 0, 0]])
|
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='multiply')
| tensor([[2.0000, 2.0000, 2.4600, 2.0000],
| [2.0000, 2.0000, 2.0000, 2.4600]])
| >>> torch.full((2, 4), 2.).scatter_(1, torch.tensor([[2], [3]]),
| ... 1.23, reduce='add')
| tensor([[2.0000, 2.0000, 3.2300, 2.0000],
| [2.0000, 2.0000, 2.0000, 3.2300]])
|
| .. function:: scatter_(dim, index, value, *, reduce=None) -> Tensor:
| :noindex:
|
| Writes the value from :attr:`value` into :attr:`self` at the indices
| specified in the :attr:`index` tensor. This operation is equivalent to the previous version,
| with the :attr:`src` tensor filled entirely with :attr:`value`.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter, can be either empty
| or of the same dimensionality as ``src``. When empty, the operation
| returns ``self`` unchanged.
| value (Scalar): the value to scatter.
|
| Keyword args:
| reduce (str, optional): reduction operation to apply, can be either
| ``'add'`` or ``'multiply'``.
|
| Example::
|
| >>> index = torch.tensor([[0, 1]])
| >>> value = 2
| >>> torch.zeros(3, 5).scatter_(0, index, value)
| tensor([[2., 0., 0., 0., 0.],
| [0., 2., 0., 0., 0.],
| [0., 0., 0., 0., 0.]])
|
| scatter_add(...)
| scatter_add(dim, index, src) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_add_`
|
| scatter_add_(...)
| scatter_add_(dim, index, src) -> Tensor
|
| Adds all values from the tensor :attr:`src` into :attr:`self` at the indices
| specified in the :attr:`index` tensor in a similar fashion as
| :meth:`~torch.Tensor.scatter_`. For each value in :attr:`src`, it is added to
| an index in :attr:`self` which is specified by its index in :attr:`src`
| for ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``.
|
| For a 3-D tensor, :attr:`self` is updated as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| :attr:`self`, :attr:`index` and :attr:`src` should have same number of
| dimensions. It is also required that ``index.size(d) <= src.size(d)`` for all
| dimensions ``d``, and that ``index.size(d) <= self.size(d)`` for all dimensions
| ``d != dim``. Note that ``index`` and ``src`` do not broadcast.
| When :attr:`index` is empty, we always return the original tensor
| without further error checking.
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and add, can be
| either empty or of the same dimensionality as ``src``. When empty, the
| operation returns ``self`` unchanged.
| src (Tensor): the source elements to scatter and add
|
| Example::
|
| >>> src = torch.ones((2, 5))
| >>> index = torch.tensor([[0, 1, 2, 0, 0]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[1., 0., 0., 1., 1.],
| [0., 1., 0., 0., 0.],
| [0., 0., 1., 0., 0.]])
| >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
| >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
| tensor([[2., 0., 0., 1., 1.],
| [0., 2., 0., 0., 0.],
| [0., 0., 2., 1., 1.]])
|
| scatter_reduce(...)
| scatter_reduce(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
|
| scatter_reduce_(...)
| scatter_reduce_(dim, index, src, reduce, *, include_self=True) -> Tensor
|
| Reduces all values from the :attr:`src` tensor to the indices specified in
| the :attr:`index` tensor in the :attr:`self` tensor using the applied reduction
| defined via the :attr:`reduce` argument (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`,
| :obj:`"amax"`, :obj:`"amin"`). For each value in :attr:`src`, it is reduced to an
| index in :attr:`self` which is specified by its index in :attr:`src` for
| ``dimension != dim`` and by the corresponding value in :attr:`index` for
| ``dimension = dim``. If :obj:`include_self="True"`, the values in the :attr:`self`
| tensor are included in the reduction.
|
| :attr:`self`, :attr:`index` and :attr:`src` should all have
| the same number of dimensions. It is also required that
| ``index.size(d) <= src.size(d)`` for all dimensions ``d``, and that
| ``index.size(d) <= self.size(d)`` for all dimensions ``d != dim``.
| Note that ``index`` and ``src`` do not broadcast.
|
| For a 3-D tensor with :obj:`reduce="sum"` and :obj:`include_self=True` the
| output is given as::
|
| self[index[i][j][k]][j][k] += src[i][j][k] # if dim == 0
| self[i][index[i][j][k]][k] += src[i][j][k] # if dim == 1
| self[i][j][index[i][j][k]] += src[i][j][k] # if dim == 2
|
| Note:
| This operation may behave nondeterministically when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
|
| .. note::
|
| The backward pass is implemented only for ``src.shape == index.shape``.
|
| .. warning::
|
| This function is in beta and may change in the near future.
|
| Args:
| dim (int): the axis along which to index
| index (LongTensor): the indices of elements to scatter and reduce.
| src (Tensor): the source elements to scatter and reduce
| reduce (str): the reduction operation to apply for non-unique indices
| (:obj:`"sum"`, :obj:`"prod"`, :obj:`"mean"`, :obj:`"amax"`, :obj:`"amin"`)
| include_self (bool): whether elements from the :attr:`self` tensor are
| included in the reduction
|
| Example::
|
| >>> src = torch.tensor([1., 2., 3., 4., 5., 6.])
| >>> index = torch.tensor([0, 1, 0, 1, 2, 1])
| >>> input = torch.tensor([1., 2., 3., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum")
| tensor([5., 14., 8., 4.])
| >>> input.scatter_reduce(0, index, src, reduce="sum", include_self=False)
| tensor([4., 12., 5., 4.])
| >>> input2 = torch.tensor([5., 4., 3., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax")
| tensor([5., 6., 5., 2.])
| >>> input2.scatter_reduce(0, index, src, reduce="amax", include_self=False)
| tensor([3., 6., 5., 2.])
|
| select(...)
| select(dim, index) -> Tensor
|
| See :func:`torch.select`
|
| select_scatter(...)
| select_scatter(src, dim, index) -> Tensor
|
| See :func:`torch.select_scatter`
|
| set_(...)
| set_(source=None, storage_offset=0, size=None, stride=None) -> Tensor
|
| Sets the underlying storage, size, and strides. If :attr:`source` is a tensor,
| :attr:`self` tensor will share the same storage and have the same size and
| strides as :attr:`source`. Changes to elements in one tensor will be reflected
| in the other.
|
| If :attr:`source` is a :class:`~torch.Storage`, the method sets the underlying
| storage, offset, size, and stride.
|
| Args:
| source (Tensor or Storage): the tensor or storage to use
| storage_offset (int, optional): the offset in the storage
| size (torch.Size, optional): the desired size. Defaults to the size of the source.
| stride (tuple, optional): the desired stride. Defaults to C-contiguous strides.
|
| sgn(...)
| sgn() -> Tensor
|
| See :func:`torch.sgn`
|
| sgn_(...)
| sgn_() -> Tensor
|
| In-place version of :meth:`~Tensor.sgn`
|
| short(...)
| short(memory_format=torch.preserve_format) -> Tensor
|
| ``self.short()`` is equivalent to ``self.to(torch.int16)``. See :func:`to`.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| sigmoid(...)
| sigmoid() -> Tensor
|
| See :func:`torch.sigmoid`
|
| sigmoid_(...)
| sigmoid_() -> Tensor
|
| In-place version of :meth:`~Tensor.sigmoid`
|
| sign(...)
| sign() -> Tensor
|
| See :func:`torch.sign`
|
| sign_(...)
| sign_() -> Tensor
|
| In-place version of :meth:`~Tensor.sign`
|
| signbit(...)
| signbit() -> Tensor
|
| See :func:`torch.signbit`
|
| sin(...)
| sin() -> Tensor
|
| See :func:`torch.sin`
|
| sin_(...)
| sin_() -> Tensor
|
| In-place version of :meth:`~Tensor.sin`
|
| sinc(...)
| sinc() -> Tensor
|
| See :func:`torch.sinc`
|
| sinc_(...)
| sinc_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinc`
|
| sinh(...)
| sinh() -> Tensor
|
| See :func:`torch.sinh`
|
| sinh_(...)
| sinh_() -> Tensor
|
| In-place version of :meth:`~Tensor.sinh`
|
| size(...)
| size(dim=None) -> torch.Size or int
|
| Returns the size of the :attr:`self` tensor. If ``dim`` is not specified,
| the returned value is a :class:`torch.Size`, a subclass of :class:`tuple`.
| If ``dim`` is specified, returns an int holding the size of that dimension.
|
| Args:
| dim (int, optional): The dimension for which to retrieve the size.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.size(dim=1)
| 4
|
| slice_inverse(...)
|
| slice_scatter(...)
| slice_scatter(src, dim=0, start=None, end=None, step=1) -> Tensor
|
| See :func:`torch.slice_scatter`
|
| slogdet(...)
| slogdet() -> (Tensor, Tensor)
|
| See :func:`torch.slogdet`
|
| smm(...)
| smm(mat) -> Tensor
|
| See :func:`torch.smm`
|
| softmax(...)
| softmax(dim) -> Tensor
|
| Alias for :func:`torch.nn.functional.softmax`.
|
| sort(...)
| sort(dim=-1, descending=False) -> (Tensor, LongTensor)
|
| See :func:`torch.sort`
|
| sparse_dim(...)
| sparse_dim() -> int
|
| Return the number of sparse dimensions in a :ref:`sparse tensor <sparse-docs>` :attr:`self`.
|
| .. note::
| Returns ``0`` if :attr:`self` is not a sparse tensor.
|
| See also :meth:`Tensor.dense_dim` and :ref:`hybrid tensors <sparse-hybrid-coo-docs>`.
|
| sparse_mask(...)
| sparse_mask(mask) -> Tensor
|
| Returns a new :ref:`sparse tensor <sparse-docs>` with values from a
| strided tensor :attr:`self` filtered by the indices of the sparse
| tensor :attr:`mask`. The values of :attr:`mask` sparse tensor are
| ignored. :attr:`self` and :attr:`mask` tensors must have the same
| shape.
|
| .. note::
|
| The returned sparse tensor might contain duplicate values if :attr:`mask`
| is not coalesced. It is therefore advisable to pass ``mask.coalesce()``
| if such behavior is not desired.
|
| .. note::
|
| The returned sparse tensor has the same indices as the sparse tensor
| :attr:`mask`, even when the corresponding values in :attr:`self` are
| zeros.
|
| Args:
| mask (Tensor): a sparse tensor whose indices are used as a filter
|
| Example::
|
| >>> nse = 5
| >>> dims = (5, 5, 2, 2)
| >>> I = torch.cat([torch.randint(0, dims[0], size=(nse,)),
| ... torch.randint(0, dims[1], size=(nse,))], 0).reshape(2, nse)
| >>> V = torch.randn(nse, dims[2], dims[3])
| >>> S = torch.sparse_coo_tensor(I, V, dims).coalesce()
| >>> D = torch.randn(dims)
| >>> D.sparse_mask(S)
| tensor(indices=tensor([[0, 0, 0, 2],
| [0, 1, 4, 3]]),
| values=tensor([[[ 1.6550, 0.2397],
| [-0.1611, -0.0779]],
|
| [[ 0.2326, -1.0558],
| [ 1.4711, 1.9678]],
|
| [[-0.5138, -0.0411],
| [ 1.9417, 0.5158]],
|
| [[ 0.0793, 0.0036],
| [-0.2569, -0.1055]]]),
| size=(5, 5, 2, 2), nnz=4, layout=torch.sparse_coo)
|
| sparse_resize_(...)
| sparse_resize_(size, sparse_dim, dense_dim) -> Tensor
|
| Resizes :attr:`self` :ref:`sparse tensor <sparse-docs>` to the desired
| size and the number of sparse and dense dimensions.
|
| .. note::
| If the number of specified elements in :attr:`self` is zero, then
| :attr:`size`, :attr:`sparse_dim`, and :attr:`dense_dim` can be any
| size and positive integers such that ``len(size) == sparse_dim +
| dense_dim``.
|
| If :attr:`self` specifies one or more elements, however, then each
| dimension in :attr:`size` must not be smaller than the corresponding
| dimension of :attr:`self`, :attr:`sparse_dim` must equal the number
| of sparse dimensions in :attr:`self`, and :attr:`dense_dim` must
| equal the number of dense dimensions in :attr:`self`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size. If :attr:`self` is non-empty
| sparse tensor, the desired size cannot be smaller than the
| original size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| sparse_resize_and_clear_(...)
| sparse_resize_and_clear_(size, sparse_dim, dense_dim) -> Tensor
|
| Removes all specified elements from a :ref:`sparse tensor
| <sparse-docs>` :attr:`self` and resizes :attr:`self` to the desired
| size and the number of sparse and dense dimensions.
|
| .. warning:
| Throws an error if :attr:`self` is not a sparse tensor.
|
| Args:
| size (torch.Size): the desired size.
| sparse_dim (int): the number of sparse dimensions
| dense_dim (int): the number of dense dimensions
|
| split_with_sizes(...)
|
| sqrt(...)
| sqrt() -> Tensor
|
| See :func:`torch.sqrt`
|
| sqrt_(...)
| sqrt_() -> Tensor
|
| In-place version of :meth:`~Tensor.sqrt`
|
| square(...)
| square() -> Tensor
|
| See :func:`torch.square`
|
| square_(...)
| square_() -> Tensor
|
| In-place version of :meth:`~Tensor.square`
|
| squeeze(...)
| squeeze(dim=None) -> Tensor
|
| See :func:`torch.squeeze`
|
| squeeze_(...)
| squeeze_(dim=None) -> Tensor
|
| In-place version of :meth:`~Tensor.squeeze`
|
| sspaddmm(...)
| sspaddmm(mat1, mat2, *, beta=1, alpha=1) -> Tensor
|
| See :func:`torch.sspaddmm`
|
| std(...)
| std(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.std`
|
| storage_offset(...)
| storage_offset() -> int
|
| Returns :attr:`self` tensor's offset in the underlying storage in terms of
| number of storage elements (not bytes).
|
| Example::
|
| >>> x = torch.tensor([1, 2, 3, 4, 5])
| >>> x.storage_offset()
| 0
| >>> x[3:].storage_offset()
| 3
|
| stride(...)
| stride(dim) -> tuple or int
|
| Returns the stride of :attr:`self` tensor.
|
| Stride is the jump necessary to go from one element to the next one in the
| specified dimension :attr:`dim`. A tuple of all strides is returned when no
| argument is passed in. Otherwise, an integer value is returned as the stride in
| the particular dimension :attr:`dim`.
|
| Args:
| dim (int, optional): the desired dimension in which stride is required
|
| Example::
|
| >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
| >>> x.stride()
| (5, 1)
| >>> x.stride(0)
| 5
| >>> x.stride(-1)
| 1
|
| sub(...)
| sub(other, *, alpha=1) -> Tensor
|
| See :func:`torch.sub`.
|
| sub_(...)
| sub_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.sub`
|
| subtract(...)
| subtract(other, *, alpha=1) -> Tensor
|
| See :func:`torch.subtract`.
|
| subtract_(...)
| subtract_(other, *, alpha=1) -> Tensor
|
| In-place version of :meth:`~Tensor.subtract`.
|
| sum(...)
| sum(dim=None, keepdim=False, dtype=None) -> Tensor
|
| See :func:`torch.sum`
|
| sum_to_size(...)
| sum_to_size(*size) -> Tensor
|
| Sum ``this`` tensor to :attr:`size`.
| :attr:`size` must be broadcastable to ``this`` tensor size.
|
| Args:
| size (int...): a sequence of integers defining the shape of the output tensor.
|
| svd(...)
| svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)
|
| See :func:`torch.svd`
|
| swapaxes(...)
| swapaxes(axis0, axis1) -> Tensor
|
| See :func:`torch.swapaxes`
|
| swapaxes_(...)
| swapaxes_(axis0, axis1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapaxes`
|
| swapdims(...)
| swapdims(dim0, dim1) -> Tensor
|
| See :func:`torch.swapdims`
|
| swapdims_(...)
| swapdims_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.swapdims`
|
| t(...)
| t() -> Tensor
|
| See :func:`torch.t`
|
| t_(...)
| t_() -> Tensor
|
| In-place version of :meth:`~Tensor.t`
|
| take(...)
| take(indices) -> Tensor
|
| See :func:`torch.take`
|
| take_along_dim(...)
| take_along_dim(indices, dim) -> Tensor
|
| See :func:`torch.take_along_dim`
|
| tan(...)
| tan() -> Tensor
|
| See :func:`torch.tan`
|
| tan_(...)
| tan_() -> Tensor
|
| In-place version of :meth:`~Tensor.tan`
|
| tanh(...)
| tanh() -> Tensor
|
| See :func:`torch.tanh`
|
| tanh_(...)
| tanh_() -> Tensor
|
| In-place version of :meth:`~Tensor.tanh`
|
| tensor_split(...)
| tensor_split(indices_or_sections, dim=0) -> List of Tensors
|
| See :func:`torch.tensor_split`
|
| tile(...)
| tile(dims) -> Tensor
|
| See :func:`torch.tile`
|
| to(...)
| to(*args, **kwargs) -> Tensor
|
| Performs Tensor dtype and/or device conversion. A :class:`torch.dtype` and :class:`torch.device` are
| inferred from the arguments of ``self.to(*args, **kwargs)``.
|
| .. note::
|
| If the ``self`` Tensor already
| has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned.
| Otherwise, the returned tensor is a copy of ``self`` with the desired
| :class:`torch.dtype` and :class:`torch.device`.
|
| .. note::
|
| If ``self`` requires gradients (``requires_grad=True``) but the target
| ``dtype`` specified is an integer type, the returned tensor will implicitly
| set ``requires_grad=False``. This is because only tensors with
| floating-point or complex dtypes can require gradients.
|
| Here are the ways to call ``to``:
|
| .. method:: to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`dtype`
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. note::
|
| According to `C++ type conversion rules <https://en.cppreference.com/w/cpp/language/implicit_conversion.html>`_,
| converting floating point value to integer type will truncate the fractional part.
| If the truncated value cannot fit into the target type (e.g., casting ``torch.inf`` to ``torch.long``),
| the behavior is undefined and the result may vary across platforms.
|
| .. method:: to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
| :noindex:
|
| Returns a Tensor with the specified :attr:`device` and (optional)
| :attr:`dtype`. If :attr:`dtype` is ``None`` it is inferred to be ``self.dtype``.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Args:
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| .. method:: to(other, non_blocking=False, copy=False) -> Tensor
| :noindex:
|
| Returns a Tensor with same :class:`torch.dtype` and :class:`torch.device` as
| the Tensor :attr:`other`.
| When :attr:`non_blocking` is set to ``True``, the function attempts to perform
| the conversion asynchronously with respect to the host, if possible. This
| asynchronous behavior applies to both pinned and pageable memory. However,
| caution is advised when using this feature. For more information, refer to the
| `tutorial on good usage of non_blocking and pin_memory <https://pytorch.org/tutorials/intermediate/pinmem_nonblock.html>`__.
| When :attr:`copy` is set, a new Tensor is created even when the Tensor
| already matches the desired conversion.
|
| Example::
|
| >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu
| >>> tensor.to(torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64)
|
| >>> cuda0 = torch.device('cuda:0')
| >>> tensor.to(cuda0)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], device='cuda:0')
|
| >>> tensor.to(cuda0, dtype=torch.float64)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
| >>> tensor.to(other, non_blocking=True)
| tensor([[-0.5044, 0.0005],
| [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
|
| to_dense(...)
| to_dense(dtype=None, *, masked_grad=True) -> Tensor
|
| Creates a strided copy of :attr:`self` if :attr:`self` is not a strided tensor, otherwise returns :attr:`self`.
|
| Keyword args:
| {dtype}
| masked_grad (bool, optional): If set to ``True`` (default) and
| :attr:`self` has a sparse layout then the backward of
| :meth:`to_dense` returns ``grad.sparse_mask(self)``.
|
| Example::
|
| >>> s = torch.sparse_coo_tensor(
| ... torch.tensor([[1, 1],
| ... [0, 2]]),
| ... torch.tensor([9, 10]),
| ... size=(3, 3))
| >>> s.to_dense()
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
|
| to_mkldnn(...)
| to_mkldnn() -> Tensor
| Returns a copy of the tensor in ``torch.mkldnn`` layout.
|
| to_padded_tensor(...)
| to_padded_tensor(padding, output_size=None) -> Tensor
| See :func:`to_padded_tensor`
|
| to_sparse(...)
| to_sparse(sparseDims) -> Tensor
|
| Returns a sparse copy of the tensor. PyTorch supports sparse tensors in
| :ref:`coordinate format <sparse-coo-docs>`.
|
| Args:
| sparseDims (int, optional): the number of sparse dimensions to include in the new sparse tensor
|
| Example::
|
| >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]])
| >>> d
| tensor([[ 0, 0, 0],
| [ 9, 0, 10],
| [ 0, 0, 0]])
| >>> d.to_sparse()
| tensor(indices=tensor([[1, 1],
| [0, 2]]),
| values=tensor([ 9, 10]),
| size=(3, 3), nnz=2, layout=torch.sparse_coo)
| >>> d.to_sparse(1)
| tensor(indices=tensor([[1]]),
| values=tensor([[ 9, 0, 10]]),
| size=(3, 3), nnz=1, layout=torch.sparse_coo)
|
| .. method:: to_sparse(*, layout=None, blocksize=None, dense_dim=None) -> Tensor
| :noindex:
|
| Returns a sparse tensor with the specified layout and blocksize. If
| the :attr:`self` is strided, the number of dense dimensions could be
| specified, and a hybrid sparse tensor will be created, with
| `dense_dim` dense dimensions and `self.dim() - 2 - dense_dim` batch
| dimension.
|
| .. note:: If the :attr:`self` layout and blocksize parameters match
| with the specified layout and blocksize, return
| :attr:`self`. Otherwise, return a sparse tensor copy of
| :attr:`self`.
|
| Args:
|
| layout (:class:`torch.layout`, optional): The desired sparse
| layout. One of ``torch.sparse_coo``, ``torch.sparse_csr``,
| ``torch.sparse_csc``, ``torch.sparse_bsr``, or
| ``torch.sparse_bsc``. Default: if ``None``,
| ``torch.sparse_coo``.
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR or BSC tensor. For other layouts,
| specifying the block size that is not ``None`` will result in a
| RuntimeError exception. A block size must be a tuple of length
| two such that its items evenly divide the two sparse dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR, CSC, BSR or BSC tensor. This argument should be
| used only if :attr:`self` is a strided tensor, and must be a
| value between 0 and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> x = torch.tensor([[1, 0], [0, 0], [2, 3]])
| >>> x.to_sparse(layout=torch.sparse_coo)
| tensor(indices=tensor([[0, 2, 2],
| [0, 0, 1]]),
| values=tensor([1, 2, 3]),
| size=(3, 2), nnz=3, layout=torch.sparse_coo)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(1, 2))
| tensor(crow_indices=tensor([0, 1, 1, 2]),
| col_indices=tensor([0, 0]),
| values=tensor([[[1, 0]],
| [[2, 3]]]), size=(3, 2), nnz=2, layout=torch.sparse_bsr)
| >>> x.to_sparse(layout=torch.sparse_bsr, blocksize=(2, 1))
| RuntimeError: Tensor size(-2) 3 needs to be divisible by blocksize[0] 2
| >>> x.to_sparse(layout=torch.sparse_csr, blocksize=(3, 1))
| RuntimeError: to_sparse for Strided to SparseCsr conversion does not use specified blocksize
|
| >>> x = torch.tensor([[[1], [0]], [[0], [0]], [[2], [3]]])
| >>> x.to_sparse(layout=torch.sparse_csr, dense_dim=1)
| tensor(crow_indices=tensor([0, 1, 1, 3]),
| col_indices=tensor([0, 0, 1]),
| values=tensor([[1],
| [2],
| [3]]), size=(3, 2, 1), nnz=3, layout=torch.sparse_csr)
|
| to_sparse_bsc(...)
| to_sparse_bsc(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse column (BSC) storage format of
| given blocksize. If the :attr:`self` is strided, then the number of
| dense dimensions could be specified, and a hybrid BSC tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSC tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
| >>> sparse_bsc.row_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsc((2, 1), 1)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 1, 0]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsc)
|
| to_sparse_bsr(...)
| to_sparse_bsr(blocksize, dense_dim) -> Tensor
|
| Convert a tensor to a block sparse row (BSR) storage format of given
| blocksize. If the :attr:`self` is strided, then the number of dense
| dimensions could be specified, and a hybrid BSR tensor will be
| created, with `dense_dim` dense dimensions and `self.dim() - 2 -
| dense_dim` batch dimension.
|
| Args:
|
| blocksize (list, tuple, :class:`torch.Size`, optional): Block size
| of the resulting BSR tensor. A block size must be a tuple of
| length two such that its items evenly divide the two sparse
| dimensions.
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting BSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(10, 10)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse_bsr = sparse.to_sparse_bsr((5, 5))
| >>> sparse_bsr.col_indices()
| tensor([0, 1, 0, 1])
|
| >>> dense = torch.zeros(4, 3, 1)
| >>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
| >>> dense.to_sparse_bsr((2, 1), 1)
| tensor(crow_indices=tensor([0, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]],
|
|
| [[[1.]],
|
| [[1.]]]]), size=(4, 3, 1), nnz=3,
| layout=torch.sparse_bsr)
|
| to_sparse_csc(...)
| to_sparse_csc() -> Tensor
|
| Convert a tensor to compressed column storage (CSC) format. Except
| for strided tensors, only works with 2D tensors. If the :attr:`self`
| is strided, then the number of dense dimensions could be specified,
| and a hybrid CSC tensor will be created, with `dense_dim` dense
| dimensions and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSC tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csc()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csc(dense_dim=2)
| tensor(ccol_indices=tensor([0, 1, 2, 3]),
| row_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csc)
|
| to_sparse_csr(...)
| to_sparse_csr(dense_dim=None) -> Tensor
|
| Convert a tensor to compressed row storage format (CSR). Except for
| strided tensors, only works with 2D tensors. If the :attr:`self` is
| strided, then the number of dense dimensions could be specified, and a
| hybrid CSR tensor will be created, with `dense_dim` dense dimensions
| and `self.dim() - 2 - dense_dim` batch dimension.
|
| Args:
|
| dense_dim (int, optional): Number of dense dimensions of the
| resulting CSR tensor. This argument should be used only if
| :attr:`self` is a strided tensor, and must be a value between 0
| and dimension of :attr:`self` tensor minus two.
|
| Example::
|
| >>> dense = torch.randn(5, 5)
| >>> sparse = dense.to_sparse_csr()
| >>> sparse._nnz()
| 25
|
| >>> dense = torch.zeros(3, 3, 1, 1)
| >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
| >>> dense.to_sparse_csr(dense_dim=2)
| tensor(crow_indices=tensor([0, 1, 2, 3]),
| col_indices=tensor([0, 2, 1]),
| values=tensor([[[1.]],
|
| [[1.]],
|
| [[1.]]]), size=(3, 3, 1, 1), nnz=3,
| layout=torch.sparse_csr)
|
| tolist(...)
| tolist() -> list or number
|
| Returns the tensor as a (nested) list. For scalars, a standard
| Python number is returned, just like with :meth:`~Tensor.item`.
| Tensors are automatically moved to the CPU first if necessary.
|
| This operation is not differentiable.
|
| Examples::
|
| >>> a = torch.randn(2, 2)
| >>> a.tolist()
| [[0.012766935862600803, 0.5415473580360413],
| [-0.08909505605697632, 0.7729271650314331]]
| >>> a[0,0].tolist()
| 0.012766935862600803
|
| topk(...)
| topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)
|
| See :func:`torch.topk`
|
| trace(...)
| trace() -> Tensor
|
| See :func:`torch.trace`
|
| transpose(...)
| transpose(dim0, dim1) -> Tensor
|
| See :func:`torch.transpose`
|
| transpose_(...)
| transpose_(dim0, dim1) -> Tensor
|
| In-place version of :meth:`~Tensor.transpose`
|
| triangular_solve(...)
| triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)
|
| See :func:`torch.triangular_solve`
|
| tril(...)
| tril(diagonal=0) -> Tensor
|
| See :func:`torch.tril`
|
| tril_(...)
| tril_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.tril`
|
| triu(...)
| triu(diagonal=0) -> Tensor
|
| See :func:`torch.triu`
|
| triu_(...)
| triu_(diagonal=0) -> Tensor
|
| In-place version of :meth:`~Tensor.triu`
|
| true_divide(...)
| true_divide(value) -> Tensor
|
| See :func:`torch.true_divide`
|
| true_divide_(...)
| true_divide_(value) -> Tensor
|
| In-place version of :meth:`~Tensor.true_divide_`
|
| trunc(...)
| trunc() -> Tensor
|
| See :func:`torch.trunc`
|
| trunc_(...)
| trunc_() -> Tensor
|
| In-place version of :meth:`~Tensor.trunc`
|
| type(...)
| type(dtype=None, non_blocking=False, **kwargs) -> str or Tensor
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (dtype or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| type_as(...)
| type_as(tensor) -> Tensor
|
| Returns this tensor cast to the type of the given tensor.
|
| This is a no-op if the tensor is already of the correct type. This is
| equivalent to ``self.type(tensor.type())``
|
| Args:
| tensor (Tensor): the tensor which has the desired type
|
| unbind(...)
| unbind(dim=0) -> seq
|
| See :func:`torch.unbind`
|
| unfold(...)
| unfold(dimension, size, step) -> Tensor
|
| Returns a view of the original tensor which contains all slices of size :attr:`size` from
| :attr:`self` tensor in the dimension :attr:`dimension`.
|
| Step between two slices is given by :attr:`step`.
|
| If `sizedim` is the size of dimension :attr:`dimension` for :attr:`self`, the size of
| dimension :attr:`dimension` in the returned tensor will be
| `(sizedim - size) / step + 1`.
|
| An additional dimension of size :attr:`size` is appended in the returned tensor.
|
| Args:
| dimension (int): dimension in which unfolding happens
| size (int): the size of each slice that is unfolded
| step (int): the step between each slice
|
| Example::
|
| >>> x = torch.arange(1., 8)
| >>> x
| tensor([ 1., 2., 3., 4., 5., 6., 7.])
| >>> x.unfold(0, 2, 1)
| tensor([[ 1., 2.],
| [ 2., 3.],
| [ 3., 4.],
| [ 4., 5.],
| [ 5., 6.],
| [ 6., 7.]])
| >>> x.unfold(0, 2, 2)
| tensor([[ 1., 2.],
| [ 3., 4.],
| [ 5., 6.]])
|
| uniform_(...)
| uniform_(from=0, to=1, *, generator=None) -> Tensor
|
| Fills :attr:`self` tensor with numbers sampled from the continuous uniform
| distribution:
|
| .. math::
| f(x) = \dfrac{1}{\text{to} - \text{from}}
|
| unsafe_chunk(...)
| unsafe_chunk(chunks, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_chunk`
|
| unsafe_split(...)
| unsafe_split(split_size, dim=0) -> List of Tensors
|
| See :func:`torch.unsafe_split`
|
| unsafe_split_with_sizes(...)
|
| unsqueeze(...)
| unsqueeze(dim) -> Tensor
|
| See :func:`torch.unsqueeze`
|
| unsqueeze_(...)
| unsqueeze_(dim) -> Tensor
|
| In-place version of :meth:`~Tensor.unsqueeze`
|
| untyped_storage(...)
| untyped_storage() -> torch.UntypedStorage
|
| Returns the underlying :class:`UntypedStorage`.
|
| values(...)
| values() -> Tensor
|
| Return the values tensor of a :ref:`sparse COO tensor <sparse-coo-docs>`.
|
| .. warning::
| Throws an error if :attr:`self` is not a sparse COO tensor.
|
| See also :meth:`Tensor.indices`.
|
| .. note::
| This method can only be called on a coalesced sparse tensor. See
| :meth:`Tensor.coalesce` for details.
|
| var(...)
| var(dim=None, *, correction=1, keepdim=False) -> Tensor
|
| See :func:`torch.var`
|
| vdot(...)
| vdot(other) -> Tensor
|
| See :func:`torch.vdot`
|
| view(...)
| view(*shape) -> Tensor
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`shape`.
|
| The returned tensor shares the same data and must have the same number
| of elements, but may have a different size. For a tensor to be viewed, the new
| view size must be compatible with its original size and stride, i.e., each new
| view dimension must either be a subspace of an original dimension, or only span
| across original dimensions :math:`d, d+1, \dots, d+k` that satisfy the following
| contiguity-like condition that :math:`\forall i = d, \dots, d+k-1`,
|
| .. math::
|
| \text{stride}[i] = \text{stride}[i+1] \times \text{size}[i+1]
|
| Otherwise, it will not be possible to view :attr:`self` tensor as :attr:`shape`
| without copying it (e.g., via :meth:`contiguous`). When it is unclear whether a
| :meth:`view` can be performed, it is advisable to use :meth:`reshape`, which
| returns a view if the shapes are compatible, and copies (equivalent to calling
| :meth:`contiguous`) otherwise.
|
| Args:
| shape (torch.Size or int...): the desired size
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x.size()
| torch.Size([4, 4])
| >>> y = x.view(16)
| >>> y.size()
| torch.Size([16])
| >>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
| >>> z.size()
| torch.Size([2, 8])
|
| >>> a = torch.randn(1, 2, 3, 4)
| >>> a.size()
| torch.Size([1, 2, 3, 4])
| >>> b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
| >>> b.size()
| torch.Size([1, 3, 2, 4])
| >>> c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
| >>> c.size()
| torch.Size([1, 3, 2, 4])
| >>> torch.equal(b, c)
| False
|
|
| .. method:: view(dtype) -> Tensor
| :noindex:
|
| Returns a new tensor with the same data as the :attr:`self` tensor but of a
| different :attr:`dtype`.
|
| If the element size of :attr:`dtype` is different than that of ``self.dtype``,
| then the size of the last dimension of the output will be scaled
| proportionally. For instance, if :attr:`dtype` element size is twice that of
| ``self.dtype``, then each pair of elements in the last dimension of
| :attr:`self` will be combined, and the size of the last dimension of the output
| will be half that of :attr:`self`. If :attr:`dtype` element size is half that
| of ``self.dtype``, then each element in the last dimension of :attr:`self` will
| be split in two, and the size of the last dimension of the output will be
| double that of :attr:`self`. For this to be possible, the following conditions
| must be true:
|
| * ``self.dim()`` must be greater than 0.
| * ``self.stride(-1)`` must be 1.
|
| Additionally, if the element size of :attr:`dtype` is greater than that of
| ``self.dtype``, the following conditions must be true as well:
|
| * ``self.size(-1)`` must be divisible by the ratio between the element
| sizes of the dtypes.
| * ``self.storage_offset()`` must be divisible by the ratio between the
| element sizes of the dtypes.
| * The strides of all dimensions, except the last dimension, must be
| divisible by the ratio between the element sizes of the dtypes.
|
| If any of the above conditions are not met, an error is thrown.
|
| .. warning::
|
| This overload is not supported by TorchScript, and using it in a Torchscript
| program will cause undefined behavior.
|
|
| Args:
| dtype (:class:`torch.dtype`): the desired dtype
|
| Example::
|
| >>> x = torch.randn(4, 4)
| >>> x
| tensor([[ 0.9482, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
| >>> x.dtype
| torch.float32
|
| >>> y = x.view(torch.int32)
| >>> y
| tensor([[ 1064483442, -1124191867, 1069546515, -1089989247],
| [-1105482831, 1061112040, 1057999968, -1084397505],
| [-1071760287, -1123489973, -1097310419, -1084649136],
| [-1101533110, 1073668768, -1082790149, -1088634448]],
| dtype=torch.int32)
| >>> y[0, 0] = 1000000000
| >>> x
| tensor([[ 0.0047, -0.0310, 1.4999, -0.5316],
| [-0.1520, 0.7472, 0.5617, -0.8649],
| [-2.4724, -0.0334, -0.2976, -0.8499],
| [-0.2109, 1.9913, -0.9607, -0.6123]])
|
| >>> x.view(torch.cfloat)
| tensor([[ 0.0047-0.0310j, 1.4999-0.5316j],
| [-0.1520+0.7472j, 0.5617-0.8649j],
| [-2.4724-0.0334j, -0.2976-0.8499j],
| [-0.2109+1.9913j, -0.9607-0.6123j]])
| >>> x.view(torch.cfloat).size()
| torch.Size([4, 2])
|
| >>> x.view(torch.uint8)
| tensor([[ 0, 202, 154, 59, 182, 243, 253, 188, 185, 252, 191, 63, 240, 22,
| 8, 191],
| [227, 165, 27, 190, 128, 72, 63, 63, 146, 203, 15, 63, 22, 106,
| 93, 191],
| [205, 59, 30, 192, 112, 206, 8, 189, 7, 95, 152, 190, 12, 147,
| 89, 191],
| [ 43, 246, 87, 190, 235, 226, 254, 63, 111, 240, 117, 191, 177, 191,
| 28, 191]], dtype=torch.uint8)
| >>> x.view(torch.uint8).size()
| torch.Size([4, 16])
|
| view_as(...)
| view_as(other) -> Tensor
|
| View this tensor as the same size as :attr:`other`.
| ``self.view_as(other)`` is equivalent to ``self.view(other.size())``.
|
| Please see :meth:`~Tensor.view` for more information about ``view``.
|
| Args:
| other (:class:`torch.Tensor`): The result tensor has the same size
| as :attr:`other`.
|
| vsplit(...)
| vsplit(split_size_or_sections) -> List of Tensors
|
| See :func:`torch.vsplit`
|
| where(...)
| where(condition, y) -> Tensor
|
| ``self.where(condition, y)`` is equivalent to ``torch.where(condition, self, y)``.
| See :func:`torch.where`
|
| xlogy(...)
| xlogy(other) -> Tensor
|
| See :func:`torch.xlogy`
|
| xlogy_(...)
| xlogy_(other) -> Tensor
|
| In-place version of :meth:`~Tensor.xlogy`
|
| xpu(...)
| xpu(device=None, non_blocking=False, memory_format=torch.preserve_format) -> Tensor
|
| Returns a copy of this object in XPU memory.
|
| If this object is already in XPU memory and on the correct device,
| then no copy is performed and the original object is returned.
|
| Args:
| device (:class:`torch.device`, optional): The destination XPU device.
| Defaults to the current XPU device.
| non_blocking (bool, optional): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host.
| Otherwise, the argument has no effect. Default: ``False``.
| memory_format (:class:`torch.memory_format`, optional): the desired memory format of
| returned Tensor. Default: ``torch.preserve_format``.
|
| zero_(...)
| zero_() -> Tensor
|
| Fills :attr:`self` tensor with zeros.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch._C.TensorBase:
|
| __new__(*args, **kwargs) class method of torch._C.TensorBase
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C.TensorBase:
|
| H
| Returns a view of a matrix (2-D tensor) conjugated and transposed.
|
| ``x.H`` is equivalent to ``x.transpose(0, 1).conj()`` for complex matrices and
| ``x.transpose(0, 1)`` for real matrices.
|
| .. seealso::
|
| :attr:`~.Tensor.mH`: An attribute that also works on batches of matrices.
|
| T
| Returns a view of this tensor with its dimensions reversed.
|
| If ``n`` is the number of dimensions in ``x``,
| ``x.T`` is equivalent to ``x.permute(n-1, n-2, ..., 0)``.
|
| .. warning::
| The use of :func:`Tensor.T` on tensors of dimension other than 2 to reverse their shape
| is deprecated and it will throw an error in a future release. Consider :attr:`~.Tensor.mT`
| to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse
| the dimensions of a tensor.
|
| data
|
| device
| Is the :class:`torch.device` where this Tensor is.
|
| dtype
|
| grad
| This attribute is ``None`` by default and becomes a Tensor the first time a call to
| :func:`backward` computes gradients for ``self``.
| The attribute will then contain the gradients computed and future calls to
| :func:`backward` will accumulate (add) gradients into it.
|
| grad_dtype
| The allowed dtype of :attr:``grad`` for this tensor.
|
| :attr:``grad_dtype`` can be set to a specific dtype or ``None``. By default,
| ``t.grad_dtype == t.dtype``. When not None, the autograd engine casts
| incoming gradients to this dtype. This attribute is only accessible and
| settable for leaf tensors.
|
| .. warning::
| Use with caution. Diverging the dtypes of a tensor and its gradient may
| break downstream systems that assume they match.
|
| Example::
|
| >>> x = torch.tensor([1.0, 2.0], requires_grad=True)
| >>> x.grad_dtype
| torch.float32
|
| >>> x.grad_dtype = torch.float16
| >>> x.grad_dtype
| torch.float16
|
| >>> # Allow any gradient dtype
| >>> x.grad_dtype = None
| >>> x.grad_dtype
|
| grad_fn
|
| imag
| Returns a new tensor containing imaginary values of the :attr:`self` tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| .. warning::
| :func:`imag` is only supported for tensors with complex dtypes.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.imag
| tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
|
| is_cpu
| Is ``True`` if the Tensor is stored on the CPU, ``False`` otherwise.
|
| is_cuda
| Is ``True`` if the Tensor is stored on the GPU, ``False`` otherwise.
|
| is_ipu
| Is ``True`` if the Tensor is stored on the IPU, ``False`` otherwise.
|
| is_leaf
| All Tensors that have :attr:`requires_grad` which is ``False`` will be leaf Tensors by convention.
|
| For Tensors that have :attr:`requires_grad` which is ``True``, they will be leaf Tensors if they were
| created by the user. This means that they are not the result of an operation and so
| :attr:`grad_fn` is None.
|
| Only leaf Tensors will have their :attr:`grad` populated during a call to :func:`backward`.
| To get :attr:`grad` populated for non-leaf Tensors, you can use :func:`retain_grad`.
|
| Example::
|
| >>> a = torch.rand(10, requires_grad=True)
| >>> a.is_leaf
| True
| >>> b = torch.rand(10, requires_grad=True).cuda()
| >>> b.is_leaf
| False
| # b was created by the operation that cast a cpu Tensor into a cuda Tensor
| >>> c = torch.rand(10, requires_grad=True) + 2
| >>> c.is_leaf
| False
| # c was created by the addition operation
| >>> d = torch.rand(10).cuda()
| >>> d.is_leaf
| True
| # d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
| >>> e = torch.rand(10).cuda().requires_grad_()
| >>> e.is_leaf
| True
| # e requires gradients and has no operations creating it
| >>> f = torch.rand(10, requires_grad=True, device="cuda")
| >>> f.is_leaf
| True
| # f requires grad, has no operation creating it
|
| is_maia
|
| is_meta
| Is ``True`` if the Tensor is a meta tensor, ``False`` otherwise. Meta tensors
| are like normal tensors, but they carry no data.
|
| is_mkldnn
|
| is_mps
| Is ``True`` if the Tensor is stored on the MPS device, ``False`` otherwise.
|
| is_mtia
|
| is_nested
|
| is_quantized
| Is ``True`` if the Tensor is quantized, ``False`` otherwise.
|
| is_sparse
| Is ``True`` if the Tensor uses sparse COO storage layout, ``False`` otherwise.
|
| is_sparse_csr
| Is ``True`` if the Tensor uses sparse CSR storage layout, ``False`` otherwise.
|
| is_vulkan
|
| is_xla
| Is ``True`` if the Tensor is stored on an XLA device, ``False`` otherwise.
|
| is_xpu
| Is ``True`` if the Tensor is stored on the XPU, ``False`` otherwise.
|
| itemsize
| Alias for :meth:`~Tensor.element_size()`
|
| layout
|
| mH
| Accessing this property is equivalent to calling :func:`adjoint`.
|
| mT
| Returns a view of this tensor with the last two dimensions transposed.
|
| ``x.mT`` is equivalent to ``x.transpose(-2, -1)``.
|
| name
|
| nbytes
| Returns the number of bytes consumed by the "view" of elements of the Tensor
| if the Tensor does not use sparse storage layout.
| Defined to be :meth:`~Tensor.numel()` * :meth:`~Tensor.element_size()`
|
| ndim
| Alias for :meth:`~Tensor.dim()`
|
| output_nr
|
| real
| Returns a new tensor containing real values of the :attr:`self` tensor for a complex-valued input tensor.
| The returned tensor and :attr:`self` share the same underlying storage.
|
| Returns :attr:`self` if :attr:`self` is a real-valued tensor.
|
| Example::
|
| >>> x=torch.randn(4, dtype=torch.cfloat)
| >>> x
| tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
| >>> x.real
| tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
|
| requires_grad
| Is ``True`` if gradients need to be computed for this Tensor, ``False`` otherwise.
|
| .. note::
|
| The fact that gradients need to be computed for a Tensor do not mean that the :attr:`grad`
| attribute will be populated, see :attr:`is_leaf` for more details.
|
| retains_grad
| Is ``True`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
| populated during :func:`backward`, ``False`` otherwise.
|
| shape
| shape() -> torch.Size
|
| Returns the size of the :attr:`self` tensor. Alias for :attr:`size`.
|
| See also :meth:`Tensor.size`.
|
| Example::
|
| >>> t = torch.empty(3, 4, 5)
| >>> t.size()
| torch.Size([3, 4, 5])
| >>> t.shape
| torch.Size([3, 4, 5])
|
| volatile
class TensorType(Type)
| Method resolution order:
| TensorType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| create_from_tensor(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| create_from_tensor(arg0: torch.Tensor) -> torch._C.TensorType
|
| get(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| get() -> torch._C.TensorType
|
| getInferred(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
| getInferred() -> torch._C.TensorType
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class ThroughputBenchmark(pybind11_builtins.pybind11_object)
| Method resolution order:
| ThroughputBenchmark
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(*args, **kwargs)
| Overloaded function.
|
| 1. __init__(self: torch._C.ThroughputBenchmark, arg0: torch._C.ScriptModule) -> None
|
| 2. __init__(self: torch._C.ThroughputBenchmark, arg0: object) -> None
|
| add_input(...)
| add_input(self: torch._C.ThroughputBenchmark, *args, **kwargs) -> None
|
| benchmark(...)
| benchmark(self: torch._C.ThroughputBenchmark, arg0: torch._C.BenchmarkConfig) -> torch._C.BenchmarkExecutionStats
|
| run_once(...)
| run_once(self: torch._C.ThroughputBenchmark, *args, **kwargs) -> object
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class TracingState(pybind11_builtins.pybind11_object)
| Method resolution order:
| TracingState
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(...)
| __repr__(self: torch._C.TracingState) -> str
|
| __str__(...)
| __str__(self: torch._C.TracingState) -> str
|
| current_scope(...)
| current_scope(self: torch._C.TracingState) -> str
|
| graph(...)
| graph(self: torch._C.TracingState) -> torch._C.Graph
|
| pop_scope(...)
| pop_scope(self: torch._C.TracingState) -> None
|
| push_scope(...)
| push_scope(self: torch._C.TracingState, arg0: str) -> None
|
| set_graph(...)
| set_graph(self: torch._C.TracingState, arg0: torch._C.Graph) -> None
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class TupleType(Type)
| Method resolution order:
| TupleType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.TupleType, arg0: collections.abc.Sequence[torch._C.Type]) -> None
|
| elements(...)
| elements(self: torch._C.TupleType) -> list[torch._C.Type]
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Type(pybind11_builtins.pybind11_object)
| Method resolution order:
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class TypedStorage(builtins.object)
| TypedStorage(*args, wrap_storage=None, dtype=None, device=None, _internal=False)
|
| Methods defined here:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __getitem__(self, idx)
|
| __init__(self, *args, device=None, dtype=None, wrap_storage=None, _internal=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __len__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, idx, value)
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| __str__(self)
| Return str(self).
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| copy_(self, source: 'T', non_blocking: 'bool | None' = None)
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| data_ptr(self)
|
| double(self)
| Casts this storage to double type.
|
| element_size(self)
|
| fill_(self, value)
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> 'Self'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU TypedStorage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| is_shared(self)
|
| long(self)
| Casts this storage to long type.
|
| nbytes(self)
|
| pickle_storage_type(self)
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU TypedStorage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| resizable(self)
|
| resize_(self, size)
|
| share_memory_(self)
| See :meth:`torch.UntypedStorage.share_memory_`
|
| short(self)
| Casts this storage to short type.
|
| size(self)
|
| to(self, *, device: 'DeviceLikeType', non_blocking: 'bool' = False) -> 'Self'
| Returns a copy of this object in device memory.
|
| If this object is already on the correct device, then no copy is performed
| and the original object is returned.
|
| Args:
| device (int): The destination device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: 'bool' = False) -> '_StorageBase | TypedStorage | str'
| Returns the type if `dtype` is not provided, else casts this object to
| the specified type.
|
| If this is already of the correct type, no copy is performed and the
| original object is returned.
|
| Args:
| dtype (type or string): The desired type
| non_blocking (bool): If ``True``, and the source is in pinned memory
| and destination is on the GPU or vice versa, the copy is performed
| asynchronously with respect to the host. Otherwise, the argument
| has no effect.
| **kwargs: For compatibility, may contain the key ``async`` in place of
| the ``non_blocking`` argument. The ``async`` arg is deprecated.
|
| untyped(self)
| Return the internal :class:`torch.UntypedStorage`.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_buffer(*args, **kwargs)
|
| from_file(filename, shared, size)
| from_file(filename, shared=False, size=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
| then the file must contain at least ``size * sizeof(Type)`` bytes
| (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| size (int): number of elements in the storage
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, *args, wrap_storage=None, dtype=None, device=None, _internal=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| device
|
| filename
| Returns the file name associated with this storage if the storage was memory mapped from a file.
| or ``None`` if the storage was not created by memory mapping a file.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'_fake_device': 'torch.device | None', 'dtype': 'to...
|
| is_sparse = False
class UnionType(Type)
| Method resolution order:
| UnionType
| Type
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: torch._C.UnionType, arg0: collections.abc.Sequence[torch._C.Type]) -> None
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from Type:
|
| __eq__(...)
| __eq__(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| __repr__(...)
| __repr__(self: torch._C.Type) -> str
|
| containedTypes(...)
| containedTypes(self: torch._C.Type) -> list[torch._C.Type]
|
| contiguous(...)
| contiguous(self: torch._C.Type) -> torch._C.Type
|
| device(...)
| device(self: torch._C.Type) -> object
|
| dim(...)
| dim(self: torch._C.Type) -> object
|
| dtype(...)
| dtype(self: torch._C.Type) -> object
|
| isSubtypeOf(...)
| isSubtypeOf(self: torch._C.Type, arg0: torch._C.Type) -> bool
|
| is_interface_type(...)
| is_interface_type(self: torch._C.Type) -> bool
|
| kind(...)
| kind(self: torch._C.Type) -> str
|
| requires_grad(...)
| requires_grad(self: torch._C.Type) -> bool
|
| scalarType(...)
| scalarType(self: torch._C.Type) -> str
|
| sizes(...)
| sizes(self: torch._C.Type) -> object
|
| str(...)
| str(self: torch._C.Type) -> str
|
| strides(...)
| strides(self: torch._C.Type) -> object
|
| symbolic_sizes(...)
| symbolic_sizes(self: torch._C.Type) -> object
|
| undefined(...)
| undefined(self: torch._C.Type) -> object
|
| varyingSizes(...)
| varyingSizes(self: torch._C.Type) -> object
|
| with_device(...)
| with_device(self: torch._C.Type, arg0: object) -> object
|
| with_dtype(...)
| with_dtype(self: torch._C.Type, arg0: object) -> object
|
| with_sizes(...)
| with_sizes(self: torch._C.Type, arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | None] | None) -> object
|
| ----------------------------------------------------------------------
| Readonly properties inherited from Type:
|
| annotation_str
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from Type:
|
| __hash__ = None
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class UntypedStorage(torch._C.StorageBase, _StorageBase)
| UntypedStorage(*args, **kwargs)
|
| Method resolution order:
| UntypedStorage
| torch._C.StorageBase
| _StorageBase
| builtins.object
|
| Methods defined here:
|
| __getitem__(self, *args, **kwargs)
| Return self[key].
|
| share_memory_(self, *args, **kwargs)
| Moves the storage to shared memory.
|
| This is a no-op for storages already in shared memory and for CUDA
| storages, which do not need to be moved for sharing across processes.
| Storages in shared memory cannot be resized.
|
| Note that to mitigate issues like `this <https://github.com/pytorch/pytorch/issues/95606>`_
| it is thread safe to call this function from multiple threads on the same object.
| It is NOT thread safe though to call any other function on self without proper
| synchronization. Please see :doc:`/notes/multiprocessing` for more details.
|
| .. note::
| When all references to a storage in shared memory are deleted, the associated shared memory
| object will also be deleted. PyTorch has a special cleanup process to ensure that this happens
| even if the current process exits unexpectedly.
|
| It is worth noting the difference between :meth:`share_memory_` and :meth:`from_file` with ``shared = True``
|
| #. ``share_memory_`` uses `shm_open(3) <https://man7.org/linux/man-pages/man3/shm_open.3.html>`_ to create a
| POSIX shared memory object while :meth:`from_file` uses
| `open(2) <https://man7.org/linux/man-pages/man2/open.2.html>`_ to open the filename passed by the user.
| #. Both use an `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_ with ``MAP_SHARED``
| to map the file/object into the current virtual address space
| #. ``share_memory_`` will call ``shm_unlink(3)`` on the object after mapping it to make sure the shared memory
| object is freed when no process has the object open. ``torch.from_file(shared=True)`` does not unlink the
| file. This file is persistent and will remain until it is deleted by the user.
|
| Returns:
| ``self``
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| filename
| Returns the file name associated with this storage.
|
| The file name will be a string if the storage is on CPU and was created via
| :meth:`~torch.from_file()` with ``shared`` as ``True``. This attribute is ``None`` otherwise.
|
| is_cuda
|
| is_hpu
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Methods inherited from torch._C.StorageBase:
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __len__(self, /)
| Return len(self).
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| copy_(...)
|
| data_ptr(...)
|
| element_size(...)
|
| fill_(...)
|
| is_shared(...)
|
| nbytes(...)
|
| new(...)
|
| resizable(...)
|
| resize_(...)
|
| ----------------------------------------------------------------------
| Static methods inherited from torch._C.StorageBase:
|
| __new__(*args, **kwargs) class method of torch._C.StorageBase
| Create and return a new object. See help(type) for accurate signature.
|
| from_buffer(...)
|
| from_file(...)
| from_file(filename, shared=False, nbytes=0) -> Storage
|
| Creates a CPU storage backed by a memory-mapped file.
|
| If ``shared`` is ``True``, then memory is shared between all processes.
| All changes are written to the file. If ``shared`` is ``False``, then the changes on
| the storage do not affect the file.
|
| ``nbytes`` is the number of bytes of storage. If ``shared`` is ``False``,
| then the file must contain at least ``nbytes`` bytes. If ``shared`` is
| ``True`` the file will be created if needed. (Note that for ``UntypedStorage``
| this argument differs from that of ``TypedStorage.from_file``)
|
| Args:
| filename (str): file name to map
| shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
| underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
| nbytes (int): number of bytes of storage
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._C.StorageBase:
|
| device
|
| ----------------------------------------------------------------------
| Methods inherited from _StorageBase:
|
| __copy__(self)
|
| __deepcopy__(self, memo)
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
|
| __reduce__(self)
| Helper for pickle.
|
| __repr__(self)
| Return repr(self).
|
| __sizeof__(self)
| Size of object in memory, in bytes.
|
| bfloat16(self)
| Casts this storage to bfloat16 type.
|
| bool(self)
| Casts this storage to bool type.
|
| byte(self)
| Casts this storage to byte type.
|
| byteswap(self, dtype)
| Swap bytes in underlying data.
|
| char(self)
| Casts this storage to char type.
|
| clone(self)
| Return a copy of this storage.
|
| complex_double(self)
| Casts this storage to complex double type.
|
| complex_float(self)
| Casts this storage to complex float type.
|
| cpu(self)
| Return a CPU copy of this storage if it's not already on the CPU.
|
| cuda(self, device=None, non_blocking=False) -> '_StorageBase | TypedStorage'
| Returns a copy of this object in CUDA memory.
|
| If this object is already in CUDA memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination GPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| double(self)
| Casts this storage to double type.
|
| float(self)
| Casts this storage to float type.
|
| float8_e4m3fn(self)
| Casts this storage to float8_e4m3fn type
|
| float8_e4m3fnuz(self)
| Casts this storage to float8_e4m3fnuz type
|
| float8_e5m2(self)
| Casts this storage to float8_e5m2 type
|
| float8_e5m2fnuz(self)
| Casts this storage to float8_e5m2fnuz type
|
| get_device(self) -> '_int'
|
| half(self)
| Casts this storage to half type.
|
| hpu(self, device=None, non_blocking=False) -> '_StorageBase | TypedStorage'
| Returns a copy of this object in HPU memory.
|
| If this object is already in HPU memory and on the correct device, then
| no copy is performed and the original object is returned.
|
| Args:
| device (int): The destination HPU id. Defaults to the current device.
| non_blocking (bool): If ``True`` and the source is in pinned memory,
| the copy will be asynchronous with respect to the host. Otherwise,
| the argument has no effect.
|
| int(self)
| Casts this storage to int type.
|
| is_pinned(self, device: 'DeviceLikeType | None' = None)
| Determine whether the CPU storage is already pinned on device.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A boolean variable.
|
| long(self)
| Casts this storage to long type.
|
| mps(self)
| Return a MPS copy of this storage if it's not already on the MPS.
|
| pin_memory(self, device: 'DeviceLikeType | None' = None)
| Copy the CPU storage to pinned memory, if it's not already pinned.
|
| Args:
| device (str or torch.device): The device to pin memory on (default: ``None``).
| This argument is discouraged and subject to deprecated.
|
| Returns:
| A pinned CPU storage.
|
| short(self)
| Casts this storage to short type.
|
| size(self) -> '_int'
|
| to(self, *, device: 'DeviceLikeType', non_blocking: '_bool' = False)
|
| tolist(self)
| Return a list containing the elements of this storage.
|
| type(self, dtype: 'str | None' = None, non_blocking: '_bool' = False) -> '_StorageBase | TypedStorage'
|
| untyped(self)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from _StorageBase:
|
| is_sparse = False
|
| is_sparse_csr = False
class Use(pybind11_builtins.pybind11_object)
| Method resolution order:
| Use
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| isAfter(...)
| isAfter(self: torch._C.Use, arg0: torch._C.Use) -> bool
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| offset
|
| user
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class Value(pybind11_builtins.pybind11_object)
| Method resolution order:
| Value
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __repr__(...)
| __repr__(self: torch._C.Value) -> str
|
| copyMetadata(...)
| copyMetadata(self: torch._C.Value, arg0: torch._C.Value) -> torch._C.Value
|
| debugName(...)
| debugName(self: torch._C.Value) -> str
|
| inferTypeFrom(...)
| inferTypeFrom(*args, **kwargs)
| Overloaded function.
|
| 1. inferTypeFrom(self: torch._C.Value, arg0: torch.Tensor) -> None
|
| 2. inferTypeFrom(self: torch._C.Value, arg0: c10::ivalue::Object) -> None
|
| isCompleteTensor(...)
| isCompleteTensor(self: torch._C.Value) -> bool
|
| node(...)
| node(self: torch._C.Value) -> torch::jit::Node
|
| offset(...)
| offset(self: torch._C.Value) -> int
|
| replaceAllUsesAfterNodeWith(...)
| replaceAllUsesAfterNodeWith(self: torch._C.Value, arg0: torch::jit::Node, arg1: torch._C.Value) -> None
|
| replaceAllUsesWith(...)
| replaceAllUsesWith(self: torch._C.Value, arg0: torch._C.Value) -> None
|
| requiresGrad(...)
| requiresGrad(self: torch._C.Value) -> bool | None
|
| requires_grad(...)
| requires_grad(self: torch._C.Value) -> bool
|
| setDebugName(...)
| setDebugName(self: torch._C.Value, arg0: str) -> torch._C.Value
|
| setType(...)
| setType(self: torch._C.Value, arg0: c10::Type) -> torch._C.Value
|
| setTypeAs(...)
| setTypeAs(self: torch._C.Value, arg0: torch._C.Value) -> torch._C.Value
|
| toIValue(...)
| toIValue(self: torch._C.Value) -> IValue | None
|
| type(...)
| type(*args, **kwargs)
| Overloaded function.
|
| 1. type(self: torch._C.Value) -> c10::Type
|
| 2. type(self: torch._C.Value) -> c10::Type
|
| unique(...)
| unique(self: torch._C.Value) -> int
|
| uses(...)
| uses(self: torch._C.Value) -> list[torch::jit::Use]
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {}
|
| ----------------------------------------------------------------------
| Static methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) class method of pybind11_builtins.pybind11_object
| Create and return a new object. See help(type) for accurate signature.
class autocast(builtins.object)
| autocast(device_type: str, dtype: torch.dtype | None = None, enabled: bool = True, cache_enabled: bool | None = None)
|
| Instances of :class:`autocast` serve as context managers or decorators that
| allow regions of your script to run in mixed precision.
|
| In these regions, ops run in an op-specific dtype chosen by autocast
| to improve performance while maintaining accuracy.
| See the :ref:`Autocast Op Reference<autocast-op-reference>` for details.
|
| When entering an autocast-enabled region, Tensors may be any type.
| You should not call ``half()`` or ``bfloat16()`` on your model(s) or inputs when using autocasting.
|
| :class:`autocast` should wrap only the forward pass(es) of your network, including the loss
| computation(s). Backward passes under autocast are not recommended.
| Backward ops run in the same type that autocast used for corresponding forward ops.
|
| Example for CUDA Devices::
|
| # Creates model and optimizer in default precision
| model = Net().cuda()
| optimizer = optim.SGD(model.parameters(), ...)
|
| for input, target in data:
| optimizer.zero_grad()
|
| # Enables autocasting for the forward pass (model + loss)
| with torch.autocast(device_type="cuda"):
| output = model(input)
| loss = loss_fn(output, target)
|
| # Exits the context manager before backward()
| loss.backward()
| optimizer.step()
|
| See the :ref:`Automatic Mixed Precision examples<amp-examples>` for usage (along with gradient scaling)
| in more complex scenarios (e.g., gradient penalty, multiple models/losses, custom autograd functions).
|
| :class:`autocast` can also be used as a decorator, e.g., on the ``forward`` method of your model::
|
| class AutocastModel(nn.Module):
| ...
|
| @torch.autocast(device_type="cuda")
| def forward(self, input): ...
|
| Floating-point Tensors produced in an autocast-enabled region may be ``float16``.
| After returning to an autocast-disabled region, using them with floating-point
| Tensors of different dtypes may cause type mismatch errors. If so, cast the Tensor(s)
| produced in the autocast region back to ``float32`` (or other dtype if desired).
| If a Tensor from the autocast region is already ``float32``, the cast is a no-op,
| and incurs no additional overhead.
| CUDA Example::
|
| # Creates some tensors in default dtype (here assumed to be float32)
| a_float32 = torch.rand((8, 8), device="cuda")
| b_float32 = torch.rand((8, 8), device="cuda")
| c_float32 = torch.rand((8, 8), device="cuda")
| d_float32 = torch.rand((8, 8), device="cuda")
|
| with torch.autocast(device_type="cuda"):
| # torch.mm is on autocast's list of ops that should run in float16.
| # Inputs are float32, but the op runs in float16 and produces float16 output.
| # No manual casts are required.
| e_float16 = torch.mm(a_float32, b_float32)
| # Also handles mixed input types
| f_float16 = torch.mm(d_float32, e_float16)
|
| # After exiting autocast, calls f_float16.float() to use with d_float32
| g_float32 = torch.mm(d_float32, f_float16.float())
|
| CPU Training Example::
|
| # Creates model and optimizer in default precision
| model = Net()
| optimizer = optim.SGD(model.parameters(), ...)
|
| for epoch in epochs:
| for input, target in data:
| optimizer.zero_grad()
|
| # Runs the forward pass with autocasting.
| with torch.autocast(device_type="cpu", dtype=torch.bfloat16):
| output = model(input)
| loss = loss_fn(output, target)
|
| loss.backward()
| optimizer.step()
|
|
| CPU Inference Example::
|
| # Creates model in default precision
| model = Net().eval()
|
| with torch.autocast(device_type="cpu", dtype=torch.bfloat16):
| for input in data:
| # Runs the forward pass with autocasting.
| output = model(input)
|
| CPU Inference Example with Jit Trace::
|
| class TestModel(nn.Module):
| def __init__(self, input_size, num_classes):
| super().__init__()
| self.fc1 = nn.Linear(input_size, num_classes)
|
| def forward(self, x):
| return self.fc1(x)
|
|
| input_size = 2
| num_classes = 2
| model = TestModel(input_size, num_classes).eval()
|
| # For now, we suggest to disable the Jit Autocast Pass,
| # As the issue: https://github.com/pytorch/pytorch/issues/75956
| torch._C._jit_set_autocast_mode(False)
|
| with torch.cpu.amp.autocast(cache_enabled=False):
| model = torch.jit.trace(model, torch.randn(1, input_size))
| model = torch.jit.freeze(model)
| # Models Run
| for _ in range(3):
| model(torch.randn(1, input_size))
|
| Type mismatch errors *in* an autocast-enabled region are a bug; if this is what you observe,
| please file an issue.
|
| ``autocast(enabled=False)`` subregions can be nested in autocast-enabled regions.
| Locally disabling autocast can be useful, for example, if you want to force a subregion
| to run in a particular ``dtype``. Disabling autocast gives you explicit control over
| the execution type. In the subregion, inputs from the surrounding region
| should be cast to ``dtype`` before use::
|
| # Creates some tensors in default dtype (here assumed to be float32)
| a_float32 = torch.rand((8, 8), device="cuda")
| b_float32 = torch.rand((8, 8), device="cuda")
| c_float32 = torch.rand((8, 8), device="cuda")
| d_float32 = torch.rand((8, 8), device="cuda")
|
| with torch.autocast(device_type="cuda"):
| e_float16 = torch.mm(a_float32, b_float32)
| with torch.autocast(device_type="cuda", enabled=False):
| # Calls e_float16.float() to ensure float32 execution
| # (necessary because e_float16 was created in an autocasted region)
| f_float32 = torch.mm(c_float32, e_float16.float())
|
| # No manual casts are required when re-entering the autocast-enabled region.
| # torch.mm again runs in float16 and produces float16 output, regardless of input types.
| g_float16 = torch.mm(d_float32, f_float32)
|
| The autocast state is thread-local. If you want it enabled in a new thread, the context manager or decorator
| must be invoked in that thread. This affects :class:`torch.nn.DataParallel` and
| :class:`torch.nn.parallel.DistributedDataParallel` when used with more than one GPU per process
| (see :ref:`Working with Multiple GPUs<amp-multigpu>`).
|
| Args:
| device_type(str, required): Device type to use. Possible values are: 'cuda', 'cpu', 'mtia', 'maia', 'xpu', and 'hpu'.
| The type is the same as the `type` attribute of a :class:`torch.device`.
| Thus, you may obtain the device type of a tensor using `Tensor.device.type`.
| enabled(bool, optional): Whether autocasting should be enabled in the region.
| Default: ``True``
| dtype(torch_dtype, optional): Data type for ops run in autocast. It uses the default value
| (``torch.float16`` for CUDA and ``torch.bfloat16`` for CPU), given by
| :func:`~torch.get_autocast_dtype`, if :attr:`dtype` is ``None``.
| Default: ``None``
| cache_enabled(bool, optional): Whether the weight cache inside autocast should be enabled.
| Default: ``True``
|
| Methods defined here:
|
| __call__(self, func)
| Call self as a function.
|
| __enter__(self)
|
| __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any)
|
| __init__(self, device_type: str, dtype: torch.dtype | None = None, enabled: bool = True, cache_enabled: bool | None = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class device(builtins.object)
| Methods defined here:
|
| __enter__(...)
|
| __eq__(self, value, /)
| Return self==value.
|
| __exit__(...)
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| index
|
| type
class dtype(builtins.object)
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| to_complex(...)
|
| to_real(...)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| abbr
|
| is_complex
|
| is_floating_point
|
| is_signed
|
| itemsize
class enable_grad(torch.utils._contextlib._NoParamDecoratorContextManager)
| enable_grad(orig_func: Optional[~F] = None) -> Union[Self, ~F]
|
| Context-manager that enables gradient calculation.
|
| Enables gradient calculation, if it has been disabled via :class:`~no_grad`
| or :class:`~set_grad_enabled`.
|
| This context manager is thread local; it will not affect computation
| in other threads.
|
| Also functions as a decorator.
|
| .. note::
| enable_grad is one of several mechanisms that can enable or
| disable gradients locally see :ref:`locally-disable-grad-doc` for
| more information on how they compare.
|
| .. note::
| This API does not apply to :ref:`forward-mode AD <forward-mode-ad>`.
|
| Example::
| >>> # xdoctest: +SKIP
| >>> x = torch.tensor([1.], requires_grad=True)
| >>> with torch.no_grad():
| ... with torch.enable_grad():
| ... y = x * 2
| >>> y.requires_grad
| True
| >>> y.backward()
| >>> x.grad
| tensor([2.])
| >>> @torch.enable_grad()
| ... def doubler(x):
| ... return x * 2
| >>> with torch.no_grad():
| ... z = doubler(x)
| >>> z.requires_grad
| True
| >>> @torch.enable_grad()
| ... def tripler(x):
| ... return x * 3
| >>> with torch.no_grad():
| ... z = tripler(x)
| >>> z.requires_grad
| True
|
| Method resolution order:
| enable_grad
| torch.utils._contextlib._NoParamDecoratorContextManager
| torch.utils._contextlib._DecoratorContextManager
| builtins.object
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.utils._contextlib._NoParamDecoratorContextManager:
|
| __new__(cls, orig_func: Optional[~F] = None) -> Union[Self, ~F]
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __call__(self, orig_func: ~F) -> ~F
| Call self as a function.
|
| clone(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class finfo(builtins.object)
| Methods defined here:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| bits
|
| dtype
|
| eps
|
| max
|
| min
|
| resolution
|
| smallest_normal
|
| tiny
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class iinfo(builtins.object)
| Methods defined here:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __str__(self, /)
| Return str(self).
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| bits
|
| dtype
|
| max
|
| min
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
class inference_mode(torch.utils._contextlib._DecoratorContextManager)
| inference_mode(mode=True)
|
| Context manager that enables or disables inference mode.
|
| InferenceMode is analogous to :class:`~no_grad` and should be used
| when you are certain your operations will not interact with autograd
| (e.g., during data loading or model evaluation). Compared to
| :class:`~no_grad`, it removes additional overhead by disabling view
| tracking and version counter bumps. It is also more restrictive, in
| that tensors created in this mode cannot be used in computations
| recorded by autograd.
|
| This context manager is thread-local; it does not affect computation
| in other threads.
|
| Also functions as a decorator.
|
| .. note::
| Inference mode is one of several mechanisms that can locally enable
| or disable gradients. See :ref:`locally-disable-grad-doc` for a
| comparison. If avoiding the use of tensors created in inference mode
| in autograd-tracked regions is difficult, consider benchmarking your
| code with and without inference mode to weigh the performance benefits
| against the trade-offs. You can always use :class:`~no_grad` instead.
|
| .. note::
| Unlike some other mechanisms that locally enable or disable grad,
| entering inference_mode also disables :ref:`forward-mode AD <forward-mode-ad>`.
|
| .. warning::
| `inference_mode` does NOT automatically set the model to evaluation mode.
| For proper inference behavior (e.g., disabling dropout, using running statistics
| in batch normalization), you must explicitly set your model to evaluation mode using
| `model.eval()` in addition to using this context manager.
|
| Args:
| mode (bool or function): Either a boolean flag to enable or disable
| inference mode, or a Python function to decorate with inference
| mode enabled.
|
| Example::
| >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_AUTOGRAD)
| >>> import torch
| >>> x = torch.ones(1, 2, 3, requires_grad=True)
| >>> with torch.inference_mode():
| ... y = x * x
| >>> y.requires_grad
| False
| >>> # xdoctest: +SKIP("want string isn't quite right")
| >>> y._version
| Traceback (most recent call last):
| File "<stdin>", line 1, in <module>
| RuntimeError: Inference tensors do not track version counter.
| >>> @torch.inference_mode()
| ... def func(x):
| ... return x * x
| >>> out = func(x)
| >>> out.requires_grad
| False
| >>> @torch.inference_mode()
| ... def doubler(x):
| ... return x * 2
| >>> out = doubler(x)
| >>> out.requires_grad
| False
|
| Method resolution order:
| inference_mode
| torch.utils._contextlib._DecoratorContextManager
| builtins.object
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None
|
| __init__(self, mode: bool = True) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| clone(self) -> 'inference_mode'
| Create a copy of this class
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, mode=True)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __call__(self, orig_func: ~F) -> ~F
| Call self as a function.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class layout(builtins.object)
| Methods defined here:
|
| __repr__(self, /)
| Return repr(self).
class memory_format(builtins.object)
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
class no_grad(torch.utils._contextlib._NoParamDecoratorContextManager)
| no_grad() -> None
|
| Context-manager that disables gradient calculation.
|
| Disabling gradient calculation is useful for inference, when you are sure
| that you will not call :meth:`Tensor.backward()`. It will reduce memory
| consumption for computations that would otherwise have `requires_grad=True`.
|
| In this mode, the result of every computation will have
| `requires_grad=False`, even when the inputs have `requires_grad=True`.
| There is an exception! All factory functions, or functions that create
| a new Tensor and take a requires_grad kwarg, will NOT be affected by
| this mode.
|
| This context manager is thread local; it will not affect computation
| in other threads.
|
| Also functions as a decorator.
|
| .. note::
| No-grad is one of several mechanisms that can enable or
| disable gradients locally see :ref:`locally-disable-grad-doc` for
| more information on how they compare.
|
| .. note::
| This API does not apply to :ref:`forward-mode AD <forward-mode-ad>`.
| If you want to disable forward AD for a computation, you can unpack
| your dual tensors.
|
| Example::
| >>> # xdoctest: +SKIP
| >>> x = torch.tensor([1.], requires_grad=True)
| >>> with torch.no_grad():
| ... y = x * 2
| >>> y.requires_grad
| False
| >>> @torch.no_grad()
| ... def doubler(x):
| ... return x * 2
| >>> z = doubler(x)
| >>> z.requires_grad
| False
| >>> @torch.no_grad()
| ... def tripler(x):
| ... return x * 3
| >>> z = tripler(x)
| >>> z.requires_grad
| False
| >>> # factory function exception
| >>> with torch.no_grad():
| ... a = torch.nn.Parameter(torch.rand(10))
| >>> a.requires_grad
| True
|
| Method resolution order:
| no_grad
| torch.utils._contextlib._NoParamDecoratorContextManager
| torch.utils._contextlib._DecoratorContextManager
| builtins.object
|
| Methods defined here:
|
| __enter__(self) -> None
|
| __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None
|
| __init__(self) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch.utils._contextlib._NoParamDecoratorContextManager:
|
| __new__(cls, orig_func: Optional[~F] = None) -> Union[Self, ~F]
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __call__(self, orig_func: ~F) -> ~F
| Call self as a function.
|
| clone(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.utils._contextlib._DecoratorContextManager:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class qscheme(builtins.object)
| Methods defined here:
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
FUNCTIONS
__getattr__(name)
abs(...)
abs(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Computes the absolute value of each element in :attr:`input`.
.. math::
\text{out}_{i} = |\text{input}_{i}|
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.abs(torch.tensor([-1, -2, 3]))
tensor([ 1, 2, 3])
abs_(...)
absolute(...)
absolute(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.abs`
acos(...)
acos(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the arccosine (in radians) of each element in :attr:`input`.
.. math::
\text{out}_{i} = \cos^{-1}(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.3348, -0.5889, 0.2005, -0.1584])
>>> torch.acos(a)
tensor([ 1.2294, 2.2004, 1.3690, 1.7298])
acos_(...)
acosh(...)
acosh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the inverse hyperbolic cosine of the elements of :attr:`input`.
.. math::
\text{out}_{i} = \cosh^{-1}(\text{input}_{i})
Note:
The domain of the inverse hyperbolic cosine is `[1, inf)` and values outside this range
will be mapped to ``NaN``, except for `+ INF` for which the output is mapped to `+ INF`.
Args:
input (Tensor): the input tensor.
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4).uniform_(1, 2)
>>> a
tensor([ 1.3192, 1.9915, 1.9674, 1.7151 ])
>>> torch.acosh(a)
tensor([ 0.7791, 1.3120, 1.2979, 1.1341 ])
acosh_(...)
adaptive_avg_pool1d(...)
adaptive_avg_pool1d(input, output_size) -> Tensor
Applies a 1D adaptive average pooling over an input signal composed of
several input planes.
See :class:`~torch.nn.AdaptiveAvgPool1d` for details and output shape.
Args:
output_size: the target output size (single integer)
adaptive_max_pool1d(...)
add(...)
add(input, other, *, alpha=1, out=None) -> Tensor
Adds :attr:`other`, scaled by :attr:`alpha`, to :attr:`input`.
.. math::
\text{{out}}_i = \text{{input}}_i + \text{{alpha}} \times \text{{other}}_i
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
Args:
input (Tensor): the input tensor.
other (Tensor or Number): the tensor or number to add to :attr:`input`.
Keyword arguments:
alpha (Number): the multiplier for :attr:`other`.
out (Tensor, optional): the output tensor.
Examples::
>>> a = torch.randn(4)
>>> a
tensor([ 0.0202, 1.0985, 1.3506, -0.6056])
>>> torch.add(a, 20)
tensor([ 20.0202, 21.0985, 21.3506, 19.3944])
>>> b = torch.randn(4)
>>> b
tensor([-0.9732, -0.3497, 0.6245, 0.4022])
>>> c = torch.randn(4, 1)
>>> c
tensor([[ 0.3743],
[-1.7724],
[-0.5811],
[-0.8017]])
>>> torch.add(b, c, alpha=10)
tensor([[ 2.7695, 3.3930, 4.3672, 4.1450],
[-18.6971, -18.0736, -17.0994, -17.3216],
[ -6.7845, -6.1610, -5.1868, -5.4090],
[ -8.9902, -8.3667, -7.3925, -7.6147]])
addbmm(...)
addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
Performs a batch matrix-matrix product of matrices stored
in :attr:`batch1` and :attr:`batch2`,
with a reduced add step (all matrix multiplications get accumulated
along the first dimension).
:attr:`input` is added to the final result.
:attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the
same number of matrices.
If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
:math:`(b \times m \times p)` tensor, :attr:`input` must be
:ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
and :attr:`out` will be a :math:`(n \times p)` tensor.
.. math::
out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)
If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
it will not be propagated.
For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and :attr:`alpha`
must be real numbers, otherwise they should be integers.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
Args:
input (Tensor): matrix to be added
batch1 (Tensor): the first batch of matrices to be multiplied
batch2 (Tensor): the second batch of matrices to be multiplied
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for `batch1 @ batch2` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
Example::
>>> M = torch.randn(3, 5)
>>> batch1 = torch.randn(10, 3, 4)
>>> batch2 = torch.randn(10, 4, 5)
>>> torch.addbmm(M, batch1, batch2)
tensor([[ 6.6311, 0.0503, 6.9768, -12.0362, -2.1653],
[ -4.8185, -1.4255, -6.6760, 8.9453, 2.5743],
[ -3.8202, 4.3691, 1.0943, -1.1109, 5.4730]])
addcdiv(...)
addcdiv(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
Performs the element-wise division of :attr:`tensor1` by :attr:`tensor2`,
multiplies the result by the scalar :attr:`value` and adds it to :attr:`input`.
.. warning::
Integer division with addcdiv is no longer supported, and in a future
release addcdiv will perform a true division of tensor1 and tensor2.
The historic addcdiv behavior can be implemented as
(input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype)
for integer inputs and as (input + value * tensor1 / tensor2) for float inputs.
The future addcdiv behavior is just the latter implementation:
(input + value * tensor1 / tensor2), for all dtypes.
.. math::
\text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}
The shapes of :attr:`input`, :attr:`tensor1`, and :attr:`tensor2` must be
:ref:`broadcastable <broadcasting-semantics>`.
For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
a real number, otherwise an integer.
Args:
input (Tensor): the tensor to be added
tensor1 (Tensor): the numerator tensor
tensor2 (Tensor): the denominator tensor
Keyword args:
value (Number, optional): multiplier for :math:`\text{tensor1} / \text{tensor2}`
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.randn(1, 3)
>>> t1 = torch.randn(3, 1)
>>> t2 = torch.randn(1, 3)
>>> torch.addcdiv(t, t1, t2, value=0.1)
tensor([[-0.2312, -3.6496, 0.1312],
[-1.0428, 3.4292, -0.1030],
[-0.5369, -0.9829, 0.0430]])
addcmul(...)
addcmul(input, tensor1, tensor2, *, value=1, out=None) -> Tensor
Performs the element-wise multiplication of :attr:`tensor1`
by :attr:`tensor2`, multiplies the result by the scalar :attr:`value`
and adds it to :attr:`input`.
.. math::
\text{out}_i = \text{input}_i + \text{value} \times \text{tensor1}_i \times \text{tensor2}_i
The shapes of :attr:`tensor`, :attr:`tensor1`, and :attr:`tensor2` must be
:ref:`broadcastable <broadcasting-semantics>`.
For inputs of type `FloatTensor` or `DoubleTensor`, :attr:`value` must be
a real number, otherwise an integer.
Args:
input (Tensor): the tensor to be added
tensor1 (Tensor): the tensor to be multiplied
tensor2 (Tensor): the tensor to be multiplied
Keyword args:
value (Number, optional): multiplier for :math:`tensor1 .* tensor2`
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.randn(1, 3)
>>> t1 = torch.randn(3, 1)
>>> t2 = torch.randn(1, 3)
>>> torch.addcmul(t, t1, t2, value=0.1)
tensor([[-0.8635, -0.6391, 1.6174],
[-0.7617, -0.5879, 1.7388],
[-0.8353, -0.6249, 1.6511]])
addmm(...)
addmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
Performs a matrix multiplication of the matrices :attr:`mat1` and :attr:`mat2`.
The matrix :attr:`input` is added to the final result.
If :attr:`mat1` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
:math:`(m \times p)` tensor, then :attr:`input` must be
:ref:`broadcastable <broadcasting-semantics>` with a :math:`(n \times p)` tensor
and :attr:`out` will be a :math:`(n \times p)` tensor.
:attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
:attr:`mat1` and :attr:`mat2` and the added matrix :attr:`input` respectively.
.. math::
\text{out} = \beta\ \text{input} + \alpha\ (\text{mat1}_i \mathbin{@} \text{mat2}_i)
If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
it will not be propagated.
For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
:attr:`alpha` must be real numbers, otherwise they should be integers.
This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. If
:attr:`input` is sparse the result will have the same layout and if :attr:`out`
is provided it must have the same layout as :attr:`input`.
.. warning::
Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
or may not have autograd support. If you notice missing functionality please
open a feature request.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
Args:
input (Tensor): matrix to be added
mat1 (Tensor): the first matrix to be matrix multiplied
mat2 (Tensor): the second matrix to be matrix multiplied
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
Example::
>>> M = torch.randn(2, 3)
>>> mat1 = torch.randn(2, 3)
>>> mat2 = torch.randn(3, 3)
>>> torch.addmm(M, mat1, mat2)
tensor([[-4.8716, 1.4671, -1.3746],
[ 0.7573, -3.9555, -2.8681]])
.. function:: addmm(input, mat1, mat2, out_dtype, *, beta=1, alpha=1, out=None) -> Tensor
:noindex:
Args:
input (Tensor): matrix to be added
mat1 (Tensor): the first matrix to be matrix multiplied
mat2 (Tensor): the second matrix to be matrix multiplied
out_dtype (dtype): the dtype of the output tensor.
Supported only on CUDA and for torch.float32 given
torch.float16/torch.bfloat16 input dtypes.
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
addmv(...)
addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
Performs a matrix-vector product of the matrix :attr:`mat` and
the vector :attr:`vec`.
The vector :attr:`input` is added to the final result.
If :attr:`mat` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
size `m`, then :attr:`input` must be
:ref:`broadcastable <broadcasting-semantics>` with a 1-D tensor of size `n` and
:attr:`out` will be 1-D tensor of size `n`.
:attr:`alpha` and :attr:`beta` are scaling factors on matrix-vector product between
:attr:`mat` and :attr:`vec` and the added tensor :attr:`input` respectively.
.. math::
\text{out} = \beta\ \text{input} + \alpha\ (\text{mat} \mathbin{@} \text{vec})
If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
it will not be propagated.
For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
:attr:`alpha` must be real numbers, otherwise they should be integers.
Args:
input (Tensor): vector to be added
mat (Tensor): matrix to be matrix multiplied
vec (Tensor): vector to be matrix multiplied
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`mat @ vec` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
Example::
>>> M = torch.randn(2)
>>> mat = torch.randn(2, 3)
>>> vec = torch.randn(3)
>>> torch.addmv(M, mat, vec)
tensor([-0.3768, -5.5565])
addmv_(...)
addr(...)
addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
Performs the outer-product of vectors :attr:`vec1` and :attr:`vec2`
and adds it to the matrix :attr:`input`.
Optional values :attr:`beta` and :attr:`alpha` are scaling factors on the
outer product between :attr:`vec1` and :attr:`vec2` and the added matrix
:attr:`input` respectively.
.. math::
\text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes \text{vec2})
If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
it will not be propagated.
If :attr:`vec1` is a vector of size `n` and :attr:`vec2` is a vector
of size `m`, then :attr:`input` must be
:ref:`broadcastable <broadcasting-semantics>` with a matrix of size
:math:`(n \times m)` and :attr:`out` will be a matrix of size
:math:`(n \times m)`.
Args:
input (Tensor): matrix to be added
vec1 (Tensor): the first vector of the outer product
vec2 (Tensor): the second vector of the outer product
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`\text{vec1} \otimes \text{vec2}` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
Example::
>>> vec1 = torch.arange(1., 4.)
>>> vec2 = torch.arange(1., 3.)
>>> M = torch.zeros(3, 2)
>>> torch.addr(M, vec1, vec2)
tensor([[ 1., 2.],
[ 2., 4.],
[ 3., 6.]])
adjoint(...)
adjoint(input: Tensor) -> Tensor
Returns a view of the tensor conjugated and with the last two dimensions transposed.
``x.adjoint()`` is equivalent to ``x.transpose(-2, -1).conj()`` for complex tensors and
to ``x.transpose(-2, -1)`` for real tensors.
Args:
{input}
Example::
>>> x = torch.arange(4, dtype=torch.float)
>>> A = torch.complex(x, x).reshape(2, 2)
>>> A
tensor([[0.+0.j, 1.+1.j],
[2.+2.j, 3.+3.j]])
>>> A.adjoint()
tensor([[0.-0.j, 2.-2.j],
[1.-1.j, 3.-3.j]])
>>> (A.adjoint() == A.mH).all()
tensor(True)
affine_grid_generator(...)
alias_copy(...)
Performs the same operation as :func:`torch.alias`, but all output tensors
are freshly created instead of aliasing the input.
all(...)
all(input: Tensor, *, out=None) -> Tensor
Tests if all elements in :attr:`input` evaluate to `True`.
.. note:: This function matches the behaviour of NumPy in returning
output of dtype `bool` for all supported dtypes except `uint8`.
For `uint8` the dtype of output is `uint8` itself.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(1, 2).bool()
>>> a
tensor([[False, True]], dtype=torch.bool)
>>> torch.all(a)
tensor(False, dtype=torch.bool)
>>> a = torch.arange(0, 3)
>>> a
tensor([0, 1, 2])
>>> torch.all(a)
tensor(False)
.. function:: all(input, dim, keepdim=False, *, out=None) -> Tensor
:noindex:
For each row of :attr:`input` in the given dimension :attr:`dim`,
returns `True` if all elements in the row evaluate to `True` and `False` otherwise.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(4, 2).bool()
>>> a
tensor([[True, True],
[True, False],
[True, True],
[True, True]], dtype=torch.bool)
>>> torch.all(a, dim=1)
tensor([ True, False, True, True], dtype=torch.bool)
>>> torch.all(a, dim=0)
tensor([ True, False], dtype=torch.bool)
allclose(...)
allclose(input: Tensor, other: Tensor, rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False) -> bool
This function checks if :attr:`input` and :attr:`other` satisfy the condition:
.. math::
\lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other}_i \rvert
elementwise, for all elements of :attr:`input` and :attr:`other`. The behaviour of this function is analogous to
`numpy.allclose <https://numpy.org/doc/stable/reference/generated/numpy.allclose.html>`_
Args:
input (Tensor): first tensor to compare
other (Tensor): second tensor to compare
atol (float, optional): absolute tolerance. Default: 1e-08
rtol (float, optional): relative tolerance. Default: 1e-05
equal_nan (bool, optional): if ``True``, then two ``NaN`` s will be considered equal. Default: ``False``
Example::
>>> torch.allclose(torch.tensor([10000., 1e-07]), torch.tensor([10000.1, 1e-08]))
False
>>> torch.allclose(torch.tensor([10000., 1e-08]), torch.tensor([10000.1, 1e-09]))
True
>>> torch.allclose(torch.tensor([1.0, float('nan')]), torch.tensor([1.0, float('nan')]))
False
>>> torch.allclose(torch.tensor([1.0, float('nan')]), torch.tensor([1.0, float('nan')]), equal_nan=True)
True
alpha_dropout(...)
alpha_dropout_(...)
amax(...)
amax(input, dim=None, keepdim=False, *, out=None) -> Tensor
Returns the maximum value of each slice of the :attr:`input` tensor in the given
dimension(s) :attr:`dim`.
.. note::
The difference between ``max``/``min`` and ``amax``/``amin`` is:
- ``amax``/``amin`` supports reducing on multiple dimensions,
- ``amax``/``amin`` does not return indices.
Both ``amax``/``amin`` evenly distribute gradients between equal values
when there are multiple input elements with the same minimum or maximum value.
For ``max``/``min``:
- If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
- If reduce over one specified axis, only propagate to the indexed element.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.8177, 1.4878, -0.2491, 0.9130],
[-0.7158, 1.1775, 2.0992, 0.4817],
[-0.0053, 0.0164, -1.3738, -0.0507],
[ 1.9700, 1.1106, -1.0318, -1.0816]])
>>> torch.amax(a, 1)
tensor([1.4878, 2.0992, 0.0164, 1.9700])
amin(...)
amin(input, dim=None, keepdim=False, *, out=None) -> Tensor
Returns the minimum value of each slice of the :attr:`input` tensor in the given
dimension(s) :attr:`dim`.
.. note::
The difference between ``max``/``min`` and ``amax``/``amin`` is:
- ``amax``/``amin`` supports reducing on multiple dimensions,
- ``amax``/``amin`` does not return indices.
Both ``amax``/``amin`` evenly distribute gradients between equal values
when there are multiple input elements with the same minimum or maximum value.
For ``max``/``min``:
- If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
- If reduce over one specified axis, only propagate to the indexed element.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.6451, -0.4866, 0.2987, -1.3312],
[-0.5744, 1.2980, 1.8397, -0.2713],
[ 0.9128, 0.9214, -1.7268, -0.2995],
[ 0.9023, 0.4853, 0.9075, -1.6165]])
>>> torch.amin(a, 1)
tensor([-1.3312, -0.5744, -1.7268, -1.6165])
aminmax(...)
aminmax(input, *, dim=None, keepdim=False, out=None) -> (Tensor min, Tensor max)
Computes the minimum and maximum values of the :attr:`input` tensor.
Args:
input (Tensor):
The input tensor
Keyword Args:
dim (Optional[int]):
The dimension along which to compute the values. If `None`,
computes the values over the entire :attr:`input` tensor.
Default is `None`.
keepdim (bool):
If `True`, the reduced dimensions will be kept in the output
tensor as dimensions with size 1 for broadcasting, otherwise
they will be removed, as if calling (:func:`torch.squeeze`).
Default is `False`.
out (Optional[Tuple[Tensor, Tensor]]):
Optional tensors on which to write the result. Must have the same
shape and dtype as the expected output.
Default is `None`.
Returns:
A named tuple `(min, max)` containing the minimum and maximum values.
Raises:
RuntimeError
If any of the dimensions to compute the values over has size 0.
.. note::
NaN values are propagated to the output if at least one value is NaN.
.. seealso::
:func:`torch.amin` computes just the minimum value
:func:`torch.amax` computes just the maximum value
Example::
>>> torch.aminmax(torch.tensor([1, -3, 5]))
torch.return_types.aminmax(
min=tensor(-3),
max=tensor(5))
>>> # aminmax propagates NaNs
>>> torch.aminmax(torch.tensor([1, -3, 5, torch.nan]))
torch.return_types.aminmax(
min=tensor(nan),
max=tensor(nan))
>>> t = torch.arange(10).view(2, 5)
>>> t
tensor([[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9]])
>>> t.aminmax(dim=0, keepdim=True)
torch.return_types.aminmax(
min=tensor([[0, 1, 2, 3, 4]]),
max=tensor([[5, 6, 7, 8, 9]]))
angle(...)
angle(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Computes the element-wise angle (in radians) of the given :attr:`input` tensor.
.. math::
\text{out}_{i} = angle(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
.. note:: Starting in PyTorch 1.8, angle returns pi for negative real numbers,
zero for non-negative real numbers, and propagates NaNs. Previously
the function would return zero for all real numbers and not propagate
floating-point NaNs.
Example::
>>> torch.angle(torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))*180/3.14159
tensor([ 135., 135, -45])
any(...)
any(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Tests if any element in :attr:`input` evaluates to `True`.
.. note:: This function matches the behaviour of NumPy in returning
output of dtype `bool` for all supported dtypes except `uint8`.
For `uint8` the dtype of output is `uint8` itself.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(1, 2).bool()
>>> a
tensor([[False, True]], dtype=torch.bool)
>>> torch.any(a)
tensor(True, dtype=torch.bool)
>>> a = torch.arange(0, 3)
>>> a
tensor([0, 1, 2])
>>> torch.any(a)
tensor(True)
.. function:: any(input, dim, keepdim=False, *, out=None) -> Tensor
:noindex:
For each row of :attr:`input` in the given dimension :attr:`dim`,
returns `True` if any element in the row evaluate to `True` and `False` otherwise.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4, 2) < 0
>>> a
tensor([[ True, True],
[False, True],
[ True, True],
[False, False]])
>>> torch.any(a, 1)
tensor([ True, True, True, False])
>>> torch.any(a, 0)
tensor([True, True])
arange(...)
arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a 1-D tensor of size :math:`\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil`
with values from the interval ``[start, end)`` taken with common difference
:attr:`step` beginning from `start`.
Note: When using floating-point dtypes (especially reduced precision types like ``bfloat16``),
the results may be affected by floating-point rounding behavior. Some values in the sequence
might not be exactly representable in certain floating-point formats, which can lead to
repeated values or unexpected rounding. For precise sequences, it is recommended to use
integer dtypes instead of floating-point dtypes.
Note that non-integer :attr:`step` is subject to floating point rounding errors when
comparing against :attr:`end`; to avoid inconsistency, we advise subtracting a small epsilon from :attr:`end`
in such cases.
.. math::
\text{out}_{{i+1}} = \text{out}_{i} + \text{step}
Args:
start (Number, optional): the starting value for the set of points. Default: ``0``.
end (Number): the ending value for the set of points
step (Number, optional): the gap between each pair of adjacent points. Default: ``1``.
Keyword args:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). If `dtype` is not given, infer the data type from the other input
arguments. If any of `start`, `end`, or `stop` are floating-point, the
`dtype` is inferred to be the default dtype, see
:meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
be `torch.int64`.
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.arange(5)
tensor([ 0, 1, 2, 3, 4])
>>> torch.arange(1, 4)
tensor([ 1, 2, 3])
>>> torch.arange(1, 2.5, 0.5)
tensor([ 1.0000, 1.5000, 2.0000])
arccos(...)
arccos(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.acos`.
arccos_(...)
arccosh(...)
arccosh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.acosh`.
arccosh_(...)
arcsin(...)
arcsin(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.asin`.
arcsin_(...)
arcsinh(...)
arcsinh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.asinh`.
arcsinh_(...)
arctan(...)
arctan(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.atan`.
arctan2(...)
arctan2(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.atan2`.
arctan_(...)
arctanh(...)
arctanh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Alias for :func:`torch.atanh`.
arctanh_(...)
are_deterministic_algorithms_enabled() -> bool
Returns True if the global deterministic flag is turned on. Refer to
:func:`torch.use_deterministic_algorithms` documentation for more details.
argmax(...)
argmax(input) -> LongTensor
Returns the indices of the maximum value of all elements in the :attr:`input` tensor.
This is the second value returned by :meth:`torch.max`. See its
documentation for the exact semantics of this method.
.. note:: If there are multiple maximal values then the indices of the first maximal value are returned.
Args:
input (Tensor): the input tensor.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 1.3398, 0.2663, -0.2686, 0.2450],
[-0.7401, -0.8805, -0.3402, -1.1936],
[ 0.4907, -1.3948, -1.0691, -0.3132],
[-1.6092, 0.5419, -0.2993, 0.3195]])
>>> torch.argmax(a)
tensor(0)
.. function:: argmax(input, dim, keepdim=False) -> LongTensor
:noindex:
Returns the indices of the maximum values of a tensor across a dimension.
This is the second value returned by :meth:`torch.max`. See its
documentation for the exact semantics of this method.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce.
If ``None``, the argmax of the flattened input is returned.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 1.3398, 0.2663, -0.2686, 0.2450],
[-0.7401, -0.8805, -0.3402, -1.1936],
[ 0.4907, -1.3948, -1.0691, -0.3132],
[-1.6092, 0.5419, -0.2993, 0.3195]])
>>> torch.argmax(a, dim=1)
tensor([ 0, 2, 0, 1])
argmin(...)
argmin(input, dim=None, keepdim=False) -> LongTensor
Returns the indices of the minimum value(s) of the flattened tensor or along a dimension
This is the second value returned by :meth:`torch.min`. See its
documentation for the exact semantics of this method.
.. note:: If there are multiple minimal values then the indices of the first minimal value are returned.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce.
If ``None``, the argmin of the flattened input is returned.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.1139, 0.2254, -0.1381, 0.3687],
[ 1.0100, -1.1975, -0.0102, -0.4732],
[-0.9240, 0.1207, -0.7506, -1.0213],
[ 1.7809, -1.2960, 0.9384, 0.1438]])
>>> torch.argmin(a)
tensor(13)
>>> torch.argmin(a, dim=1)
tensor([ 2, 1, 3, 1])
>>> torch.argmin(a, dim=1, keepdim=True)
tensor([[2],
[1],
[3],
[1]])
argsort(...)
argsort(input, dim=-1, descending=False, *, stable=False) -> Tensor
Returns the indices that sort a tensor along a given dimension in ascending
order by value.
This is the second value returned by :meth:`torch.sort`. See its documentation
for the exact semantics of this method.
If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
the order of equivalent elements. If ``False``, the relative order of values
which compare equal is not guaranteed. ``True`` is slower.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to sort along
descending (bool, optional): controls the sorting order (ascending or descending)
Keyword args:
stable (bool, optional): controls the relative order of equivalent elements
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.0785, 1.5267, -0.8521, 0.4065],
[ 0.1598, 0.0788, -0.0745, -1.2700],
[ 1.2208, 1.0722, -0.7064, 1.2564],
[ 0.0669, -0.2318, -0.8229, -0.9280]])
>>> torch.argsort(a, dim=1)
tensor([[2, 0, 3, 1],
[3, 2, 1, 0],
[2, 1, 0, 3],
[3, 2, 1, 0]])
argwhere(...)
argwhere(input) -> Tensor
Returns a tensor containing the indices of all non-zero elements of
:attr:`input`. Each row in the result contains the indices of a non-zero
element in :attr:`input`. The result is sorted lexicographically, with
the last index changing the fastest (C-style).
If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
:attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
non-zero elements in the :attr:`input` tensor.
.. note::
This function is similar to NumPy's `argwhere`.
When :attr:`input` is on CUDA, this function causes host-device synchronization.
Args:
{input}
Example::
>>> t = torch.tensor([1, 0, 1])
>>> torch.argwhere(t)
tensor([[0],
[2]])
>>> t = torch.tensor([[1, 0, 1], [0, 1, 1]])
>>> torch.argwhere(t)
tensor([[0, 0],
[0, 2],
[1, 1],
[1, 2]])
as_strided(...)
as_strided(input, size, stride, storage_offset=None) -> Tensor
Create a view of an existing `torch.Tensor` :attr:`input` with specified
:attr:`size`, :attr:`stride` and :attr:`storage_offset`.
.. warning::
Prefer using other view functions, like :meth:`torch.Tensor.view` or
:meth:`torch.Tensor.expand`, to setting a view's strides manually with
`as_strided`, as this function will throw an error on non-standard Pytorch
backends (that do not have a concept of stride) and the result will depend
on the current layout in memory. The constructed view must only refer to
elements within the Tensor's storage or a runtime error will be thrown.
If the generated view is "overlapped" (with multiple indices referring to
the same element in memory), the behavior of inplace operations on this view
is undefined (and might not throw runtime errors).
Args:
input (Tensor): the input tensor.
size (tuple or ints): the shape of the output tensor
stride (tuple or ints): the stride of the output tensor
storage_offset (int, optional): the offset in the underlying storage of the output tensor.
If ``None``, the storage_offset of the output tensor will match the input tensor.
Example::
>>> x = torch.randn(3, 3)
>>> x
tensor([[ 0.9039, 0.6291, 1.0795],
[ 0.1586, 2.1939, -0.4900],
[-0.1909, -0.7503, 1.9355]])
>>> t = torch.as_strided(x, (2, 2), (1, 2))
>>> t
tensor([[0.9039, 1.0795],
[0.6291, 0.1586]])
>>> t = torch.as_strided(x, (2, 2), (1, 2), 1)
tensor([[0.6291, 0.1586],
[1.0795, 2.1939]])
as_strided_(...)
as_strided_copy(...)
Performs the same operation as :func:`torch.as_strided`, but all output tensors
are freshly created instead of aliasing the input.
as_strided_scatter(...)
as_strided_scatter(input, src, size, stride, storage_offset=None) -> Tensor
Embeds the values of the :attr:`src` tensor into :attr:`input` along
the elements corresponding to the result of calling
input.as_strided(size, stride, storage_offset).
This function returns a tensor with fresh storage; it does not
return a view.
Args:
input (Tensor): the input tensor.
size (tuple or ints): the shape of the output tensor
stride (tuple or ints): the stride of the output tensor
storage_offset (int, optional): the offset in the underlying storage of the output tensor
.. note::
:attr:`src` must be of the proper size in order to be embedded
into :attr:`input`. Specifically, it should have the same shape as
`torch.as_strided(input, size, stride, storage_offset)`
Example::
>>> a = torch.arange(4).reshape(2, 2) + 1
>>> a
tensor([[1, 2],
[3, 4]])
>>> b = torch.zeros(3, 3)
>>> b
tensor([[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]])
>>> torch.as_strided_scatter(b, a, (2, 2), (1, 2))
tensor([[1., 3., 2.],
[4., 0., 0.],
[0., 0., 0.]])
as_tensor(...)
as_tensor(data: Any, *, dtype: Optional[dtype] = None, device: Optional[DeviceLikeType]) -> Tensor
Converts :attr:`data` into a tensor, sharing data and preserving autograd
history if possible.
If :attr:`data` is already a tensor with the requested dtype and device
then :attr:`data` itself is returned, but if :attr:`data` is a
tensor with a different dtype or device then it's copied as if using
`data.to(dtype=dtype, device=device)`.
If :attr:`data` is a NumPy array (an ndarray) with the same dtype and device then a
tensor is constructed using :func:`torch.from_numpy`.
If :attr:`data` is a CuPy array, the returned tensor will be located on the same device as the CuPy array unless
specifically overwritten by :attr:`device` or a default device. The device of the CuPy array is inferred from the
pointer of the array using `cudaPointerGetAttributes` unless :attr:`device` is provided with an explicit device index.
.. seealso::
:func:`torch.tensor` never shares its data and creates a new "leaf tensor" (see :doc:`/notes/autograd`).
Args:
data (array_like): Initial data for the tensor. Can be a list, tuple,
NumPy ``ndarray``, scalar, and other types.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, infers data type from :attr:`data`.
device (:class:`torch.device`, optional): the device of the constructed tensor. If None and data is a tensor
then the device of data is used. If None and data is not a tensor then
the result tensor is constructed on the current device.
Example::
>>> a = numpy.array([1, 2, 3])
>>> t = torch.as_tensor(a)
>>> t
tensor([ 1, 2, 3])
>>> t[0] = -1
>>> a
array([-1, 2, 3])
>>> a = numpy.array([1, 2, 3])
>>> t = torch.as_tensor(a, device=torch.device('cuda'))
>>> t
tensor([ 1, 2, 3])
>>> t[0] = -1
>>> a
array([1, 2, 3])
asarray(...)
asarray(obj: Any, *, dtype: Optional[dtype], device: Optional[DeviceLikeType], copy: Optional[bool] = None, requires_grad: Optional[bool] = None) -> Tensor # noqa: B950
Converts :attr:`obj` to a tensor.
:attr:`obj` can be one of:
1. a tensor
2. a NumPy array or a NumPy scalar
3. a DLPack capsule
4. an object that implements Python's buffer protocol
5. a scalar
6. a sequence of scalars
When :attr:`obj` is a tensor, NumPy array, or DLPack capsule the returned tensor will,
by default, have the same requires_grad as :attr:`obj` (defaulting to False), have the
same datatype, be on the same device, and share memory with it. These properties can be
controlled with the :attr:`dtype`, :attr:`device`, :attr:`copy`, and
:attr:`requires_grad` keyword arguments. If the returned tensor is of a different
datatype, on a different device, or a copy is requested then it will not share its
memory with :attr:`obj`. If :attr:`requires_grad` is ``True`` (or ``None``, and
:attr:`obj` was a tensor with requires_grad set), then the returned tensor will require
a gradient, and if :attr:`obj` is also a tensor with an autograd history then the
returned tensor will have the same history.
When :attr:`obj` is not a tensor, NumPy array, or DLPack capsule but implements Python's
buffer protocol then the buffer is interpreted as an array of bytes grouped according to
the size of the datatype passed to the :attr:`dtype` keyword argument. (If no datatype is
passed then the default floating point datatype is used, instead.) The returned tensor
will have the specified datatype (or default floating point datatype if none is specified)
and, by default, be on the CPU device and share memory with the buffer.
When :attr:`obj` is a NumPy scalar, the returned tensor will be a 0-dimensional tensor on
the CPU and that doesn't share its memory (i.e. ``copy=True``). By default datatype will
be the PyTorch datatype corresponding to the NumPy's scalar's datatype.
When :attr:`obj` is none of the above but a scalar, or a sequence of scalars then the
returned tensor will, by default, infer its datatype from the scalar values, be on the
current default device, and not share its memory.
.. seealso::
:func:`torch.tensor` creates a tensor that always copies the data from the input object.
:func:`torch.from_numpy` creates a tensor that always shares memory from NumPy arrays.
:func:`torch.frombuffer` creates a tensor that always shares memory from objects that
implement the buffer protocol.
:func:`torch.from_dlpack` creates a tensor that always shares memory from
DLPack capsules.
Args:
obj (object): a tensor, NumPy array, DLPack Capsule, object that implements Python's
buffer protocol, scalar, or sequence of scalars.
Keyword args:
dtype (:class:`torch.dtype`, optional): the datatype of the returned tensor.
Default: ``None``, which causes the datatype of the returned tensor to be
inferred from :attr:`obj`.
copy (bool, optional): controls whether the returned tensor shares memory with :attr:`obj`.
Default: ``None``, which causes the returned tensor to share memory with :attr:`obj`
whenever possible. If ``True`` then the returned tensor does not share its memory.
If ``False`` then the returned tensor shares its memory with :attr:`obj` and an
error is thrown if it cannot.
device (:class:`torch.device`, optional): the device of the returned tensor.
Default: ``None``, which causes the device of :attr:`obj` to be used. Or, if
:attr:`obj` is a Python sequence, the current default device will be used.
requires_grad (bool, optional): whether the returned tensor requires grad.
Default: ``None``, which causes requires_grad for the returned tensor to be
inferred from :attr:`obj`. If ``True``, then the returned tensor will require
a gradient, and if :attr:`obj` is also a tensor with an autograd history then
the returned tensor will have the same history.
Example::
>>> a = torch.tensor([1, 2, 3])
>>> # Shares memory with tensor 'a'
>>> b = torch.asarray(a)
>>> a.data_ptr() == b.data_ptr()
True
>>> # Forces memory copy
>>> c = torch.asarray(a, copy=True)
>>> a.data_ptr() == c.data_ptr()
False
>>> a = torch.tensor([1., 2., 3.], requires_grad=True)
>>> b = a + 2
>>> b
tensor([3., 4., 5.], grad_fn=<AddBackward0>)
>>> # Shares memory with tensor 'b', with no grad
>>> c = torch.asarray(b, requires_grad=False)
>>> c
tensor([3., 4., 5.])
>>> # Shares memory with tensor 'b', retaining autograd history
>>> d = torch.asarray(b, requires_grad=True)
>>> d
tensor([3., 4., 5.], grad_fn=<AddBackward0>)
>>> # Shares memory with tensor 'b', retaining autograd history
>>> e = torch.asarray(b)
>>> e
tensor([3., 4., 5.], grad_fn=<AddBackward0>)
>>> array = numpy.array([1, 2, 3])
>>> # Shares memory with array 'array'
>>> t1 = torch.asarray(array)
>>> array.__array_interface__['data'][0] == t1.data_ptr()
True
>>> # Copies memory due to dtype mismatch
>>> t2 = torch.asarray(array, dtype=torch.float32)
>>> array.__array_interface__['data'][0] == t2.data_ptr()
False
>>> scalar = numpy.float64(0.5)
>>> torch.asarray(scalar)
tensor(0.5000, dtype=torch.float64)
asin(...)
asin(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the arcsine of the elements (in radians) in the :attr:`input` tensor.
.. math::
\text{out}_{i} = \sin^{-1}(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-0.5962, 1.4985, -0.4396, 1.4525])
>>> torch.asin(a)
tensor([-0.6387, nan, -0.4552, nan])
asin_(...)
asinh(...)
asinh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the inverse hyperbolic sine of the elements of :attr:`input`.
.. math::
\text{out}_{i} = \sinh^{-1}(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.1606, -1.4267, -1.0899, -1.0250 ])
>>> torch.asinh(a)
tensor([ 0.1599, -1.1534, -0.9435, -0.8990 ])
asinh_(...)
atan(...)
atan(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the arctangent of the elements (in radians) in the :attr:`input` tensor.
.. math::
\text{out}_{i} = \tan^{-1}(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.2341, 0.2539, -0.6256, -0.6448])
>>> torch.atan(a)
tensor([ 0.2299, 0.2487, -0.5591, -0.5727])
atan2(...)
atan2(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
Element-wise arctangent of :math:`\text{input}_{i} / \text{other}_{i}`
with consideration of the quadrant. Returns a new tensor with the signed angles
in radians between vector :math:`(\text{other}_{i}, \text{input}_{i})`
and vector :math:`(1, 0)`. (Note that :math:`\text{other}_{i}`, the second
parameter, is the x-coordinate, while :math:`\text{input}_{i}`, the first
parameter, is the y-coordinate.)
The shapes of ``input`` and ``other`` must be
:ref:`broadcastable <broadcasting-semantics>`.
Args:
input (Tensor): the first input tensor
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.9041, 0.0196, -0.3108, -2.4423])
>>> torch.atan2(a, torch.randn(4))
tensor([ 0.9833, 0.0811, -1.9743, -1.4151])
atan_(...)
atanh(...)
atanh(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the inverse hyperbolic tangent of the elements of :attr:`input`.
Note:
The domain of the inverse hyperbolic tangent is `(-1, 1)` and values outside this range
will be mapped to ``NaN``, except for the values `1` and `-1` for which the output is
mapped to `+/-INF` respectively.
.. math::
\text{out}_{i} = \tanh^{-1}(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4).uniform_(-1, 1)
>>> a
tensor([ -0.9385, 0.2968, -0.8591, -0.1871 ])
>>> torch.atanh(a)
tensor([ -1.7253, 0.3060, -1.2899, -0.1893 ])
atanh_(...)
atleast_1d(*tensors)
Returns a 1-dimensional view of each input tensor with zero dimensions.
Input tensors with one or more dimensions are returned as-is.
Args:
input (Tensor or sequence of Tensors): tensor(s) to be converted to at least 1-dimensional.
Returns:
output (Tensor or tuple of Tensors)
Example::
>>> x = torch.arange(2)
>>> x
tensor([0, 1])
>>> torch.atleast_1d(x)
tensor([0, 1])
>>> x = torch.tensor(1.)
>>> x
tensor(1.)
>>> torch.atleast_1d(x)
tensor([1.])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.)
>>> torch.atleast_1d((x, y))
(tensor([0.5000]), tensor([1.]))
>>> torch.atleast_1d()
()
atleast_2d(*tensors)
Returns a 2-dimensional view of each input tensor with zero dimensions.
Input tensors with two or more dimensions are returned as-is.
Args:
input (Tensor or sequence of Tensors): tensor(s) to be converted to at least 2-dimensional.
Returns:
output (Tensor or tuple of Tensors)
Example::
>>> x = torch.tensor(1.)
>>> x
tensor(1.)
>>> torch.atleast_2d(x)
tensor([[1.]])
>>> x = torch.arange(4).view(2, 2)
>>> x
tensor([[0, 1],
[2, 3]])
>>> torch.atleast_2d(x)
tensor([[0, 1],
[2, 3]])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.)
>>> torch.atleast_2d((x, y))
(tensor([[0.5000]]), tensor([[1.]]))
>>> torch.atleast_2d()
()
atleast_3d(*tensors)
Returns a 3-dimensional view of each input tensor with zero dimensions.
Input tensors with three or more dimensions are returned as-is.
Args:
input (Tensor or sequence of Tensors): tensor(s) to be converted to at least 3-dimensional.
Returns:
output (Tensor or tuple of Tensors)
Example:
>>> x = torch.tensor(0.5)
>>> x
tensor(0.5000)
>>> torch.atleast_3d(x)
tensor([[[0.5000]]])
>>> y = torch.arange(4).view(2, 2)
>>> y
tensor([[0, 1],
[2, 3]])
>>> torch.atleast_3d(y)
tensor([[[0],
[1]],
<BLANKLINE>
[[2],
[3]]])
>>> x = torch.tensor(1).view(1, 1, 1)
>>> x
tensor([[[1]]])
>>> torch.atleast_3d(x)
tensor([[[1]]])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.0)
>>> torch.atleast_3d((x, y))
(tensor([[[0.5000]]]), tensor([[[1.]]]))
>>> torch.atleast_3d()
()
autocast_decrement_nesting(...)
autocast_increment_nesting(...)
avg_pool1d(...)
avg_pool1d(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True) -> Tensor
Applies a 1D average pooling over an input signal composed of several
input planes.
See :class:`~torch.nn.AvgPool1d` for details and output shape.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iW)`
kernel_size: the size of the window. Can be a single number or a
tuple `(kW,)`
stride: the stride of the window. Can be a single number or a tuple
`(sW,)`. Default: :attr:`kernel_size`
padding: implicit zero paddings on both sides of the input. Can be a single
number or a tuple `(padW,)`. Should be at most half of effective kernel
size, that is :math:`((kernelSize - 1) * dilation + 1) / 2`. Default: 0
ceil_mode: when True, will use `ceil` instead of `floor` to compute the
output shape. Default: ``False``
count_include_pad: when True, will include the zero-padding in the
averaging calculation. Default: ``True``
Examples::
>>> # pool of square window of size=3, stride=2
>>> input = torch.tensor([[[1, 2, 3, 4, 5, 6, 7]]], dtype=torch.float32)
>>> F.avg_pool1d(input, kernel_size=3, stride=2)
tensor([[[ 2., 4., 6.]]])
baddbmm(...)
baddbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) -> Tensor
Performs a batch matrix-matrix product of matrices in :attr:`batch1`
and :attr:`batch2`.
:attr:`input` is added to the final result.
:attr:`batch1` and :attr:`batch2` must be 3-D tensors each containing the same
number of matrices.
If :attr:`batch1` is a :math:`(b \times n \times m)` tensor, :attr:`batch2` is a
:math:`(b \times m \times p)` tensor, then :attr:`input` must be
:ref:`broadcastable <broadcasting-semantics>` with a
:math:`(b \times n \times p)` tensor and :attr:`out` will be a
:math:`(b \times n \times p)` tensor. Both :attr:`alpha` and :attr:`beta` mean the
same as the scaling factors used in :meth:`torch.addbmm`.
.. math::
\text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)
If :attr:`beta` is 0, then the content of :attr:`input` will be ignored, and `nan` and `inf` in
it will not be propagated.
For inputs of type `FloatTensor` or `DoubleTensor`, arguments :attr:`beta` and
:attr:`alpha` must be real numbers, otherwise they should be integers.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
Args:
input (Tensor): the tensor to be added
batch1 (Tensor): the first batch of matrices to be multiplied
batch2 (Tensor): the second batch of matrices to be multiplied
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
Example::
>>> M = torch.randn(10, 3, 5)
>>> batch1 = torch.randn(10, 3, 4)
>>> batch2 = torch.randn(10, 4, 5)
>>> torch.baddbmm(M, batch1, batch2).size()
torch.Size([10, 3, 5])
.. function:: baddbmm(input, batch1, batch2, out_dtype, *, beta=1, alpha=1, out=None) -> Tensor
:noindex:
Args:
input (Tensor): the tensor to be added
batch1 (Tensor): the first batch of matrices to be multiplied
batch2 (Tensor): the second batch of matrices to be multiplied
out_dtype (dtype): the dtype of the output tensor.
Supported only on CUDA and for torch.float32 given
torch.float16/torch.bfloat16 input dtypes.
Keyword args:
beta (Number, optional): multiplier for :attr:`input` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`\text{batch1} \mathbin{@} \text{batch2}` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
bartlett_window(...)
bartlett_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Bartlett window function.
.. math::
w[n] = 1 - \left| \frac{2n}{N-1} - 1 \right| = \begin{cases}
\frac{2n}{N - 1} & \text{if } 0 \leq n \leq \frac{N - 1}{2} \\
2 - \frac{2n}{N - 1} & \text{if } \frac{N - 1}{2} < n < N \\
\end{cases},
where :math:`N` is the full window size.
The input :attr:`window_length` is a positive integer controlling the
returned window size. :attr:`periodic` flag determines whether the returned
window trims off the last duplicate value from the symmetric window and is
ready to be used as a periodic window with functions like
:meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
``torch.bartlett_window(L, periodic=True)`` equal to
``torch.bartlett_window(L + 1, periodic=False)[:-1])``.
.. note::
If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
Arguments:
window_length (int): the size of returned window
periodic (bool, optional): If True, returns a window to be used as periodic
function. If False, return a symmetric window.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
batch_norm(...)
batch_norm_backward_elemt(...)
batch_norm_backward_reduce(...)
batch_norm_elemt(...)
batch_norm_gather_stats(...)
batch_norm_gather_stats_with_counts(...)
batch_norm_stats(...)
batch_norm_update_stats(...)
bernoulli(...)
bernoulli(input: Tensor, *, generator: Optional[Generator], out: Optional[Tensor]) -> Tensor
Draws binary random numbers (0 or 1) from a Bernoulli distribution.
The :attr:`input` tensor should be a tensor containing probabilities
to be used for drawing the binary random number.
Hence, all values in :attr:`input` have to be in the range:
:math:`0 \leq \text{input}_i \leq 1`.
The :math:`\text{i}^{th}` element of the output tensor will draw a
value :math:`1` according to the :math:`\text{i}^{th}` probability value given
in :attr:`input`.
.. math::
\text{out}_{i} \sim \mathrm{Bernoulli}(p = \text{input}_{i})
The returned :attr:`out` tensor only has values 0 or 1 and is of the same
shape as :attr:`input`.
:attr:`out` can have integral ``dtype``, but :attr:`input` must have floating
point ``dtype``.
Args:
input (Tensor): the input tensor of probability values for the Bernoulli distribution
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.empty(3, 3).uniform_(0, 1) # generate a uniform random matrix with range [0, 1]
>>> a
tensor([[ 0.1737, 0.0950, 0.3609],
[ 0.7148, 0.0289, 0.2676],
[ 0.9456, 0.8937, 0.7202]])
>>> torch.bernoulli(a)
tensor([[ 1., 0., 0.],
[ 0., 0., 0.],
[ 1., 1., 1.]])
>>> a = torch.ones(3, 3) # probability of drawing "1" is 1
>>> torch.bernoulli(a)
tensor([[ 1., 1., 1.],
[ 1., 1., 1.],
[ 1., 1., 1.]])
>>> a = torch.zeros(3, 3) # probability of drawing "1" is 0
>>> torch.bernoulli(a)
tensor([[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]])
bilinear(...)
bilinear(input1, input2, weight, bias=None) -> Tensor
Applies a bilinear transformation to the incoming data:
:math:`y = x_1^T A x_2 + b`
Shape:
- input1: :math:`(N, *, H_{in1})` where :math:`H_{in1}=\text{in1\_features}`
and :math:`*` means any number of additional dimensions.
All but the last dimension of the inputs should be the same.
- input2: :math:`(N, *, H_{in2})` where :math:`H_{in2}=\text{in2\_features}`
- weight: :math:`(\text{out\_features}, \text{in1\_features},
\text{in2\_features})`
- bias: :math:`(\text{out\_features})`
- output: :math:`(N, *, H_{out})` where :math:`H_{out}=\text{out\_features}`
and all but the last dimension are the same shape as the input.
binary_cross_entropy_with_logits(...)
bincount(...)
bincount(input, weights=None, minlength=0) -> Tensor
Count the frequency of each value in an array of non-negative ints.
The number of bins (size 1) is one larger than the largest value in
:attr:`input` unless :attr:`input` is empty, in which case the result is a
tensor of size 0. If :attr:`minlength` is specified, the number of bins is at least
:attr:`minlength` and if :attr:`input` is empty, then the result is tensor of size
:attr:`minlength` filled with zeros. If ``n`` is the value at position ``i``,
``out[n] += weights[i]`` if :attr:`weights` is specified else
``out[n] += 1``.
Note:
This operation may produce nondeterministic gradients when given tensors on a CUDA device. See :doc:`/notes/randomness` for more information.
Arguments:
input (Tensor): 1-d int tensor
weights (Tensor): optional, weight for each value in the input tensor.
Should be of same size as input tensor.
minlength (int): optional, minimum number of bins. Should be non-negative.
Returns:
output (Tensor): a tensor of shape ``Size([max(input) + 1])`` if
:attr:`input` is non-empty, else ``Size(0)``
Example::
>>> input = torch.randint(0, 8, (5,), dtype=torch.int64)
>>> weights = torch.linspace(0, 1, steps=5)
>>> input, weights
(tensor([4, 3, 6, 3, 4]),
tensor([ 0.0000, 0.2500, 0.5000, 0.7500, 1.0000])
>>> torch.bincount(input)
tensor([0, 0, 0, 2, 2, 0, 1])
>>> input.bincount(weights)
tensor([0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 0.0000, 0.5000])
binomial(...)
bitwise_and(...)
bitwise_and(input, other, *, out=None) -> Tensor
Computes the bitwise AND of :attr:`input` and :attr:`other`. The input tensor must be of
integral or Boolean types. For bool tensors, it computes the logical AND.
Args:
input: the first input tensor
other: the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.bitwise_and(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([1, 0, 3], dtype=torch.int8)
>>> torch.bitwise_and(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
tensor([ False, True, False])
bitwise_left_shift(...)
bitwise_left_shift(input, other, *, out=None) -> Tensor
Computes the left arithmetic shift of :attr:`input` by :attr:`other` bits.
The input tensor must be of integral type. This operator supports
:ref:`broadcasting to a common shape <broadcasting-semantics>` and
:ref:`type promotion <type-promotion-doc>`.
The operation applied is:
.. math::
\text{out}_i = \text{input}_i << \text{other}_i
Args:
input (Tensor or Scalar): the first input tensor
other (Tensor or Scalar): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.bitwise_left_shift(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([-2, -2, 24], dtype=torch.int8)
bitwise_not(...)
bitwise_not(input, *, out=None) -> Tensor
Computes the bitwise NOT of the given input tensor. The input tensor must be of
integral or Boolean types. For bool tensors, it computes the logical NOT.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.bitwise_not(torch.tensor([-1, -2, 3], dtype=torch.int8))
tensor([ 0, 1, -4], dtype=torch.int8)
bitwise_or(...)
bitwise_or(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
Computes the bitwise OR of :attr:`input` and :attr:`other`. The input tensor must be of
integral or Boolean types. For bool tensors, it computes the logical OR.
Args:
input: the first input tensor
other: the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.bitwise_or(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([-1, -2, 3], dtype=torch.int8)
>>> torch.bitwise_or(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
tensor([ True, True, False])
bitwise_right_shift(...)
bitwise_right_shift(input, other, *, out=None) -> Tensor
Computes the right arithmetic shift of :attr:`input` by :attr:`other` bits.
The input tensor must be of integral type. This operator supports
:ref:`broadcasting to a common shape <broadcasting-semantics>` and
:ref:`type promotion <type-promotion-doc>`.
In any case, if the value of the right operand is negative or is greater
or equal to the number of bits in the promoted left operand, the behavior is undefined.
The operation applied is:
.. math::
\text{out}_i = \text{input}_i >> \text{other}_i
Args:
input (Tensor or Scalar): the first input tensor
other (Tensor or Scalar): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.bitwise_right_shift(torch.tensor([-2, -7, 31], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([-1, -7, 3], dtype=torch.int8)
bitwise_xor(...)
bitwise_xor(input, other, *, out=None) -> Tensor
Computes the bitwise XOR of :attr:`input` and :attr:`other`. The input tensor must be of
integral or Boolean types. For bool tensors, it computes the logical XOR.
Args:
input: the first input tensor
other: the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.bitwise_xor(torch.tensor([-1, -2, 3], dtype=torch.int8), torch.tensor([1, 0, 3], dtype=torch.int8))
tensor([-2, -2, 0], dtype=torch.int8)
>>> torch.bitwise_xor(torch.tensor([True, True, False]), torch.tensor([False, True, False]))
tensor([ True, False, False])
blackman_window(...)
blackman_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Blackman window function.
.. math::
w[n] = 0.42 - 0.5 \cos \left( \frac{2 \pi n}{N - 1} \right) + 0.08 \cos \left( \frac{4 \pi n}{N - 1} \right)
where :math:`N` is the full window size.
The input :attr:`window_length` is a positive integer controlling the
returned window size. :attr:`periodic` flag determines whether the returned
window trims off the last duplicate value from the symmetric window and is
ready to be used as a periodic window with functions like
:meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
``torch.blackman_window(L, periodic=True)`` equal to
``torch.blackman_window(L + 1, periodic=False)[:-1]``.
.. note::
If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
Arguments:
window_length (int): the size of returned window
periodic (bool, optional): If True, returns a window to be used as periodic
function. If False, return a symmetric window.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
block_diag(*tensors)
Create a block diagonal matrix from provided tensors.
Args:
*tensors: One or more tensors with 0, 1, or 2 dimensions.
Returns:
Tensor: A 2 dimensional tensor with all the input tensors arranged in
order such that their upper left and lower right corners are
diagonally adjacent. All other elements are set to 0.
Example::
>>> import torch
>>> A = torch.tensor([[0, 1], [1, 0]])
>>> B = torch.tensor([[3, 4, 5], [6, 7, 8]])
>>> C = torch.tensor(7)
>>> D = torch.tensor([1, 2, 3])
>>> E = torch.tensor([[4], [5], [6]])
>>> torch.block_diag(A, B, C, D, E)
tensor([[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 3, 4, 5, 0, 0, 0, 0, 0],
[0, 0, 6, 7, 8, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 7, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 2, 3, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 5],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 6]])
bmm(...)
bmm(input, mat2, *, out=None) -> Tensor
Performs a batch matrix-matrix product of matrices stored in :attr:`input`
and :attr:`mat2`.
:attr:`input` and :attr:`mat2` must be 3-D tensors each containing
the same number of matrices.
If :attr:`input` is a :math:`(b \times n \times m)` tensor, :attr:`mat2` is a
:math:`(b \times m \times p)` tensor, :attr:`out` will be a
:math:`(b \times n \times p)` tensor.
.. math::
\text{out}_i = \text{input}_i \mathbin{@} \text{mat2}_i
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
.. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
For broadcasting matrix products, see :func:`torch.matmul`.
Args:
input (Tensor): the first batch of matrices to be multiplied
mat2 (Tensor): the second batch of matrices to be multiplied
Keyword Args:
out (Tensor, optional): the output tensor.
Example::
>>> input = torch.randn(10, 3, 4)
>>> mat2 = torch.randn(10, 4, 5)
>>> res = torch.bmm(input, mat2)
>>> res.size()
torch.Size([10, 3, 5])
.. function:: bmm(input, mat2, out_dtype, *, out=None) -> Tensor
:noindex:
Args:
input (Tensor): the first batch of matrices to be multiplied
mat2 (Tensor): the second batch of matrices to be multiplied
out_dtype (dtype): the dtype of the output tensor.
Supported only on CUDA and for torch.float32 given
torch.float16/torch.bfloat16 input dtypes.
Keyword Args:
out (Tensor, optional): the output tensor.
broadcast_tensors(*tensors)
broadcast_tensors(*tensors) -> List of Tensors
Broadcasts the given tensors according to :ref:`broadcasting-semantics`.
Args:
*tensors: any number of tensors of the same type
.. warning::
More than one element of a broadcasted tensor may refer to a single
memory location. As a result, in-place operations (especially ones that
are vectorized) may result in incorrect behavior. If you need to write
to the tensors, please clone them first.
Example::
>>> x = torch.arange(3).view(1, 3)
>>> y = torch.arange(2).view(2, 1)
>>> a, b = torch.broadcast_tensors(x, y)
>>> a.size()
torch.Size([2, 3])
>>> a
tensor([[0, 1, 2],
[0, 1, 2]])
broadcast_to(...)
broadcast_to(input, shape) -> Tensor
Broadcasts :attr:`input` to the shape :attr:`\shape`.
Equivalent to calling ``input.expand(shape)``. See :meth:`~Tensor.expand` for details.
Args:
input (Tensor): the input tensor.
shape (list, tuple, or :class:`torch.Size`): the new shape.
Example::
>>> x = torch.tensor([1, 2, 3])
>>> torch.broadcast_to(x, (3, 3))
tensor([[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])
bucketize(...)
bucketize(input, boundaries, *, out_int32=False, right=False, out=None) -> Tensor
Returns the indices of the buckets to which each value in the :attr:`input` belongs, where the
boundaries of the buckets are set by :attr:`boundaries`. Return a new tensor with the same size
as :attr:`input`. If :attr:`right` is False (default), then the left boundary is open. Note that
this behavior is opposite the behavior of
`numpy.digitize <https://numpy.org/doc/stable/reference/generated/numpy.digitize.html>`_.
More formally, the returned index satisfies the following rules:
.. list-table::
:widths: 15 85
:header-rows: 1
* - :attr:`right`
- *returned index satisfies*
* - False
- ``boundaries[i-1] < input[m][n]...[l][x] <= boundaries[i]``
* - True
- ``boundaries[i-1] <= input[m][n]...[l][x] < boundaries[i]``
Args:
input (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
boundaries (Tensor): 1-D tensor, must contain a strictly increasing sequence, or the return value is undefined.
Keyword args:
out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
Default value is False, i.e. default output data type is torch.int64.
right (bool, optional): determines the behavior for values in :attr:`boundaries`. See the table above.
out (Tensor, optional): the output tensor, must be the same size as :attr:`input` if provided.
Example::
>>> boundaries = torch.tensor([1, 3, 5, 7, 9])
>>> boundaries
tensor([1, 3, 5, 7, 9])
>>> v = torch.tensor([[3, 6, 9], [3, 6, 9]])
>>> v
tensor([[3, 6, 9],
[3, 6, 9]])
>>> torch.bucketize(v, boundaries)
tensor([[1, 3, 4],
[1, 3, 4]])
>>> torch.bucketize(v, boundaries, right=True)
tensor([[2, 3, 5],
[2, 3, 5]])
can_cast(...)
can_cast(from_, to) -> bool
Determines if a type conversion is allowed under PyTorch casting rules
described in the type promotion :ref:`documentation <type-promotion-doc>`.
Args:
from\_ (dtype): The original :class:`torch.dtype`.
to (dtype): The target :class:`torch.dtype`.
Example::
>>> torch.can_cast(torch.double, torch.float)
True
>>> torch.can_cast(torch.float, torch.int)
False
cartesian_prod(*tensors: torch.Tensor) -> torch.Tensor
Do cartesian product of the given sequence of tensors. The behavior is similar to
python's `itertools.product`.
Args:
*tensors: any number of 1 dimensional tensors.
Returns:
Tensor: A tensor equivalent to converting all the input tensors into lists,
do `itertools.product` on these lists, and finally convert the resulting list
into tensor.
Example::
>>> import itertools
>>> a = [1, 2, 3]
>>> b = [4, 5]
>>> list(itertools.product(a, b))
[(1, 4), (1, 5), (2, 4), (2, 5), (3, 4), (3, 5)]
>>> tensor_a = torch.tensor(a)
>>> tensor_b = torch.tensor(b)
>>> torch.cartesian_prod(tensor_a, tensor_b)
tensor([[1, 4],
[1, 5],
[2, 4],
[2, 5],
[3, 4],
[3, 5]])
cat(...)
cat(tensors, dim=0, *, out=None) -> Tensor
Concatenates the given sequence of tensors in :attr:`tensors` in the given dimension.
All tensors must either have the same shape (except in the concatenating
dimension) or be a 1-D empty tensor with size ``(0,)``.
:func:`torch.cat` can be seen as an inverse operation for :func:`torch.split`
and :func:`torch.chunk`.
:func:`torch.cat` can be best understood via examples.
.. seealso::
:func:`torch.stack` concatenates the given sequence along a new dimension.
Args:
tensors (sequence of Tensors): Non-empty tensors provided must have the same shape,
except in the cat dimension.
dim (int, optional): the dimension over which the tensors are concatenated
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.randn(2, 3)
>>> x
tensor([[ 0.6580, -1.0969, -0.4614],
[-0.1034, -0.5790, 0.1497]])
>>> torch.cat((x, x, x), 0)
tensor([[ 0.6580, -1.0969, -0.4614],
[-0.1034, -0.5790, 0.1497],
[ 0.6580, -1.0969, -0.4614],
[-0.1034, -0.5790, 0.1497],
[ 0.6580, -1.0969, -0.4614],
[-0.1034, -0.5790, 0.1497]])
>>> torch.cat((x, x, x), 1)
tensor([[ 0.6580, -1.0969, -0.4614, 0.6580, -1.0969, -0.4614, 0.6580,
-1.0969, -0.4614],
[-0.1034, -0.5790, 0.1497, -0.1034, -0.5790, 0.1497, -0.1034,
-0.5790, 0.1497]])
ccol_indices_copy(...)
cdist(x1, x2, p=2.0, compute_mode='use_mm_for_euclid_dist_if_necessary')
Computes batched the p-norm distance between each pair of the two collections of row vectors.
Args:
x1 (Tensor): input tensor where the last two dimensions represent the points and the feature dimension respectively.
The shape can be :math:`D_1 \times D_2 \times \cdots \times D_n \times P \times M`,
where :math:`P` is the number of points and :math:`M` is the feature dimension.
x2 (Tensor): input tensor where the last two dimensions also represent the points and the feature dimension respectively.
The shape can be :math:`D_1' \times D_2' \times \cdots \times D_m' \times R \times M`,
where :math:`R` is the number of points and :math:`M` is the feature dimension,
which should match the feature dimension of `x1`.
p: p value for the p-norm distance to calculate between each vector pair
:math:`\in [0, \infty]`.
compute_mode:
'use_mm_for_euclid_dist_if_necessary' - will use matrix multiplication approach to calculate
euclidean distance (p = 2) if P > 25 or R > 25
'use_mm_for_euclid_dist' - will always use matrix multiplication approach to calculate
euclidean distance (p = 2)
'donot_use_mm_for_euclid_dist' - will never use matrix multiplication approach to calculate
euclidean distance (p = 2)
Default: use_mm_for_euclid_dist_if_necessary.
If x1 has shape :math:`B \times P \times M` and x2 has shape :math:`B \times R \times M` then the
output will have shape :math:`B \times P \times R`.
This function is equivalent to `scipy.spatial.distance.cdist(input,'minkowski', p=p)`
if :math:`p \in (0, \infty)`. When :math:`p = 0` it is equivalent to
`scipy.spatial.distance.cdist(input, 'hamming') * M`. When :math:`p = \infty`, the closest
scipy function is `scipy.spatial.distance.cdist(xn, lambda x, y: np.abs(x - y).max())`.
Example:
>>> a = torch.tensor([[0.9041, 0.0196], [-0.3108, -2.4423], [-0.4821, 1.059]])
>>> a
tensor([[ 0.9041, 0.0196],
[-0.3108, -2.4423],
[-0.4821, 1.0590]])
>>> b = torch.tensor([[-2.1763, -0.4713], [-0.6986, 1.3702]])
>>> b
tensor([[-2.1763, -0.4713],
[-0.6986, 1.3702]])
>>> torch.cdist(a, b, p=2)
tensor([[3.1193, 2.0959],
[2.7138, 3.8322],
[2.2830, 0.3791]])
ceil(...)
ceil(input, *, out=None) -> Tensor
Returns a new tensor with the ceil of the elements of :attr:`input`,
the smallest integer greater than or equal to each element.
For integer inputs, follows the array-api convention of returning a
copy of the input tensor.
.. math::
\text{out}_{i} = \left\lceil \text{input}_{i} \right\rceil
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-0.6341, -1.4208, -1.0900, 0.5826])
>>> torch.ceil(a)
tensor([-0., -1., -1., 1.])
ceil_(...)
celu(...)
celu_(...)
celu_(input, alpha=1.) -> Tensor
In-place version of :func:`~celu`.
chain_matmul(*matrices, out=None)
Returns the matrix product of the :math:`N` 2-D tensors. This product is efficiently computed
using the matrix chain order algorithm which selects the order in which incurs the lowest cost in terms
of arithmetic operations (`[CLRS]`_). Note that since this is a function to compute the product, :math:`N`
needs to be greater than or equal to 2; if equal to 2 then a trivial matrix-matrix product is returned.
If :math:`N` is 1, then this is a no-op - the original matrix is returned as is.
.. warning::
:func:`torch.chain_matmul` is deprecated and will be removed in a future PyTorch release.
Use :func:`torch.linalg.multi_dot` instead, which accepts a list of two or more tensors
rather than multiple arguments.
Args:
matrices (Tensors...): a sequence of 2 or more 2-D tensors whose product is to be determined.
out (Tensor, optional): the output tensor. Ignored if :attr:`out` = ``None``.
Returns:
Tensor: if the :math:`i^{th}` tensor was of dimensions :math:`p_{i} \times p_{i + 1}`, then the product
would be of dimensions :math:`p_{1} \times p_{N + 1}`.
Example::
>>> # xdoctest: +SKIP
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> a = torch.randn(3, 4)
>>> b = torch.randn(4, 5)
>>> c = torch.randn(5, 6)
>>> d = torch.randn(6, 7)
>>> # will raise a deprecation warning
>>> torch.chain_matmul(a, b, c, d)
tensor([[ -2.3375, -3.9790, -4.1119, -6.6577, 9.5609, -11.5095, -3.2614],
[ 21.4038, 3.3378, -8.4982, -5.2457, -10.2561, -2.4684, 2.7163],
[ -0.9647, -5.8917, -2.3213, -5.2284, 12.8615, -12.2816, -2.5095]])
.. _`[CLRS]`: https://mitpress.mit.edu/books/introduction-algorithms-third-edition
channel_shuffle(...)
channel_shuffle(input, groups) -> Tensor
Divide the channels in a tensor of shape :math:`(*, C , H, W)`
into g groups and rearrange them as :math:`(*, C \frac g, g, H, W)`,
while keeping the original tensor shape.
See :class:`~torch.nn.ChannelShuffle` for details.
Args:
input (Tensor): the input tensor
groups (int): number of groups to divide channels in and rearrange.
Examples::
>>> input = torch.randn(1, 4, 2, 2)
>>> print(input)
[[[[1, 2],
[3, 4]],
[[5, 6],
[7, 8]],
[[9, 10],
[11, 12]],
[[13, 14],
[15, 16]],
]]
>>> output = torch.nn.functional.channel_shuffle(input, 2)
>>> print(output)
[[[[1, 2],
[3, 4]],
[[9, 10],
[11, 12]],
[[5, 6],
[7, 8]],
[[13, 14],
[15, 16]],
]]
cholesky(...)
cholesky(input, upper=False, *, out=None) -> Tensor
Computes the Cholesky decomposition of a symmetric positive-definite
matrix :math:`A` or for batches of symmetric positive-definite matrices.
If :attr:`upper` is ``True``, the returned matrix ``U`` is upper-triangular, and
the decomposition has the form:
.. math::
A = U^TU
If :attr:`upper` is ``False``, the returned matrix ``L`` is lower-triangular, and
the decomposition has the form:
.. math::
A = LL^T
If :attr:`upper` is ``True``, and :math:`A` is a batch of symmetric positive-definite
matrices, then the returned tensor will be composed of upper-triangular Cholesky factors
of each of the individual matrices. Similarly, when :attr:`upper` is ``False``, the returned
tensor will be composed of lower-triangular Cholesky factors of each of the individual
matrices.
.. warning::
:func:`torch.cholesky` is deprecated in favor of :func:`torch.linalg.cholesky`
and will be removed in a future PyTorch release.
``L = torch.cholesky(A)`` should be replaced with
.. code:: python
L = torch.linalg.cholesky(A)
``U = torch.cholesky(A, upper=True)`` should be replaced with
.. code:: python
U = torch.linalg.cholesky(A).mH
This transform will produce equivalent results for all valid (symmetric positive definite) inputs.
Args:
input (Tensor): the input tensor :math:`A` of size :math:`(*, n, n)` where `*` is zero or more
batch dimensions consisting of symmetric positive-definite matrices.
upper (bool, optional): flag that indicates whether to return a
upper or lower triangular matrix. Default: ``False``
Keyword args:
out (Tensor, optional): the output matrix
Example::
>>> a = torch.randn(3, 3)
>>> a = a @ a.mT + 1e-3 # make symmetric positive-definite
>>> l = torch.cholesky(a)
>>> a
tensor([[ 2.4112, -0.7486, 1.4551],
[-0.7486, 1.3544, 0.1294],
[ 1.4551, 0.1294, 1.6724]])
>>> l
tensor([[ 1.5528, 0.0000, 0.0000],
[-0.4821, 1.0592, 0.0000],
[ 0.9371, 0.5487, 0.7023]])
>>> l @ l.mT
tensor([[ 2.4112, -0.7486, 1.4551],
[-0.7486, 1.3544, 0.1294],
[ 1.4551, 0.1294, 1.6724]])
>>> a = torch.randn(3, 2, 2) # Example for batched input
>>> a = a @ a.mT + 1e-03 # make symmetric positive-definite
>>> l = torch.cholesky(a)
>>> z = l @ l.mT
>>> torch.dist(z, a)
tensor(2.3842e-07)
cholesky_inverse(...)
cholesky_inverse(L, upper=False, *, out=None) -> Tensor
Computes the inverse of a complex Hermitian or real symmetric
positive-definite matrix given its Cholesky decomposition.
Let :math:`A` be a complex Hermitian or real symmetric positive-definite matrix,
and :math:`L` its Cholesky decomposition such that:
.. math::
A = LL^{\text{H}}
where :math:`L^{\text{H}}` is the conjugate transpose when :math:`L` is complex,
and the transpose when :math:`L` is real-valued.
Computes the inverse matrix :math:`A^{-1}`.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :math:`A` is a batch of matrices
then the output has the same batch dimensions.
Args:
L (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
consisting of lower or upper triangular Cholesky decompositions of
symmetric or Hermitian positive-definite matrices.
upper (bool, optional): flag that indicates whether :math:`L` is lower triangular
or upper triangular. Default: ``False``
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Example::
>>> A = torch.randn(3, 3)
>>> A = A @ A.T + torch.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix
>>> L = torch.linalg.cholesky(A) # Extract Cholesky decomposition
>>> torch.cholesky_inverse(L)
tensor([[ 1.9314, 1.2251, -0.0889],
[ 1.2251, 2.4439, 0.2122],
[-0.0889, 0.2122, 0.1412]])
>>> A.inverse()
tensor([[ 1.9314, 1.2251, -0.0889],
[ 1.2251, 2.4439, 0.2122],
[-0.0889, 0.2122, 0.1412]])
>>> A = torch.randn(3, 2, 2, dtype=torch.complex64)
>>> A = A @ A.mH + torch.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices
>>> L = torch.linalg.cholesky(A)
>>> torch.dist(torch.inverse(A), torch.cholesky_inverse(L))
tensor(5.6358e-7)
cholesky_solve(...)
cholesky_solve(B, L, upper=False, *, out=None) -> Tensor
Computes the solution of a system of linear equations with complex Hermitian
or real symmetric positive-definite lhs given its Cholesky decomposition.
Let :math:`A` be a complex Hermitian or real symmetric positive-definite matrix,
and :math:`L` its Cholesky decomposition such that:
.. math::
A = LL^{\text{H}}
where :math:`L^{\text{H}}` is the conjugate transpose when :math:`L` is complex,
and the transpose when :math:`L` is real-valued.
Returns the solution :math:`X` of the following linear system:
.. math::
AX = B
Supports inputs of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if :math:`A` or :math:`B` is a batch of matrices
then the output has the same batch dimensions.
Args:
B (Tensor): right-hand side tensor of shape `(*, n, k)`
where :math:`*` is zero or more batch dimensions
L (Tensor): tensor of shape `(*, n, n)` where `*` is zero or more batch dimensions
consisting of lower or upper triangular Cholesky decompositions of
symmetric or Hermitian positive-definite matrices.
upper (bool, optional): flag that indicates whether :math:`L` is lower triangular
or upper triangular. Default: ``False``.
Keyword args:
out (Tensor, optional): output tensor. Ignored if `None`. Default: `None`.
Example::
>>> A = torch.randn(3, 3)
>>> A = A @ A.T + torch.eye(3) * 1e-3 # Creates a symmetric positive-definite matrix
>>> L = torch.linalg.cholesky(A) # Extract Cholesky decomposition
>>> B = torch.randn(3, 2)
>>> torch.cholesky_solve(B, L)
tensor([[ -8.1625, 19.6097],
[ -5.8398, 14.2387],
[ -4.3771, 10.4173]])
>>> A.inverse() @ B
tensor([[ -8.1626, 19.6097],
[ -5.8398, 14.2387],
[ -4.3771, 10.4173]])
>>> A = torch.randn(3, 2, 2, dtype=torch.complex64)
>>> A = A @ A.mH + torch.eye(2) * 1e-3 # Batch of Hermitian positive-definite matrices
>>> L = torch.linalg.cholesky(A)
>>> B = torch.randn(2, 1, dtype=torch.complex64)
>>> X = torch.cholesky_solve(B, L)
>>> torch.dist(X, A.inverse() @ B)
tensor(1.6881e-5)
choose_qparams_optimized(...)
chunk(...)
chunk(input: Tensor, chunks: int, dim: int = 0) -> Tuple[Tensor, ...]
Attempts to split a tensor into the specified number of chunks. Each chunk is a view of
the input tensor.
.. note::
This function may return fewer than the specified number of chunks!
.. seealso::
:func:`torch.tensor_split` a function that always returns exactly the specified number of chunks
If the tensor size along the given dimension :attr:`dim` is divisible by :attr:`chunks`,
all returned chunks will be the same size.
If the tensor size along the given dimension :attr:`dim` is not divisible by :attr:`chunks`,
all returned chunks will be the same size, except the last one.
If such division is not possible, this function may return fewer
than the specified number of chunks.
Arguments:
input (Tensor): the tensor to split
chunks (int): number of chunks to return
dim (int): dimension along which to split the tensor
Example:
>>> torch.arange(11).chunk(6)
(tensor([0, 1]),
tensor([2, 3]),
tensor([4, 5]),
tensor([6, 7]),
tensor([8, 9]),
tensor([10]))
>>> torch.arange(12).chunk(6)
(tensor([0, 1]),
tensor([2, 3]),
tensor([4, 5]),
tensor([6, 7]),
tensor([8, 9]),
tensor([10, 11]))
>>> torch.arange(13).chunk(6)
(tensor([0, 1, 2]),
tensor([3, 4, 5]),
tensor([6, 7, 8]),
tensor([ 9, 10, 11]),
tensor([12]))
clamp(...)
clamp(input, min=None, max=None, *, out=None) -> Tensor
Clamps all elements in :attr:`input` into the range `[` :attr:`min`, :attr:`max` `]`.
Letting min_value and max_value be :attr:`min` and :attr:`max`, respectively, this returns:
.. math::
y_i = \min(\max(x_i, \text{min\_value}_i), \text{max\_value}_i)
If :attr:`min` is ``None``, there is no lower bound.
Or, if :attr:`max` is ``None`` there is no upper bound.
.. note::
If :attr:`min` is greater than :attr:`max` :func:`torch.clamp(..., min, max) <torch.clamp>`
sets all elements in :attr:`input` to the value of :attr:`max`.
Args:
input (Tensor): the input tensor.
min (Number or Tensor, optional): lower-bound of the range to be clamped to
max (Number or Tensor, optional): upper-bound of the range to be clamped to
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-1.7120, 0.1734, -0.0478, -0.0922])
>>> torch.clamp(a, min=-0.5, max=0.5)
tensor([-0.5000, 0.1734, -0.0478, -0.0922])
>>> min = torch.linspace(-1, 1, steps=4)
>>> torch.clamp(a, min=min)
tensor([-1.0000, 0.1734, 0.3333, 1.0000])
clamp_(...)
clamp_max(...)
clamp_max_(...)
clamp_min(...)
clamp_min_(...)
clear_autocast_cache(...)
clip(...)
clip(input, min=None, max=None, *, out=None) -> Tensor
Alias for :func:`torch.clamp`.
clip_(...)
clone(...)
clone(input, *, memory_format=torch.preserve_format) -> Tensor
Returns a copy of :attr:`input`.
.. note::
This function is differentiable, so gradients will flow back from the
result of this operation to :attr:`input`. To create a tensor without an
autograd relationship to :attr:`input` see :meth:`~Tensor.detach`.
In addition, when ``torch.preserve_format`` is used:
If the input tensor is dense (i.e., non-overlapping strided),
its memory format (including strides) is retained.
Otherwise (e.g., a non-dense view like a stepped slice),
the output is converted to the dense (contiguous) format.
Args:
input (Tensor): the input tensor.
Keyword args:
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned tensor. Default: ``torch.preserve_format``.
col_indices_copy(...)
Performs the same operation as :func:`torch.col_indices`, but all output tensors
are freshly created instead of aliasing the input.
column_stack(...)
column_stack(tensors, *, out=None) -> Tensor
Creates a new tensor by horizontally stacking the tensors in :attr:`tensors`.
Equivalent to ``torch.hstack(tensors)``, except each zero or one dimensional tensor ``t``
in :attr:`tensors` is first reshaped into a ``(t.numel(), 1)`` column before being stacked horizontally.
Args:
tensors (sequence of Tensors): sequence of tensors to concatenate
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([1, 2, 3])
>>> b = torch.tensor([4, 5, 6])
>>> torch.column_stack((a, b))
tensor([[1, 4],
[2, 5],
[3, 6]])
>>> a = torch.arange(5)
>>> b = torch.arange(10).reshape(5, 2)
>>> torch.column_stack((a, b, b))
tensor([[0, 0, 1, 0, 1],
[1, 2, 3, 2, 3],
[2, 4, 5, 4, 5],
[3, 6, 7, 6, 7],
[4, 8, 9, 8, 9]])
combinations(...)
combinations(input: Tensor, r: int = 2, with_replacement: bool = False) -> seq
Compute combinations of length :math:`r` of the given tensor. The behavior is similar to
python's `itertools.combinations` when `with_replacement` is set to `False`, and
`itertools.combinations_with_replacement` when `with_replacement` is set to `True`.
Arguments:
input (Tensor): 1D vector.
r (int, optional): number of elements to combine
with_replacement (bool, optional): whether to allow duplication in combination
Returns:
Tensor: A tensor equivalent to converting all the input tensors into lists, do
`itertools.combinations` or `itertools.combinations_with_replacement` on these
lists, and finally convert the resulting list into tensor.
Example::
>>> a = [1, 2, 3]
>>> list(itertools.combinations(a, r=2))
[(1, 2), (1, 3), (2, 3)]
>>> list(itertools.combinations(a, r=3))
[(1, 2, 3)]
>>> list(itertools.combinations_with_replacement(a, r=2))
[(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)]
>>> tensor_a = torch.tensor(a)
>>> torch.combinations(tensor_a)
tensor([[1, 2],
[1, 3],
[2, 3]])
>>> torch.combinations(tensor_a, r=3)
tensor([[1, 2, 3]])
>>> torch.combinations(tensor_a, with_replacement=True)
tensor([[1, 1],
[1, 2],
[1, 3],
[2, 2],
[2, 3],
[3, 3]])
compile(model: collections.abc.Callable[~_InputT, ~_RetT] | None = None, *, fullgraph: bool = False, dynamic: bool | None = None, backend: str | collections.abc.Callable | None = None, mode: str | None = None, options: dict[str, str | int | bool | collections.abc.Callable] | None = None, name: str | None = None, disable: bool = False, recompile_limit: int | None = None, isolate_recompiles: bool = False, shapes_spec: Any = None) -> collections.abc.Callable[[collections.abc.Callable[~_InputT, ~_RetT]], collections.abc.Callable[~_InputT, ~_RetT]] | collections.abc.Callable[~_InputT, ~_RetT]
Optimizes given model/function using TorchDynamo and specified backend.
If you are compiling an :class:`torch.nn.Module`, you can also use :meth:`torch.nn.Module.compile`
to compile the module inplace without changing its structure.
Concretely, for every frame executed within the compiled region, we will attempt
to compile it and cache the compiled result on the code object for future
use. A single frame may be compiled multiple times if previous compiled
results are not applicable for subsequent calls (this is called a "guard
failure"), you can use TORCH_LOGS=guards to debug these situations.
Multiple compiled results can be associated with a frame up to
``torch._dynamo.config.recompile_limit``, which defaults to 8; at which
point we will fall back to eager. Note that compile caches are per
*code object*, not frame; if you dynamically create multiple copies of a
function, they will all share the same code cache.
Args:
model (Callable or None): Module/function to optimize
fullgraph (bool): If False (default), torch.compile attempts to discover compilable regions
in the function that it will optimize. If True, then we require that the entire function be
capturable into a single graph. If this is not possible (that is, if there are graph breaks),
then this will raise an error. This also opts into unbacked semantics, notably it will turn on
capture_scalar_outputs and capture_dynamic_output_shape_ops on by default.
dynamic (bool or None): Use dynamic shape tracing. When this is True, we will up-front attempt
to generate a kernel that is as dynamic as possible to avoid recompilations when
sizes change. This may not always work as some operations/optimizations will
force specialization; use TORCH_LOGS=dynamic to debug overspecialization.
When this is False, we will NEVER generate dynamic kernels, we will always specialize.
By default (None), we automatically detect if dynamism has occurred and compile a more
dynamic kernel upon recompile.
backend (str or Callable): backend to be used
- "inductor" is the default backend, which is a good balance between performance and overhead
- Non experimental in-tree backends can be seen with `torch._dynamo.list_backends()`
- Experimental or debug in-tree backends can be seen with `torch._dynamo.list_backends(None)`
- To register an out-of-tree custom backend:
https://docs.pytorch.org/docs/main/user_guide/torch_compiler/torch.compiler_custom_backends.html#registering-custom-backends
mode (str): Can be either "default", "reduce-overhead", "max-autotune" or "max-autotune-no-cudagraphs"
- "default" is the default mode, which is a good balance between performance and overhead
- "reduce-overhead" is a mode that reduces the overhead of python with CUDA graphs,
useful for small batches. Reduction of overhead can come at the cost of more memory
usage, as we will cache the workspace memory required for the invocation so that we
do not have to reallocate it on subsequent runs. Reduction of overhead is not guaranteed
to work; today, we only reduce overhead for CUDA only graphs which do not mutate inputs.
There are other circumstances where CUDA graphs are not applicable; use TORCH_LOGS=perf_hints
to debug.
- "max-autotune" is a mode that leverages Triton or template based matrix multiplications
on supported devices and Triton based convolutions on GPU.
It enables CUDA graphs by default on GPU.
- "max-autotune-no-cudagraphs" is a mode similar to "max-autotune" but without CUDA graphs
- To see the exact configs that each mode sets you can call `torch._inductor.list_mode_options()`
options (dict): A dictionary of options to pass to the backend. Some notable ones to try out are
- `epilogue_fusion` which fuses pointwise ops into templates. Requires `max_autotune` to also be set
- `max_autotune` which will profile to pick the best matmul configuration
- `fallback_random` which is useful when debugging accuracy issues
- `shape_padding` which pads matrix shapes to better align loads on GPUs especially for tensor cores
- `triton.cudagraphs` which will reduce the overhead of python with CUDA graphs
- `trace.enabled` which is the most useful debugging flag to turn on
- `trace.graph_diagram` which will show you a picture of your graph after fusion
- `guard_filter_fn` that controls which dynamo guards are saved with compilations.
This is an unsafe feature and there is no backward compatibility guarantee provided
for dynamo guards as data types.
For stable helper functions to use, see the documentations in `torch.compiler`, for example:
- `torch.compiler.skip_guard_on_inbuilt_nn_modules_unsafe`
- `torch.compiler.skip_guard_on_all_nn_modules_unsafe`
- `torch.compiler.keep_tensor_guards_unsafe`
- For inductor you can see the full list of configs that it supports by calling `torch._inductor.list_options()`
name (str or None): Optional identifier for the compiled region. When supported by downstream
tooling, this is surfaced on wrapped compiled-region higher-order operators and other debug metadata.
disable (bool): Turn torch.compile() into a no-op for testing
recompile_limit (int or None): Maximum number of recompilations allowed for this
``torch.compile()`` call before falling back to eager. If None (default), uses
the global ``torch._dynamo.config.recompile_limit`` (default 8). With
``fullgraph=True``, exceeding the limit raises ``FailOnRecompileLimitHit``.
isolate_recompiles (bool): If True, this ``torch.compile()`` call tracks
recompilations independently. By default, all ``torch.compile()`` calls on the
same function share a single set of compiled entries, so one call's
recompilations count against every other call's limit. With
``isolate_recompiles=True``, each call gets its own isolated set of entries.
Lookups for an isolated compile call will still fall back to entries from
non-isolated compile calls (BC-friendly reuse), but new compilations are
stored separately. ``recompile_limit`` is checked per-region;
``accumulated_recompile_limit`` is a global cap across all regions.
Default-strategy behavior is asymmetric: SKIP decisions (from
``skip_code``, ``@torch._dynamo.skip``, FX-generated code, etc.) are
inherited by isolated regions — those remain skipped. RUN_ONLY persisted
by a non-isolated region hitting its recompile limit does NOT bleed
into isolated regions — each region manages its own RUN_ONLY state.
Default False.
Example::
@torch.compile(options={"triton.cudagraphs": True}, fullgraph=True)
def foo(x):
return torch.sin(x) + torch.cos(x)
complex(...)
complex(real, imag, *, out=None) -> Tensor
Constructs a complex tensor with its real part equal to :attr:`real` and its
imaginary part equal to :attr:`imag`.
Args:
real (Tensor): The real part of the complex tensor. Must be half, float or double.
imag (Tensor): The imaginary part of the complex tensor. Must be same dtype
as :attr:`real`.
Keyword args:
out (Tensor): If the inputs are ``torch.float32``, must be
``torch.complex64``. If the inputs are ``torch.float64``, must be
``torch.complex128``.
Example::
>>> real = torch.tensor([1, 2], dtype=torch.float32)
>>> imag = torch.tensor([3, 4], dtype=torch.float32)
>>> z = torch.complex(real, imag)
>>> z
tensor([(1.+3.j), (2.+4.j)])
>>> z.dtype
torch.complex64
concat(...)
concat(tensors, dim=0, *, out=None) -> Tensor
Alias of :func:`torch.cat`.
concatenate(...)
concatenate(tensors, axis=0, out=None) -> Tensor
Alias of :func:`torch.cat`.
cond(pred: bool | int | float | torch.Tensor, true_fn: collections.abc.Callable, false_fn: collections.abc.Callable, operands: tuple | list = ()) -> Any
Conditionally applies `true_fn` or `false_fn`.
.. warning::
`torch.cond` is a prototype feature in PyTorch. It has limited support for input and output types.
Please look forward to a more stable implementation in a future version of PyTorch.
Read more about feature classification at: https://pytorch.org/blog/pytorch-feature-classification-changes/#prototype
`cond` is structured control flow operator. That is, it is like a Python if-statement,
but has restrictions on `true_fn`, `false_fn`, and `operands` that enable it to be
capturable using torch.compile and torch.export.
Assuming the constraints on `cond`'s arguments are met, `cond` is equivalent to the following::
def cond(pred, true_branch, false_branch, operands):
if pred:
return true_branch(*operands)
else:
return false_branch(*operands)
Args:
pred (Union[bool, torch.Tensor]): A boolean expression or a tensor with one element,
indicating which branch function to apply.
true_fn (Callable): A callable function (a -> b) that is within the
scope that is being traced.
false_fn (Callable): A callable function (a -> b) that is within the
scope that is being traced. The true branch and false branch must
have consistent input and outputs, meaning the inputs have to be
the same, and the outputs have to be the same type and shape. Int
output is also allowed. We'll make the output dynamic by turning it
into a symint.
operands (Tuple of possibly nested dict/list/tuple of torch.Tensor): A tuple of inputs to the
true/false functions. It can be empty if true_fn/false_fn doesn't require input. Defaults to ().
Example::
def true_fn(x: torch.Tensor):
return x.cos()
def false_fn(x: torch.Tensor):
return x.sin()
return cond(x.shape[0] > 4, true_fn, false_fn, (x,))
Restrictions:
- The conditional statement (aka `pred`) must meet one of the following constraints:
- It's a `torch.Tensor` with only one element, and torch.bool dtype
- It's a boolean expression, e.g. `x.shape[0] > 10` or `x.dim() > 1 and x.shape[1] > 10`
- The branch function (aka `true_fn`/`false_fn`) must meet all of the following constraints:
- The function signature must match with operands.
- The function must return a tensor with the same metadata, e.g. shape,
dtype, etc.
- The function cannot have in-place mutations on global variables.
(Note: in-place tensor operations such as `add_` for intermediate results
are allowed in a branch)
- The function can perform in-place mutations on its input tensors during inference (i.e.,
when `torch.is_grad_enabled()` is False).
Note: When using `torch.compile()` with a non-constant predicate, the outputs will always
be new tensors that do not share object identity with the original inputs.
Example::
def true_fn(x):
return x.sin_()
def false_fn(x):
return x + 1
def f(x):
return cond(x.sum() > 0, true_fn, false_fn, (x,))
x = torch.ones(4)
with torch.no_grad():
result = torch.compile(f)(x)
assert result is not x # result is a new tensor, not the original x
conj(...)
conj(input) -> Tensor
Returns a view of :attr:`input` with a flipped conjugate bit. If :attr:`input` has a non-complex dtype,
this function just returns :attr:`input`.
.. note::
:func:`torch.conj` performs a lazy conjugation, but the actual conjugated tensor can be materialized
at any time using :func:`torch.resolve_conj`.
.. warning:: In the future, :func:`torch.conj` may return a non-writeable view for an :attr:`input` of
non-complex dtype. It's recommended that programs not modify the tensor returned by :func:`torch.conj_physical`
when :attr:`input` is of non-complex dtype to be compatible with this change.
Args:
input (Tensor): the input tensor.
Example::
>>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
>>> x.is_conj()
False
>>> y = torch.conj(x)
>>> y.is_conj()
True
conj_physical(...)
conj_physical(input, *, out=None) -> Tensor
Computes the element-wise conjugate of the given :attr:`input` tensor.
If :attr:`input` has a non-complex dtype, this function just returns :attr:`input`.
.. note::
This performs the conjugate operation regardless of the fact conjugate bit is set or not.
.. warning:: In the future, :func:`torch.conj_physical` may return a non-writeable view for an :attr:`input` of
non-complex dtype. It's recommended that programs not modify the tensor returned by :func:`torch.conj_physical`
when :attr:`input` is of non-complex dtype to be compatible with this change.
.. math::
\text{out}_{i} = conj(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.conj_physical(torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))
tensor([-1 - 1j, -2 - 2j, 3 + 3j])
conj_physical_(...)
constant_pad_nd(...)
conv1d(...)
conv1d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) -> Tensor
Applies a 1D convolution over an input signal composed of several input
planes.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
See :class:`~torch.nn.Conv1d` for details and output shape.
Note:
In some circumstances when given tensors on a CUDA device and using CuDNN, this operator may select a nondeterministic algorithm to increase performance. If this is undesirable, you can try to make the operation deterministic (potentially at a performance cost) by setting ``torch.backends.cudnn.deterministic = True``. See :doc:`/notes/randomness` for more information.
Note:
This operator supports complex data types i.e. ``complex32, complex64, complex128``.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iW)`
weight: filters of shape :math:`(\text{out\_channels} , \frac{\text{in\_channels}}{\text{groups}} , kW)`
bias: optional bias of shape :math:`(\text{out\_channels})`. Default: ``None``
stride: the stride of the convolving kernel. Can be a single number or
a one-element tuple `(sW,)`. Default: 1
padding: implicit paddings on both sides of the input. Can be a string {'valid', 'same'},
single number or a one-element tuple `(padW,)`. Default: 0
``padding='valid'`` is the same as no padding. ``padding='same'`` pads
the input so the output has the same shape as the input. However, this mode
doesn't support any stride values other than 1.
.. warning::
For ``padding='same'``, if the ``weight`` is even-length and
``dilation`` is odd in any dimension, a full :func:`pad` operation
may be needed internally. Lowering performance.
dilation: the spacing between kernel elements. Can be a single number or
a one-element tuple `(dW,)`. Default: 1
groups: split input into groups, :math:`\text{in\_channels}` should be divisible by
the number of groups. Default: 1
Examples::
>>> inputs = torch.randn(33, 16, 30)
>>> filters = torch.randn(20, 16, 5)
>>> F.conv1d(inputs, filters)
conv2d(...)
conv2d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) -> Tensor
Applies a 2D convolution over an input image composed of several input
planes.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
See :class:`~torch.nn.Conv2d` for details and output shape.
Note:
In some circumstances when given tensors on a CUDA device and using CuDNN, this operator may select a nondeterministic algorithm to increase performance. If this is undesirable, you can try to make the operation deterministic (potentially at a performance cost) by setting ``torch.backends.cudnn.deterministic = True``. See :doc:`/notes/randomness` for more information.
Note:
This operator supports complex data types i.e. ``complex32, complex64, complex128``.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iH , iW)`
weight: filters of shape :math:`(\text{out\_channels} , \frac{\text{in\_channels}}{\text{groups}} , kH , kW)`
bias: optional bias tensor of shape :math:`(\text{out\_channels})`. Default: ``None``
stride: the stride of the convolving kernel. Can be a single number or a
tuple `(sH, sW)`. Default: 1
padding: implicit paddings on both sides of the input. Can be a string {'valid', 'same'},
single number or a tuple `(padH, padW)`. Default: 0
``padding='valid'`` is the same as no padding. ``padding='same'`` pads
the input so the output has the same shape as the input. However, this mode
doesn't support any stride values other than 1.
.. warning::
For ``padding='same'``, if the ``weight`` is even-length and
``dilation`` is odd in any dimension, a full :func:`pad` operation
may be needed internally. Lowering performance.
dilation: the spacing between kernel elements. Can be a single number or
a tuple `(dH, dW)`. Default: 1
groups: split input into groups, both :math:`\text{in\_channels}` and :math:`\text{out\_channels}`
should be divisible by the number of groups. Default: 1
Examples::
>>> # With square kernels and equal stride
>>> filters = torch.randn(8, 4, 3, 3)
>>> inputs = torch.randn(1, 4, 5, 5)
>>> F.conv2d(inputs, filters, padding=1)
conv3d(...)
conv3d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) -> Tensor
Applies a 3D convolution over an input image composed of several input
planes.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
See :class:`~torch.nn.Conv3d` for details and output shape.
Note:
In some circumstances when given tensors on a CUDA device and using CuDNN, this operator may select a nondeterministic algorithm to increase performance. If this is undesirable, you can try to make the operation deterministic (potentially at a performance cost) by setting ``torch.backends.cudnn.deterministic = True``. See :doc:`/notes/randomness` for more information.
Note:
This operator supports complex data types i.e. ``complex32, complex64, complex128``.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iT , iH , iW)`
weight: filters of shape :math:`(\text{out\_channels} , \frac{\text{in\_channels}}{\text{groups}} , kT , kH , kW)`
bias: optional bias tensor of shape :math:`(\text{out\_channels})`. Default: None
stride: the stride of the convolving kernel. Can be a single number or a
tuple `(sT, sH, sW)`. Default: 1
padding: implicit paddings on both sides of the input. Can be a string {'valid', 'same'},
single number or a tuple `(padT, padH, padW)`. Default: 0
``padding='valid'`` is the same as no padding. ``padding='same'`` pads
the input so the output has the same shape as the input. However, this mode
doesn't support any stride values other than 1.
.. warning::
For ``padding='same'``, if the ``weight`` is even-length and
``dilation`` is odd in any dimension, a full :func:`pad` operation
may be needed internally. Lowering performance.
dilation: the spacing between kernel elements. Can be a single number or
a tuple `(dT, dH, dW)`. Default: 1
groups: split input into groups, :math:`\text{in\_channels}` should be divisible by
the number of groups. Default: 1
Examples::
>>> filters = torch.randn(33, 16, 3, 3, 3)
>>> inputs = torch.randn(20, 16, 50, 10, 20)
>>> F.conv3d(inputs, filters)
conv_tbc(...)
Applies a 1-dimensional sequence convolution over an input sequence.
Input and output dimensions are (Time, Batch, Channels) - hence TBC.
Args:
input: input tensor of shape :math:`(\text{sequence length} \times batch \times \text{in\_channels})`
weight: filter of shape (:math:`\text{kernel width} \times \text{in\_channels} \times \text{out\_channels}`)
bias: bias of shape (:math:`\text{out\_channels}`)
pad: number of timesteps to pad. Default: 0
conv_transpose1d(...)
conv_transpose1d(input, weight, bias=None, stride=1, padding=0, output_padding=0, groups=1, dilation=1) -> Tensor
Applies a 1D transposed convolution operator over an input signal
composed of several input planes, sometimes also called "deconvolution".
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
See :class:`~torch.nn.ConvTranspose1d` for details and output shape.
Note:
In some circumstances when given tensors on a CUDA device and using CuDNN, this operator may select a nondeterministic algorithm to increase performance. If this is undesirable, you can try to make the operation deterministic (potentially at a performance cost) by setting ``torch.backends.cudnn.deterministic = True``. See :doc:`/notes/randomness` for more information.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iW)`
weight: filters of shape :math:`(\text{in\_channels} , \frac{\text{out\_channels}}{\text{groups}} , kW)`
bias: optional bias of shape :math:`(\text{out\_channels})`. Default: None
stride: the stride of the convolving kernel. Can be a single number or a
tuple ``(sW,)``. Default: 1
padding: ``dilation * (kernel_size - 1) - padding`` zero-padding will be added to both
sides of each dimension in the input. Can be a single number or a tuple
``(padW,)``. Default: 0
output_padding: additional size added to one side of each dimension in the
output shape. Can be a single number or a tuple ``(out_padW)``. Default: 0
groups: split input into groups, :math:`\text{in\_channels}` should be divisible by the
number of groups. Default: 1
dilation: the spacing between kernel elements. Can be a single number or
a tuple ``(dW,)``. Default: 1
Examples::
>>> inputs = torch.randn(20, 16, 50)
>>> weights = torch.randn(16, 33, 5)
>>> F.conv_transpose1d(inputs, weights)
conv_transpose2d(...)
conv_transpose2d(input, weight, bias=None, stride=1, padding=0, output_padding=0, groups=1, dilation=1) -> Tensor
Applies a 2D transposed convolution operator over an input image
composed of several input planes, sometimes also called "deconvolution".
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
See :class:`~torch.nn.ConvTranspose2d` for details and output shape.
Note:
In some circumstances when given tensors on a CUDA device and using CuDNN, this operator may select a nondeterministic algorithm to increase performance. If this is undesirable, you can try to make the operation deterministic (potentially at a performance cost) by setting ``torch.backends.cudnn.deterministic = True``. See :doc:`/notes/randomness` for more information.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iH , iW)`
weight: filters of shape :math:`(\text{in\_channels} , \frac{\text{out\_channels}}{\text{groups}} , kH , kW)`
bias: optional bias of shape :math:`(\text{out\_channels})`. Default: None
stride: the stride of the convolving kernel. Can be a single number or a
tuple ``(sH, sW)``. Default: 1
padding: ``dilation * (kernel_size - 1) - padding`` zero-padding will be added to both
sides of each dimension in the input. Can be a single number or a tuple
``(padH, padW)``. Default: 0
output_padding: additional size added to one side of each dimension in the
output shape. Can be a single number or a tuple ``(out_padH, out_padW)``.
Default: 0
groups: split input into groups, :math:`\text{in\_channels}` should be divisible by the
number of groups. Default: 1
dilation: the spacing between kernel elements. Can be a single number or
a tuple ``(dH, dW)``. Default: 1
Examples::
>>> # With square kernels and equal stride
>>> inputs = torch.randn(1, 4, 5, 5)
>>> weights = torch.randn(4, 8, 3, 3)
>>> F.conv_transpose2d(inputs, weights, padding=1)
conv_transpose3d(...)
conv_transpose3d(input, weight, bias=None, stride=1, padding=0, output_padding=0, groups=1, dilation=1) -> Tensor
Applies a 3D transposed convolution operator over an input image
composed of several input planes, sometimes also called "deconvolution"
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
See :class:`~torch.nn.ConvTranspose3d` for details and output shape.
Note:
In some circumstances when given tensors on a CUDA device and using CuDNN, this operator may select a nondeterministic algorithm to increase performance. If this is undesirable, you can try to make the operation deterministic (potentially at a performance cost) by setting ``torch.backends.cudnn.deterministic = True``. See :doc:`/notes/randomness` for more information.
Args:
input: input tensor of shape :math:`(\text{minibatch} , \text{in\_channels} , iT , iH , iW)`
weight: filters of shape :math:`(\text{in\_channels} , \frac{\text{out\_channels}}{\text{groups}} , kT , kH , kW)`
bias: optional bias of shape :math:`(\text{out\_channels})`. Default: None
stride: the stride of the convolving kernel. Can be a single number or a
tuple ``(sT, sH, sW)``. Default: 1
padding: ``dilation * (kernel_size - 1) - padding`` zero-padding will be added to both
sides of each dimension in the input. Can be a single number or a tuple
``(padT, padH, padW)``. Default: 0
output_padding: additional size added to one side of each dimension in the
output shape. Can be a single number or a tuple
``(out_padT, out_padH, out_padW)``. Default: 0
groups: split input into groups, :math:`\text{in\_channels}` should be divisible by the
number of groups. Default: 1
dilation: the spacing between kernel elements. Can be a single number or
a tuple `(dT, dH, dW)`. Default: 1
Examples::
>>> inputs = torch.randn(20, 16, 50, 10, 20)
>>> weights = torch.randn(16, 33, 3, 3, 3)
>>> F.conv_transpose3d(inputs, weights)
convolution(...)
copysign(...)
copysign(input, other, *, out=None) -> Tensor
Create a new floating-point tensor with the magnitude of :attr:`input` and the sign of :attr:`other`, elementwise.
.. math::
\text{out}_{i} = \begin{cases}
-|\text{input}_{i}| & \text{if } \text{other}_{i} \leq -0.0 \\
|\text{input}_{i}| & \text{if } \text{other}_{i} \geq 0.0 \\
\end{cases}
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
and integer and float inputs.
Args:
input (Tensor): magnitudes.
other (Tensor or Number): contains value(s) whose signbit(s) are
applied to the magnitudes in :attr:`input`.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(5)
>>> a
tensor([-1.2557, -0.0026, -0.5387, 0.4740, -0.9244])
>>> torch.copysign(a, 1)
tensor([1.2557, 0.0026, 0.5387, 0.4740, 0.9244])
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.7079, 0.2778, -1.0249, 0.5719],
[-0.0059, -0.2600, -0.4475, -1.3948],
[ 0.3667, -0.9567, -2.5757, -0.1751],
[ 0.2046, -0.0742, 0.2998, -0.1054]])
>>> b = torch.randn(4)
tensor([ 0.2373, 0.3120, 0.3190, -1.1128])
>>> torch.copysign(a, b)
tensor([[ 0.7079, 0.2778, 1.0249, -0.5719],
[ 0.0059, 0.2600, 0.4475, -1.3948],
[ 0.3667, 0.9567, 2.5757, -0.1751],
[ 0.2046, 0.0742, 0.2998, -0.1054]])
>>> a = torch.tensor([1.])
>>> b = torch.tensor([-0.])
>>> torch.copysign(a, b)
tensor([-1.])
.. note::
copysign handles signed zeros. If the other argument has a negative zero (-0),
the corresponding output value will be negative.
corrcoef(...)
corrcoef(input) -> Tensor
Estimates the Pearson product-moment correlation coefficient matrix of the variables given by the :attr:`input` matrix,
where rows are the variables and columns are the observations.
.. note::
The correlation coefficient matrix R is computed using the covariance matrix C as given by
:math:`R_{ij} = \frac{ C_{ij} } { \sqrt{ C_{ii} * C_{jj} } }`
.. note::
Due to floating point rounding, the resulting array may not be Hermitian and its diagonal elements may not be 1.
The real and imaginary values are clipped to the interval [-1, 1] in an attempt to improve this situation.
Args:
input (Tensor): A 2D matrix containing multiple variables and observations, or a
Scalar or 1D vector representing a single variable.
Returns:
(Tensor) The correlation coefficient matrix of the variables.
.. seealso::
:func:`torch.cov` covariance matrix.
Example::
>>> x = torch.tensor([[0, 1, 2], [2, 1, 0]])
>>> torch.corrcoef(x)
tensor([[ 1., -1.],
[-1., 1.]])
>>> x = torch.randn(2, 4)
>>> x
tensor([[-0.2678, -0.0908, -0.3766, 0.2780],
[-0.5812, 0.1535, 0.2387, 0.2350]])
>>> torch.corrcoef(x)
tensor([[1.0000, 0.3582],
[0.3582, 1.0000]])
>>> torch.corrcoef(x[0])
tensor(1.)
cos(...)
cos(input, *, out=None) -> Tensor
Returns a new tensor with the cosine of the elements of :attr:`input` given in radians.
.. math::
\text{out}_{i} = \cos(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 1.4309, 1.2706, -0.8562, 0.9796])
>>> torch.cos(a)
tensor([ 0.1395, 0.2957, 0.6553, 0.5574])
cos_(...)
cosh(...)
cosh(input, *, out=None) -> Tensor
Returns a new tensor with the hyperbolic cosine of the elements of
:attr:`input`.
.. math::
\text{out}_{i} = \cosh(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.1632, 1.1835, -0.6979, -0.7325])
>>> torch.cosh(a)
tensor([ 1.0133, 1.7860, 1.2536, 1.2805])
.. note::
When :attr:`input` is on the CPU, the implementation of torch.cosh may use
the Sleef library, which rounds very large results to infinity or negative
infinity. See `here <https://sleef.org/purec.xhtml>`_ for details.
cosh_(...)
cosine_embedding_loss(...)
cosine_similarity(...)
cosine_similarity(x1, x2, dim=1, eps=1e-8) -> Tensor
Returns cosine similarity between ``x1`` and ``x2``, computed along dim. ``x1`` and ``x2`` must be broadcastable
to a common shape. ``dim`` refers to the dimension in this common shape. Dimension ``dim`` of the output is
squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 fewer dimension.
.. math ::
\text{similarity} = \dfrac{x_1 \cdot x_2}{\max(\Vert x_1 \Vert _2, \epsilon) \cdot \max(\Vert x_2 \Vert _2, \epsilon)}
Supports :ref:`type promotion <type-promotion-doc>`.
Args:
x1 (Tensor): First input.
x2 (Tensor): Second input.
dim (int, optional): Dimension along which cosine similarity is computed. Default: 1
eps (float, optional): Small value to avoid division by zero.
Default: 1e-8
Example::
>>> input1 = torch.randn(100, 128)
>>> input2 = torch.randn(100, 128)
>>> output = F.cosine_similarity(input1, input2)
>>> print(output)
count_nonzero(...)
count_nonzero(input, dim=None) -> Tensor
Counts the number of non-zero values in the tensor :attr:`input` along the given :attr:`dim`.
If no dim is specified then all non-zeros in the tensor are counted.
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): Dim or tuple of dims along which to count non-zeros.
Example::
>>> x = torch.zeros(3,3)
>>> x[torch.randn(3,3) > 0.5] = 1
>>> x
tensor([[0., 1., 1.],
[0., 0., 0.],
[0., 0., 1.]])
>>> torch.count_nonzero(x)
tensor(3)
>>> torch.count_nonzero(x, dim=0)
tensor([0, 1, 2])
cov(...)
cov(input, *, correction=1, fweights=None, aweights=None) -> Tensor
Estimates the covariance matrix of the variables given by the :attr:`input` matrix, where rows are
the variables and columns are the observations.
A covariance matrix is a square matrix giving the covariance of each pair of variables. The diagonal contains
the variance of each variable (covariance of a variable with itself). By definition, if :attr:`input` represents
a single variable (Scalar or 1D) then its variance is returned.
The sample covariance of the variables :math:`x` and :math:`y` is given by:
.. math::
\text{cov}(x,y) = \frac{\sum^{N}_{i = 1}(x_{i} - \bar{x})(y_{i} - \bar{y})}{\max(0,~N~-~\delta N)}
where :math:`\bar{x}` and :math:`\bar{y}` are the simple means of the :math:`x` and :math:`y` respectively, and
:math:`\delta N` is the :attr:`correction`.
If :attr:`fweights` and/or :attr:`aweights` are provided, the weighted covariance
is calculated, which is given by:
.. math::
\text{cov}_w(x,y) = \frac{\sum^{N}_{i = 1}w_i(x_{i} - \mu_x^*)(y_{i} - \mu_y^*)}
{\max(0,~\sum^{N}_{i = 1}w_i~-~\frac{\sum^{N}_{i = 1}w_ia_i}{\sum^{N}_{i = 1}w_i}~\delta N)}
where :math:`w` denotes :attr:`fweights` or :attr:`aweights` (``f`` and ``a`` for brevity) based on whichever is
provided, or :math:`w = f \times a` if both are provided, and
:math:`\mu_x^* = \frac{\sum^{N}_{i = 1}w_ix_{i} }{\sum^{N}_{i = 1}w_i}` is the weighted mean of the variable. If not
provided, ``f`` and/or ``a`` can be seen as a :math:`\mathbb{1}` vector of appropriate size.
Args:
input (Tensor): A 2D matrix containing multiple variables and observations, or a
Scalar or 1D vector representing a single variable.
Keyword Args:
correction (int, optional): difference between the sample size and sample degrees of freedom.
Defaults to Bessel's correction, ``correction = 1`` which returns the unbiased estimate,
even if both :attr:`fweights` and :attr:`aweights` are specified. ``correction = 0``
will return the simple average. Defaults to ``1``.
fweights (tensor, optional): A Scalar or 1D tensor of observation vector frequencies representing the number of
times each observation should be repeated. Its numel must equal the number of columns of :attr:`input`.
Must have integral dtype. Ignored if ``None``. Defaults to ``None``.
aweights (tensor, optional): A Scalar or 1D array of observation vector weights.
These relative weights are typically large for observations considered "important" and smaller for
observations considered less "important". Its numel must equal the number of columns of :attr:`input`.
Must have floating point dtype. Ignored if ``None``. Defaults to ``None``.
Returns:
(Tensor) The covariance matrix of the variables.
.. seealso::
:func:`torch.corrcoef` normalized covariance matrix.
Example::
>>> x = torch.tensor([[0, 2], [1, 1], [2, 0]]).T
>>> x
tensor([[0, 1, 2],
[2, 1, 0]])
>>> torch.cov(x)
tensor([[ 1., -1.],
[-1., 1.]])
>>> torch.cov(x, correction=0)
tensor([[ 0.6667, -0.6667],
[-0.6667, 0.6667]])
>>> fw = torch.randint(1, 10, (3,))
>>> fw
tensor([1, 6, 9])
>>> aw = torch.rand(3)
>>> aw
tensor([0.4282, 0.0255, 0.4144])
>>> torch.cov(x, fweights=fw, aweights=aw)
tensor([[ 0.4169, -0.4169],
[-0.4169, 0.4169]])
cross(...)
cross(input, other, dim=None, *, out=None) -> Tensor
Returns the cross product of vectors in dimension :attr:`dim` of :attr:`input`
and :attr:`other`.
Supports input of float, double, cfloat and cdouble dtypes. Also supports batches
of vectors, for which it computes the product along the dimension :attr:`dim`.
In this case, the output has the same batch dimensions as the inputs.
.. warning::
If :attr:`dim` is not given, it defaults to the first dimension found
with the size 3. Note that this might be unexpected.
This behavior is deprecated and will be changed to match that of :func:`torch.linalg.cross`
in a future release.
.. seealso::
:func:`torch.linalg.cross` which has dim=-1 as default.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
dim (int, optional): the dimension to take the cross-product in.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4, 3)
>>> a
tensor([[-0.3956, 1.1455, 1.6895],
[-0.5849, 1.3672, 0.3599],
[-1.1626, 0.7180, -0.0521],
[-0.1339, 0.9902, -2.0225]])
>>> b = torch.randn(4, 3)
>>> b
tensor([[-0.0257, -1.4725, -1.2251],
[-1.1479, -0.7005, -1.9757],
[-1.3904, 0.3726, -1.1836],
[-0.9688, -0.7153, 0.2159]])
>>> torch.cross(a, b, dim=1)
tensor([[ 1.0844, -0.5281, 0.6120],
[-2.4490, -1.5687, 1.9792],
[-0.8304, -1.3037, 0.5650],
[-1.2329, 1.9883, 1.0551]])
>>> torch.cross(a, b)
tensor([[ 1.0844, -0.5281, 0.6120],
[-2.4490, -1.5687, 1.9792],
[-0.8304, -1.3037, 0.5650],
[-1.2329, 1.9883, 1.0551]])
crow_indices_copy(...)
Performs the same operation as :func:`torch.crow_indices`, but all output tensors
are freshly created instead of aliasing the input.
ctc_loss(...)
cudnn_affine_grid_generator(...)
cudnn_batch_norm(...)
cudnn_convolution(...)
cudnn_convolution_add_relu(...)
cudnn_convolution_relu(...)
cudnn_convolution_transpose(...)
cudnn_grid_sampler(...)
cudnn_is_acceptable(...)
cummax(...)
cummax(input, dim, *, out=None) -> (Tensor, LongTensor)
Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative maximum of
elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
location of each maximum value found in the dimension :attr:`dim`.
.. math::
y_i = max(x_1, x_2, x_3, \dots, x_i)
Args:
input (Tensor): the input tensor.
dim (int): the dimension to do the operation over
Keyword args:
out (tuple, optional): the result tuple of two output tensors (values, indices)
Example::
>>> a = torch.randn(10)
>>> a
tensor([-0.3449, -1.5447, 0.0685, -1.5104, -1.1706, 0.2259, 1.4696, -1.3284,
1.9946, -0.8209])
>>> torch.cummax(a, dim=0)
torch.return_types.cummax(
values=tensor([-0.3449, -0.3449, 0.0685, 0.0685, 0.0685, 0.2259, 1.4696, 1.4696,
1.9946, 1.9946]),
indices=tensor([0, 0, 2, 2, 2, 5, 6, 6, 8, 8]))
cummin(...)
cummin(input, dim, *, out=None) -> (Tensor, LongTensor)
Returns a namedtuple ``(values, indices)`` where ``values`` is the cumulative minimum of
elements of :attr:`input` in the dimension :attr:`dim`. And ``indices`` is the index
location of each maximum value found in the dimension :attr:`dim`.
.. math::
y_i = min(x_1, x_2, x_3, \dots, x_i)
Args:
input (Tensor): the input tensor.
dim (int): the dimension to do the operation over
Keyword args:
out (tuple, optional): the result tuple of two output tensors (values, indices)
Example::
>>> a = torch.randn(10)
>>> a
tensor([-0.2284, -0.6628, 0.0975, 0.2680, -1.3298, -0.4220, -0.3885, 1.1762,
0.9165, 1.6684])
>>> torch.cummin(a, dim=0)
torch.return_types.cummin(
values=tensor([-0.2284, -0.6628, -0.6628, -0.6628, -1.3298, -1.3298, -1.3298, -1.3298,
-1.3298, -1.3298]),
indices=tensor([0, 1, 1, 1, 4, 4, 4, 4, 4, 4]))
cumprod(...)
cumprod(input, dim, *, dtype=None, out=None) -> Tensor
Returns the cumulative product of elements of :attr:`input` in the dimension
:attr:`dim`.
For example, if :attr:`input` is a vector of size N, the result will also be
a vector of size N, with elements.
.. math::
y_i = x_1 \times x_2\times x_3\times \dots \times x_i
Args:
input (Tensor): the input tensor.
dim (int): the dimension to do the operation over
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(10)
>>> a
tensor([ 0.6001, 0.2069, -0.1919, 0.9792, 0.6727, 1.0062, 0.4126,
-0.2129, -0.4206, 0.1968])
>>> torch.cumprod(a, dim=0)
tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0158, -0.0065,
0.0014, -0.0006, -0.0001])
>>> a[5] = 0.0
>>> torch.cumprod(a, dim=0)
tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0000, -0.0000,
0.0000, -0.0000, -0.0000])
cumsum(...)
cumsum(input, dim, *, dtype=None, out=None) -> Tensor
Returns the cumulative sum of elements of :attr:`input` in the dimension
:attr:`dim`.
For example, if :attr:`input` is a vector of size N, the result will also be
a vector of size N, with elements.
.. math::
y_i = x_1 + x_2 + x_3 + \dots + x_i
Args:
input (Tensor): the input tensor.
dim (int): the dimension to do the operation over
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randint(1, 20, (10,))
>>> a
tensor([13, 7, 3, 10, 13, 3, 15, 10, 9, 10])
>>> torch.cumsum(a, dim=0)
tensor([13, 20, 23, 33, 46, 49, 64, 74, 83, 93])
cumulative_trapezoid(...)
cumulative_trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
Cumulatively computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_
along :attr:`dim`. By default the spacing between elements is assumed to be 1, but
:attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
used to specify arbitrary spacing along :attr:`dim`.
For more details, please read :func:`torch.trapezoid`. The difference between :func:`torch.trapezoid`
and this function is that, :func:`torch.trapezoid` returns a value for each integration,
where as this function returns a cumulative value for every spacing within the integration. This
is analogous to how `.sum` returns a value and `.cumsum` returns a cumulative sum.
Arguments:
y (Tensor): Values to use when computing the trapezoidal rule.
x (Tensor): If specified, defines spacing between values as specified above.
Keyword arguments:
dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
are specified then this defaults to 1. Effectively multiplies the result by its value.
dim (int): The dimension along which to compute the trapezoidal rule.
The last (inner-most) dimension by default.
Examples::
>>> # Cumulatively computes the trapezoidal rule in 1D, spacing is implicitly 1.
>>> y = torch.tensor([1, 5, 10])
>>> torch.cumulative_trapezoid(y)
tensor([3., 10.5])
>>> # Computes the same trapezoidal rule directly up to each element to verify
>>> (1 + 5) / 2
3.0
>>> (1 + 10 + 10) / 2
10.5
>>> # Cumulatively computes the trapezoidal rule in 1D with constant spacing of 2
>>> # NOTE: the result is the same as before, but multiplied by 2
>>> torch.cumulative_trapezoid(y, dx=2)
tensor([6., 21.])
>>> # Cumulatively computes the trapezoidal rule in 1D with arbitrary spacing
>>> x = torch.tensor([1, 3, 6])
>>> torch.cumulative_trapezoid(y, x)
tensor([6., 28.5])
>>> # Computes the same trapezoidal rule directly up to each element to verify
>>> ((3 - 1) * (1 + 5)) / 2
6.0
>>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
28.5
>>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 matrix
>>> y = torch.arange(9).reshape(3, 3)
tensor([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> torch.cumulative_trapezoid(y)
tensor([[ 0.5, 2.],
[ 3.5, 8.],
[ 6.5, 14.]])
>>> # Cumulatively computes the trapezoidal rule for each column of the matrix
>>> torch.cumulative_trapezoid(y, dim=0)
tensor([[ 1.5, 2.5, 3.5],
[ 6.0, 8.0, 10.0]])
>>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
>>> # with the same arbitrary spacing
>>> y = torch.ones(3, 3)
>>> x = torch.tensor([1, 3, 6])
>>> torch.cumulative_trapezoid(y, x)
tensor([[2., 5.],
[2., 5.],
[2., 5.]])
>>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix
>>> # with different arbitrary spacing per row
>>> y = torch.ones(3, 3)
>>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
>>> torch.cumulative_trapezoid(y, x)
tensor([[1., 2.],
[2., 4.],
[3., 6.]])
deg2rad(...)
deg2rad(input, *, out=None) -> Tensor
Returns a new tensor with each of the elements of :attr:`input`
converted from angles in degrees to radians.
Args:
input (Tensor): the input tensor.
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([[180.0, -180.0], [360.0, -360.0], [90.0, -90.0]])
>>> torch.deg2rad(a)
tensor([[ 3.1416, -3.1416],
[ 6.2832, -6.2832],
[ 1.5708, -1.5708]])
deg2rad_(...)
dequantize(...)
dequantize(tensor) -> Tensor
Returns an fp32 Tensor by dequantizing a quantized Tensor
Args:
tensor (Tensor): A quantized Tensor
.. function:: dequantize(tensors) -> sequence of Tensors
:noindex:
Given a list of quantized Tensors, dequantize them and return a list of fp32 Tensors
Args:
tensors (sequence of Tensors): A list of quantized Tensors
det(...)
det(input) -> Tensor
Alias for :func:`torch.linalg.det`
detach(...)
detach_(...)
detach_copy(...)
Performs the same operation as :func:`torch.detach`, but all output tensors
are freshly created instead of aliasing the input.
diag(...)
diag(input, diagonal=0, *, out=None) -> Tensor
- If :attr:`input` is a vector (1-D tensor), then returns a 2-D square tensor
with the elements of :attr:`input` as the diagonal.
- If :attr:`input` is a matrix (2-D tensor), then returns a 1-D tensor with
the diagonal elements of :attr:`input`.
The argument :attr:`diagonal` controls which diagonal to consider:
- If :attr:`diagonal` = 0, it is the main diagonal.
- If :attr:`diagonal` > 0, it is above the main diagonal.
- If :attr:`diagonal` < 0, it is below the main diagonal.
Args:
input (Tensor): the input tensor.
diagonal (int, optional): the diagonal to consider
Keyword args:
out (Tensor, optional): the output tensor.
.. seealso::
:func:`torch.diagonal` always returns the diagonal of its input.
:func:`torch.diagflat` always constructs a tensor with diagonal elements
specified by the input.
Examples:
Get the square matrix where the input vector is the diagonal::
>>> a = torch.randn(3)
>>> a
tensor([ 0.5950,-0.0872, 2.3298])
>>> torch.diag(a)
tensor([[ 0.5950, 0.0000, 0.0000],
[ 0.0000,-0.0872, 0.0000],
[ 0.0000, 0.0000, 2.3298]])
>>> torch.diag(a, 1)
tensor([[ 0.0000, 0.5950, 0.0000, 0.0000],
[ 0.0000, 0.0000,-0.0872, 0.0000],
[ 0.0000, 0.0000, 0.0000, 2.3298],
[ 0.0000, 0.0000, 0.0000, 0.0000]])
Get the k-th diagonal of a given matrix::
>>> a = torch.randn(3, 3)
>>> a
tensor([[-0.4264, 0.0255,-0.1064],
[ 0.8795,-0.2429, 0.1374],
[ 0.1029,-0.6482,-1.6300]])
>>> torch.diag(a, 0)
tensor([-0.4264,-0.2429,-1.6300])
>>> torch.diag(a, 1)
tensor([ 0.0255, 0.1374])
diag_embed(...)
diag_embed(input, offset=0, dim1=-2, dim2=-1) -> Tensor
Creates a tensor whose diagonals of certain 2D planes (specified by
:attr:`dim1` and :attr:`dim2`) are filled by :attr:`input`.
To facilitate creating batched diagonal matrices, the 2D planes formed by
the last two dimensions of the returned tensor are chosen by default.
The argument :attr:`offset` controls which diagonal to consider:
- If :attr:`offset` = 0, it is the main diagonal.
- If :attr:`offset` > 0, it is above the main diagonal.
- If :attr:`offset` < 0, it is below the main diagonal.
The size of the new matrix will be calculated to make the specified diagonal
of the size of the last input dimension.
Note that for :attr:`offset` other than :math:`0`, the order of :attr:`dim1`
and :attr:`dim2` matters. Exchanging them is equivalent to changing the
sign of :attr:`offset`.
Applying :meth:`torch.diagonal` to the output of this function with
the same arguments yields a matrix identical to input. However,
:meth:`torch.diagonal` has different default dimensions, so those
need to be explicitly specified.
Args:
input (Tensor): the input tensor. Must be at least 1-dimensional.
offset (int, optional): which diagonal to consider. Default: 0
(main diagonal).
dim1 (int, optional): first dimension with respect to which to
take diagonal. Default: -2.
dim2 (int, optional): second dimension with respect to which to
take diagonal. Default: -1.
Example::
>>> a = torch.randn(2, 3)
>>> torch.diag_embed(a)
tensor([[[ 1.5410, 0.0000, 0.0000],
[ 0.0000, -0.2934, 0.0000],
[ 0.0000, 0.0000, -2.1788]],
[[ 0.5684, 0.0000, 0.0000],
[ 0.0000, -1.0845, 0.0000],
[ 0.0000, 0.0000, -1.3986]]])
>>> torch.diag_embed(a, offset=1, dim1=0, dim2=2)
tensor([[[ 0.0000, 1.5410, 0.0000, 0.0000],
[ 0.0000, 0.5684, 0.0000, 0.0000]],
[[ 0.0000, 0.0000, -0.2934, 0.0000],
[ 0.0000, 0.0000, -1.0845, 0.0000]],
[[ 0.0000, 0.0000, 0.0000, -2.1788],
[ 0.0000, 0.0000, 0.0000, -1.3986]],
[[ 0.0000, 0.0000, 0.0000, 0.0000],
[ 0.0000, 0.0000, 0.0000, 0.0000]]])
diagflat(...)
diagflat(input, offset=0) -> Tensor
- If :attr:`input` is a vector (1-D tensor), then returns a 2-D square tensor
with the elements of :attr:`input` as the diagonal.
- If :attr:`input` is a tensor with more than one dimension, then returns a
2-D tensor with diagonal elements equal to a flattened :attr:`input`.
The argument :attr:`offset` controls which diagonal to consider:
- If :attr:`offset` = 0, it is the main diagonal.
- If :attr:`offset` > 0, it is above the main diagonal.
- If :attr:`offset` < 0, it is below the main diagonal.
Args:
input (Tensor): the input tensor.
offset (int, optional): the diagonal to consider. Default: 0 (main
diagonal).
Examples::
>>> a = torch.randn(3)
>>> a
tensor([-0.2956, -0.9068, 0.1695])
>>> torch.diagflat(a)
tensor([[-0.2956, 0.0000, 0.0000],
[ 0.0000, -0.9068, 0.0000],
[ 0.0000, 0.0000, 0.1695]])
>>> torch.diagflat(a, 1)
tensor([[ 0.0000, -0.2956, 0.0000, 0.0000],
[ 0.0000, 0.0000, -0.9068, 0.0000],
[ 0.0000, 0.0000, 0.0000, 0.1695],
[ 0.0000, 0.0000, 0.0000, 0.0000]])
>>> a = torch.randn(2, 2)
>>> a
tensor([[ 0.2094, -0.3018],
[-0.1516, 1.9342]])
>>> torch.diagflat(a)
tensor([[ 0.2094, 0.0000, 0.0000, 0.0000],
[ 0.0000, -0.3018, 0.0000, 0.0000],
[ 0.0000, 0.0000, -0.1516, 0.0000],
[ 0.0000, 0.0000, 0.0000, 1.9342]])
diagonal(...)
diagonal(input, offset=0, dim1=0, dim2=1) -> Tensor
Returns a partial view of :attr:`input` with the its diagonal elements
with respect to :attr:`dim1` and :attr:`dim2` appended as a dimension
at the end of the shape.
The argument :attr:`offset` controls which diagonal to consider:
- If :attr:`offset` = 0, it is the main diagonal.
- If :attr:`offset` > 0, it is above the main diagonal.
- If :attr:`offset` < 0, it is below the main diagonal.
Applying :meth:`torch.diag_embed` to the output of this function with
the same arguments yields a diagonal matrix with the diagonal entries
of the input. However, :meth:`torch.diag_embed` has different default
dimensions, so those need to be explicitly specified.
Args:
input (Tensor): the input tensor. Must be at least 2-dimensional.
offset (int, optional): which diagonal to consider. Default: 0
(main diagonal).
dim1 (int, optional): first dimension with respect to which to
take diagonal. Default: 0.
dim2 (int, optional): second dimension with respect to which to
take diagonal. Default: 1.
.. note:: To take a batch diagonal, pass in dim1=-2, dim2=-1.
Examples::
>>> a = torch.randn(3, 3)
>>> a
tensor([[-1.0854, 1.1431, -0.1752],
[ 0.8536, -0.0905, 0.0360],
[ 0.6927, -0.3735, -0.4945]])
>>> torch.diagonal(a)
tensor([-1.0854, -0.0905, -0.4945])
>>> torch.diagonal(a, 1)
tensor([ 1.1431, 0.0360])
>>> b = torch.randn(2, 5)
>>> b
tensor([[-1.7948, -1.2731, -0.3181, 2.0200, -1.6745],
[ 1.8262, -1.5049, 0.4114, 1.0704, -1.2607]])
>>> torch.diagonal(b, 1, 1, 0)
tensor([1.8262])
>>> x = torch.randn(2, 5, 4, 2)
>>> torch.diagonal(x, offset=-1, dim1=1, dim2=2)
tensor([[[-1.2631, 0.3755, -1.5977, -1.8172],
[-1.1065, 1.0401, -0.2235, -0.7938]],
[[-1.7325, -0.3081, 0.6166, 0.2335],
[ 1.0500, 0.7336, -0.3836, -1.1015]]])
diagonal_copy(...)
Performs the same operation as :func:`torch.diagonal`, but all output tensors
are freshly created instead of aliasing the input.
diagonal_scatter(...)
diagonal_scatter(input, src, offset=0, dim1=0, dim2=1) -> Tensor
Embeds the values of the :attr:`src` tensor into :attr:`input` along
the diagonal elements of :attr:`input`, with respect to :attr:`dim1`
and :attr:`dim2`.
This function returns a tensor with fresh storage; it does not
return a view.
The argument :attr:`offset` controls which diagonal to consider:
- If :attr:`offset` = 0, it is the main diagonal.
- If :attr:`offset` > 0, it is above the main diagonal.
- If :attr:`offset` < 0, it is below the main diagonal.
Args:
input (Tensor): the input tensor. Must be at least 2-dimensional.
src (Tensor): the tensor to embed into :attr:`input`.
offset (int, optional): which diagonal to consider. Default: 0
(main diagonal).
dim1 (int, optional): first dimension with respect to which to
take diagonal. Default: 0.
dim2 (int, optional): second dimension with respect to which to
take diagonal. Default: 1.
.. note::
:attr:`src` must be of the proper size in order to be embedded
into :attr:`input`. Specifically, it should have the same shape as
``torch.diagonal(input, offset, dim1, dim2)``
Examples::
>>> a = torch.zeros(3, 3)
>>> a
tensor([[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]])
>>> torch.diagonal_scatter(a, torch.ones(3), 0)
tensor([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])
>>> torch.diagonal_scatter(a, torch.ones(2), 1)
tensor([[0., 1., 0.],
[0., 0., 1.],
[0., 0., 0.]])
diff(...)
diff(input, n=1, dim=-1, prepend=None, append=None) -> Tensor
Computes the n-th forward difference along the given dimension.
The first-order differences are given by `out[i] = input[i + 1] - input[i]`. Higher-order
differences are calculated by using :func:`torch.diff` recursively.
Args:
input (Tensor): the tensor to compute the differences on
n (int, optional): the number of times to recursively compute the difference
dim (int, optional): the dimension to compute the difference along.
Default is the last dimension.
prepend, append (Tensor, optional): values to prepend or append to
:attr:`input` along :attr:`dim` before computing the difference.
Their dimensions must be equivalent to that of input, and their shapes
must match input's shape except on :attr:`dim`.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([1, 3, 2])
>>> torch.diff(a)
tensor([ 2, -1])
>>> b = torch.tensor([4, 5])
>>> torch.diff(a, append=b)
tensor([ 2, -1, 2, 1])
>>> c = torch.tensor([[1, 2, 3], [3, 4, 5]])
>>> torch.diff(c, dim=0)
tensor([[2, 2, 2]])
>>> torch.diff(c, dim=1)
tensor([[1, 1],
[1, 1]])
digamma(...)
digamma(input, *, out=None) -> Tensor
Alias for :func:`torch.special.digamma`.
dist(...)
dist(input, other, p=2) -> Tensor
Returns the p-norm of (:attr:`input` - :attr:`other`)
The shapes of :attr:`input` and :attr:`other` must be
:ref:`broadcastable <broadcasting-semantics>`.
Args:
input (Tensor): the input tensor.
other (Tensor): the Right-hand-side input tensor
p (float, optional): the norm to be computed
Example::
>>> x = torch.randn(4)
>>> x
tensor([-1.5393, -0.8675, 0.5916, 1.6321])
>>> y = torch.randn(4)
>>> y
tensor([ 0.0967, -1.0511, 0.6295, 0.8360])
>>> torch.dist(x, y, 3.5)
tensor(1.6727)
>>> torch.dist(x, y, 3)
tensor(1.6973)
>>> torch.dist(x, y, 0)
tensor(4.)
>>> torch.dist(x, y, 1)
tensor(2.6537)
div(...)
div(input, other, *, rounding_mode=None, out=None) -> Tensor
Divides each element of the input ``input`` by the corresponding element of
:attr:`other`.
.. math::
\text{out}_i = \frac{\text{input}_i}{\text{other}_i}
.. note::
By default, this performs a "true" division like Python 3.
See the :attr:`rounding_mode` argument for floor division.
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
Always promotes integer types to the default scalar type.
Args:
input (Tensor): the dividend
other (Tensor or Number): the divisor
Keyword args:
rounding_mode (str, optional): Type of rounding applied to the result:
* None - default behavior. Performs no rounding and, if both :attr:`input` and
:attr:`other` are integer types, promotes the inputs to the default scalar type.
Equivalent to true division in Python (the ``/`` operator) and NumPy's ``np.true_divide``.
* ``"trunc"`` - rounds the results of the division towards zero.
Equivalent to C-style integer division.
* ``"floor"`` - rounds the results of the division down.
Equivalent to floor division in Python (the ``//`` operator) and NumPy's ``np.floor_divide``.
out (Tensor, optional): the output tensor.
Examples::
>>> x = torch.tensor([ 0.3810, 1.2774, -0.2972, -0.3719, 0.4637])
>>> torch.div(x, 0.5)
tensor([ 0.7620, 2.5548, -0.5944, -0.7438, 0.9274])
>>> a = torch.tensor([[-0.3711, -1.9353, -0.4605, -0.2917],
... [ 0.1815, -1.0111, 0.9805, -1.5923],
... [ 0.1062, 1.4581, 0.7759, -1.2344],
... [-0.1830, -0.0313, 1.1908, -1.4757]])
>>> b = torch.tensor([ 0.8032, 0.2930, -0.8113, -0.2308])
>>> torch.div(a, b)
tensor([[-0.4620, -6.6051, 0.5676, 1.2639],
[ 0.2260, -3.4509, -1.2086, 6.8990],
[ 0.1322, 4.9764, -0.9564, 5.3484],
[-0.2278, -0.1068, -1.4678, 6.3938]])
>>> torch.div(a, b, rounding_mode='trunc')
tensor([[-0., -6., 0., 1.],
[ 0., -3., -1., 6.],
[ 0., 4., -0., 5.],
[-0., -0., -1., 6.]])
>>> torch.div(a, b, rounding_mode='floor')
tensor([[-1., -7., 0., 1.],
[ 0., -4., -2., 6.],
[ 0., 4., -1., 5.],
[-1., -1., -2., 6.]])
divide(...)
divide(input, other, *, rounding_mode=None, out=None) -> Tensor
Alias for :func:`torch.div`.
dot(...)
dot(input, tensor, *, out=None) -> Tensor
Computes the dot product of two 1D tensors.
.. note::
Unlike NumPy's dot, torch.dot intentionally only supports computing the dot product
of two 1D tensors with the same number of elements.
Args:
input (Tensor): first tensor in the dot product, must be 1D.
tensor (Tensor): second tensor in the dot product, must be 1D.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.dot(torch.tensor([2, 3]), torch.tensor([2, 1]))
tensor(7)
>>> t1, t2 = torch.tensor([0, 1]), torch.tensor([2, 3])
>>> torch.dot(t1, t2)
tensor(3)
dropout(...)
dropout_(...)
dsmm(...)
dsplit(...)
dsplit(input, indices_or_sections) -> List of Tensors
Splits :attr:`input`, a tensor with three or more dimensions, into multiple tensors
depthwise according to :attr:`indices_or_sections`. Each split is a view of
:attr:`input`.
This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=2)
(the split dimension is 2), except that if :attr:`indices_or_sections` is an integer
it must evenly divide the split dimension or a runtime error will be thrown.
This function is based on NumPy's :func:`numpy.dsplit`.
Args:
input (Tensor): tensor to split.
indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
Example::
>>> t = torch.arange(16.0).reshape(2, 2, 4)
>>> t
tensor([[[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.]],
[[ 8., 9., 10., 11.],
[12., 13., 14., 15.]]])
>>> torch.dsplit(t, 2)
(tensor([[[ 0., 1.],
[ 4., 5.]],
[[ 8., 9.],
[12., 13.]]]),
tensor([[[ 2., 3.],
[ 6., 7.]],
[[10., 11.],
[14., 15.]]]))
>>> torch.dsplit(t, [3, 6])
(tensor([[[ 0., 1., 2.],
[ 4., 5., 6.]],
[[ 8., 9., 10.],
[12., 13., 14.]]]),
tensor([[[ 3.],
[ 7.]],
[[11.],
[15.]]]),
tensor([], size=(2, 2, 0)))
dstack(...)
dstack(tensors, *, out=None) -> Tensor
Stack tensors in sequence depthwise (along third axis).
This is equivalent to concatenation along the third axis after 1-D and 2-D tensors have been reshaped by :func:`torch.atleast_3d`.
Args:
tensors (sequence of Tensors): sequence of tensors to concatenate
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([1, 2, 3])
>>> b = torch.tensor([4, 5, 6])
>>> torch.dstack((a,b))
tensor([[[1, 4],
[2, 5],
[3, 6]]])
>>> a = torch.tensor([[1],[2],[3]])
>>> b = torch.tensor([[4],[5],[6]])
>>> torch.dstack((a,b))
tensor([[[1, 4]],
[[2, 5]],
[[3, 6]]])
einsum(*args: Any) -> torch.Tensor
einsum(equation, *operands) -> Tensor
Sums the product of the elements of the input :attr:`operands` along dimensions specified using a notation
based on the Einstein summation convention.
Einsum allows computing many common multi-dimensional linear algebraic array operations by representing them
in a short-hand format based on the Einstein summation convention, given by :attr:`equation`. The details of
this format are described below, but the general idea is to label every dimension of the input :attr:`operands`
with some subscript and define which subscripts are part of the output. The output is then computed by summing
the product of the elements of the :attr:`operands` along the dimensions whose subscripts are not part of the
output. For example, matrix multiplication can be computed using einsum as `torch.einsum("ij,jk->ik", A, B)`.
Here, j is the summation subscript and i and k the output subscripts (see section below for more details on why).
Equation:
The :attr:`equation` string specifies the subscripts (letters in `[a-zA-Z]`) for each dimension of
the input :attr:`operands` in the same order as the dimensions, separating subscripts for each operand by a
comma (','), e.g. `'ij,jk'` specify subscripts for two 2D operands. The dimensions labeled with the same subscript
must be broadcastable, that is, their size must either match or be `1`. The exception is if a subscript is
repeated for the same input operand, in which case the dimensions labeled with this subscript for this operand
must match in size and the operand will be replaced by its diagonal along these dimensions. The subscripts that
appear exactly once in the :attr:`equation` will be part of the output, sorted in increasing alphabetical order.
The output is computed by multiplying the input :attr:`operands` element-wise, with their dimensions aligned based
on the subscripts, and then summing out the dimensions whose subscripts are not part of the output.
Optionally, the output subscripts can be explicitly defined by adding an arrow ('->') at the end of the equation
followed by the subscripts for the output. For instance, the following equation computes the transpose of a
matrix multiplication: 'ij,jk->ki'. The output subscripts must appear at least once for some input operand and
at most once for the output.
Ellipsis ('...') can be used in place of subscripts to broadcast the dimensions covered by the ellipsis.
Each input operand may contain at most one ellipsis which will cover the dimensions not covered by subscripts,
e.g. for an input operand with 5 dimensions, the ellipsis in the equation `'ab...c'` cover the third and fourth
dimensions. The ellipsis does not need to cover the same number of dimensions across the :attr:`operands` but the
'shape' of the ellipsis (the size of the dimensions covered by them) must broadcast together. If the output is not
explicitly defined with the arrow ('->') notation, the ellipsis will come first in the output (left-most dimensions),
before the subscript labels that appear exactly once for the input operands. e.g. the following equation implements
batch matrix multiplication `'...ij,...jk'`.
A few final notes: the equation may contain whitespaces between the different elements (subscripts, ellipsis,
arrow and comma) but something like `'. . .'` is not valid. An empty string `''` is valid for scalar operands.
.. note::
``torch.einsum`` handles ellipsis ('...') differently from NumPy in that it allows dimensions
covered by the ellipsis to be summed over, that is, ellipsis are not required to be part of the output.
.. note::
Please install opt-einsum (https://optimized-einsum.readthedocs.io/en/stable/) in order to enroll into a more
performant einsum. You can install when installing torch like so: `pip install torch[opt-einsum]` or by itself
with `pip install opt-einsum`.
If opt-einsum is available, this function will automatically speed up computation and/or consume less memory
by optimizing contraction order through our opt_einsum backend :mod:`torch.backends.opt_einsum` (The _ vs - is
confusing, I know). This optimization occurs when there are at least three inputs, since the order does not matter
otherwise. Note that finding `the` optimal path is an NP-hard problem, thus, opt-einsum relies on different
heuristics to achieve near-optimal results. If opt-einsum is not available, the default order is to contract
from left to right.
To bypass this default behavior, add the following to disable opt_einsum and skip path calculation:
``torch.backends.opt_einsum.enabled = False``
To specify which strategy you'd like for opt_einsum to compute the contraction path, add the following line:
``torch.backends.opt_einsum.strategy = 'auto'``. The default strategy is 'auto', and we also support 'greedy' and
'optimal'. Disclaimer that the runtime of 'optimal' is factorial in the number of inputs! See more details in
the opt_einsum documentation (https://optimized-einsum.readthedocs.io/en/stable/path_finding.html).
.. note::
As of PyTorch 1.10 :func:`torch.einsum` also supports the sublist format (see examples below). In this format,
subscripts for each operand are specified by sublists, list of integers in the range [0, 52). These sublists
follow their operands, and an extra sublist can appear at the end of the input to specify the output's
subscripts., e.g. `torch.einsum(op1, sublist1, op2, sublist2, ..., [subslist_out])`. Python's `Ellipsis` object
may be provided in a sublist to enable broadcasting as described in the Equation section above.
Args:
equation (str): The subscripts for the Einstein summation.
operands (List[Tensor]): The tensors to compute the Einstein summation of.
Examples::
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # trace
>>> torch.einsum('ii', torch.randn(4, 4))
tensor(-1.2104)
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # diagonal
>>> torch.einsum('ii->i', torch.randn(4, 4))
tensor([-0.1034, 0.7952, -0.2433, 0.4545])
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # outer product
>>> x = torch.randn(5)
>>> y = torch.randn(4)
>>> torch.einsum('i,j->ij', x, y)
tensor([[ 0.1156, -0.2897, -0.3918, 0.4963],
[-0.3744, 0.9381, 1.2685, -1.6070],
[ 0.7208, -1.8058, -2.4419, 3.0936],
[ 0.1713, -0.4291, -0.5802, 0.7350],
[ 0.5704, -1.4290, -1.9323, 2.4480]])
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # batch matrix multiplication
>>> As = torch.randn(3, 2, 5)
>>> Bs = torch.randn(3, 5, 4)
>>> torch.einsum('bij,bjk->bik', As, Bs)
tensor([[[-1.0564, -1.5904, 3.2023, 3.1271],
[-1.6706, -0.8097, -0.8025, -2.1183]],
[[ 4.2239, 0.3107, -0.5756, -0.2354],
[-1.4558, -0.3460, 1.5087, -0.8530]],
[[ 2.8153, 1.8787, -4.3839, -1.2112],
[ 0.3728, -2.1131, 0.0921, 0.8305]]])
>>> # xdoctest: +IGNORE_WANT("non-deterministic")
>>> # with sublist format and ellipsis
>>> torch.einsum(As, [..., 0, 1], Bs, [..., 1, 2], [..., 0, 2])
tensor([[[-1.0564, -1.5904, 3.2023, 3.1271],
[-1.6706, -0.8097, -0.8025, -2.1183]],
[[ 4.2239, 0.3107, -0.5756, -0.2354],
[-1.4558, -0.3460, 1.5087, -0.8530]],
[[ 2.8153, 1.8787, -4.3839, -1.2112],
[ 0.3728, -2.1131, 0.0921, 0.8305]]])
>>> # batch permute
>>> A = torch.randn(2, 3, 4, 5)
>>> torch.einsum('...ij->...ji', A).shape
torch.Size([2, 3, 5, 4])
>>> # equivalent to torch.nn.functional.bilinear
>>> A = torch.randn(3, 5, 4)
>>> l = torch.randn(2, 5)
>>> r = torch.randn(2, 4)
>>> torch.einsum('bn,anm,bm->ba', l, A, r)
tensor([[-0.3430, -5.2405, 0.4494],
[ 0.3311, 5.5201, -3.0356]])
embedding(...)
embedding_bag(...)
embedding_renorm_(...)
empty(...)
empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) -> Tensor
Returns a tensor filled with uninitialized data. The shape of the tensor is
defined by the variable argument :attr:`size`.
.. note::
If :func:`torch.use_deterministic_algorithms()` and
:attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
``True``, the output tensor is initialized to prevent any possible
nondeterministic behavior from using the data as an input to an operation.
Floating point and complex tensors are filled with NaN, and integer tensors
are filled with the maximum value.
Args:
size (int...): a sequence of integers defining the shape of the output tensor.
Can be a variable number of arguments or a collection like a list or tuple.
Keyword args:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.contiguous_format``.
Example::
>>> torch.empty((2,3), dtype=torch.int64)
tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13],
[ 7.5751e+18, 7.1428e+18, 7.5955e+18]])
empty_like(...)
empty_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns an uninitialized tensor with the same size as :attr:`input`.
``torch.empty_like(input)`` is equivalent to
``torch.empty(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
.. note::
If :func:`torch.use_deterministic_algorithms()` and
:attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
``True``, the output tensor is initialized to prevent any possible
nondeterministic behavior from using the data as an input to an operation.
Floating point and complex tensors are filled with NaN, and integer tensors
are filled with the maximum value.
When ``torch.preserve_format`` is used:
If the input tensor is dense (i.e., non-overlapping strided),
its memory format (including strides) is retained.
Otherwise (e.g., a non-dense view like a stepped slice),
the output is converted to the dense format.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
Example::
>>> a=torch.empty((2,3), dtype=torch.int32, device = 'cuda')
>>> torch.empty_like(a)
tensor([[0, 0, 0],
[0, 0, 0]], device='cuda:0', dtype=torch.int32)
empty_permuted(...)
empty_permuted(size, physical_layout, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
Creates an uninitialized, non-overlapping and dense tensor with the
specified :attr:`size`, with :attr:`physical_layout` specifying how the
dimensions are physically laid out in memory (each logical dimension is listed
from outermost to innermost). :attr:`physical_layout` is a generalization
of NCHW/NHWC notation: if each dimension is assigned a number according to
what order they occur in size (N=0, C=1, H=2, W=3), then NCHW is ``(0, 1, 2, 3)``
while NHWC is ``(0, 2, 3, 1)``. Equivalently, the strides of the output
tensor ``t`` are such that ``t.stride(physical_layout[i]) == contiguous_strides[i]``
(notably, this function is *not* equivalent to ``torch.empty(size).permute(physical_layout)``).
Unlike :func:`torch.empty_strided`, this is guaranteed to produce a dense
tensor with no overlaps. If possible, prefer using this function over
:func:`torch.empty_strided` or manual use of :func:`torch.as_strided`.
.. note::
If :func:`torch.use_deterministic_algorithms()` and
:attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
``True``, the output tensor is initialized to prevent any possible
nondeterministic behavior from using the data as an input to an operation.
Floating point and complex tensors are filled with NaN, and integer tensors
are filled with the maximum value.
Args:
size (tuple of int): the shape of the output tensor
physical_layout (tuple of int): the ordering of dimensions physically in memory
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Examples:
>>> torch.empty((2, 3, 5, 7)).stride()
(105, 35, 7, 1)
>>> torch.empty_permuted((2, 3, 5, 7), (0, 1, 2, 3)).stride()
(105, 35, 7, 1)
>>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).stride()
(105, 1, 21, 3)
>>> torch.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).stride()
(105, 1, 21, 3)
>>> torch.empty_permuted((2, 3, 5, 7), (0, 2, 3, 1)).dim_order()
(0, 2, 3, 1)
empty_quantized(...)
empty_strided(...)
empty_strided(size, stride, *, dtype=None, layout=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
Creates a tensor with the specified :attr:`size` and :attr:`stride` and filled with undefined data.
.. warning::
If the constructed tensor is "overlapped" (with multiple indices referring to the same element
in memory) its behavior is undefined.
.. note::
If :func:`torch.use_deterministic_algorithms()` and
:attr:`torch.utils.deterministic.fill_uninitialized_memory` are both set to
``True``, the output tensor is initialized to prevent any possible
nondeterministic behavior from using the data as an input to an operation.
Floating point and complex tensors are filled with NaN, and integer tensors
are filled with the maximum value.
Args:
size (tuple of int): the shape of the output tensor
stride (tuple of int): the strides of the output tensor
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> a = torch.empty_strided((2, 3), (1, 2))
>>> a
tensor([[8.9683e-44, 4.4842e-44, 5.1239e+07],
[0.0000e+00, 0.0000e+00, 3.0705e-41]])
>>> a.stride()
(1, 2)
>>> a.size()
torch.Size([2, 3])
eq(...)
eq(input, other, *, out=None) -> Tensor
Computes element-wise equality
The second argument can be a number or a tensor whose shape is
:ref:`broadcastable <broadcasting-semantics>` with the first argument.
Args:
input (Tensor): the tensor to compare
other (Tensor or float): the tensor or value to compare
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
A boolean tensor that is True where :attr:`input` is equal to :attr:`other` and False elsewhere
Example::
>>> torch.eq(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[ True, False],
[False, True]])
equal(...)
equal(input, other) -> bool
``True`` if two tensors have the same size and elements, ``False`` otherwise.
.. note::
Tensors containing NaNs are never equal to each other. Additionally, this function does not
differentiate between the data types of the tensors during comparison. For more thorough tensor checks,
use :meth:`torch.testing.assert_close`.
Example::
>>> torch.equal(torch.tensor([1, 2]), torch.tensor([1, 2]))
True
>>> torch.equal(torch.tensor([3, torch.nan]), torch.tensor([3, torch.nan]))
False
>>> torch.equal(torch.tensor([1, 2, 3], dtype=torch.int32), torch.tensor([1, 2, 3], dtype=torch.float32))
True
erf(...)
erf(input, *, out=None) -> Tensor
Alias for :func:`torch.special.erf`.
erf_(...)
erfc(...)
erfc(input, *, out=None) -> Tensor
Alias for :func:`torch.special.erfc`.
erfc_(...)
erfinv(...)
erfinv(input, *, out=None) -> Tensor
Alias for :func:`torch.special.erfinv`.
exp(...)
exp(input, *, out=None) -> Tensor
Returns a new tensor with the exponential of the elements
of the input tensor :attr:`input`.
.. math::
y_{i} = e^{x_{i}}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.exp(torch.tensor([0, math.log(2.)]))
tensor([ 1., 2.])
exp2(...)
exp2(input, *, out=None) -> Tensor
Alias for :func:`torch.special.exp2`.
exp2_(...)
exp_(...)
expand_copy(...)
Performs the same operation as :func:`torch.Tensor.expand`, but all output tensors
are freshly created instead of aliasing the input.
expm1(...)
expm1(input, *, out=None) -> Tensor
Alias for :func:`torch.special.expm1`.
expm1_(...)
eye(...)
eye(n, m=None, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.
Args:
n (int): the number of rows
m (int, optional): the number of columns with default being :attr:`n`
Keyword arguments:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 2-D tensor with ones on the diagonal and zeros elsewhere
Example::
>>> torch.eye(3)
tensor([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
fake_quantize_per_channel_affine(...)
fake_quantize_per_channel_affine(input, scale, zero_point, axis, quant_min, quant_max) -> Tensor
Returns a new tensor with the data in :attr:`input` fake quantized per channel using :attr:`scale`,
:attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`, across the channel specified by :attr:`axis`.
.. math::
\text{output} = (
min(
\text{quant\_max},
max(
\text{quant\_min},
\text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
)
) - \text{zero\_point}
) \times \text{scale}
Args:
input (Tensor): the input value(s), in ``torch.float32``
scale (Tensor): quantization scale, per channel in ``torch.float32``
zero_point (Tensor): quantization zero_point, per channel in ``torch.int32`` or ``torch.half`` or ``torch.float32``
axis (int32): channel axis
quant_min (int64): lower bound of the quantized domain
quant_max (int64): upper bound of the quantized domain
Returns:
Tensor: A newly fake_quantized per channel ``torch.float32`` tensor
Example::
>>> x = torch.randn(2, 2, 2)
>>> x
tensor([[[-0.2525, -0.0466],
[ 0.3491, -0.2168]],
[[-0.5906, 1.6258],
[ 0.6444, -0.0542]]])
>>> scales = (torch.randn(2) + 1) * 0.05
>>> scales
tensor([0.0475, 0.0486])
>>> zero_points = torch.zeros(2).to(torch.int32)
>>> zero_points
tensor([0, 0])
>>> torch.fake_quantize_per_channel_affine(x, scales, zero_points, 1, 0, 255)
tensor([[[0.0000, 0.0000],
[0.3405, 0.0000]],
[[0.0000, 1.6134],
[0.6323, 0.0000]]])
fake_quantize_per_tensor_affine(...)
fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max) -> Tensor
Returns a new tensor with the data in :attr:`input` fake quantized using :attr:`scale`,
:attr:`zero_point`, :attr:`quant_min` and :attr:`quant_max`.
.. math::
\text{output} = (
min(
\text{quant\_max},
max(
\text{quant\_min},
\text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point}
)
) - \text{zero\_point}
) \times \text{scale}
Args:
input (Tensor): the input value(s), ``torch.float32`` tensor
scale (double scalar or ``float32`` Tensor): quantization scale
zero_point (int64 scalar or ``int32`` Tensor): quantization zero_point
quant_min (int64): lower bound of the quantized domain
quant_max (int64): upper bound of the quantized domain
Returns:
Tensor: A newly fake_quantized ``torch.float32`` tensor
Example::
>>> x = torch.randn(4)
>>> x
tensor([ 0.0552, 0.9730, 0.3973, -1.0780])
>>> torch.fake_quantize_per_tensor_affine(x, 0.1, 0, 0, 255)
tensor([0.1000, 1.0000, 0.4000, 0.0000])
>>> torch.fake_quantize_per_tensor_affine(x, torch.tensor(0.1), torch.tensor(0), 0, 255)
tensor([0.1000, 1.0000, 0.4000, 0.0000])
fbgemm_linear_fp16_weight(...)
fbgemm_linear_fp16_weight_fp32_activation(...)
fbgemm_linear_int8_weight(...)
fbgemm_linear_int8_weight_fp32_activation(...)
fbgemm_linear_quantize_weight(...)
fbgemm_pack_gemm_matrix_fp16(...)
fbgemm_pack_quantized_matrix(...)
feature_alpha_dropout(...)
feature_alpha_dropout_(...)
feature_dropout(...)
feature_dropout_(...)
fill(...)
fill_(...)
fix(...)
fix(input, *, out=None) -> Tensor
Alias for :func:`torch.trunc`
fix_(...)
flatten(...)
flatten(input, start_dim=0, end_dim=-1) -> Tensor
Flattens :attr:`input` by reshaping it into a one-dimensional tensor. If :attr:`start_dim` or :attr:`end_dim`
are passed, only dimensions starting with :attr:`start_dim` and ending with :attr:`end_dim` are flattened.
The order of elements in :attr:`input` is unchanged.
Unlike NumPy's flatten, which always copies input's data, this function may return the original object, a view,
or copy. If no dimensions are flattened, then the original object :attr:`input` is returned. Otherwise, if input can
be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the
flattened shape is input's data copied. See :meth:`torch.Tensor.view` for details on when a view will be returned.
.. note::
Flattening a zero-dimensional tensor will return a one-dimensional view.
Args:
input (Tensor): the input tensor.
start_dim (int): the first dim to flatten
end_dim (int): the last dim to flatten
Example::
>>> t = torch.tensor([[[1, 2],
... [3, 4]],
... [[5, 6],
... [7, 8]]])
>>> torch.flatten(t)
tensor([1, 2, 3, 4, 5, 6, 7, 8])
>>> torch.flatten(t, start_dim=1)
tensor([[1, 2, 3, 4],
[5, 6, 7, 8]])
flip(...)
flip(input, dims) -> Tensor
Reverse the order of an n-D tensor along given axis in dims.
.. note::
`torch.flip` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.flip`,
which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
`torch.flip` is expected to be slower than `np.flip`.
Args:
input (Tensor): the input tensor.
dims (a list or tuple): axis to flip on
Example::
>>> x = torch.arange(8).view(2, 2, 2)
>>> x
tensor([[[ 0, 1],
[ 2, 3]],
[[ 4, 5],
[ 6, 7]]])
>>> torch.flip(x, [0, 1])
tensor([[[ 6, 7],
[ 4, 5]],
[[ 2, 3],
[ 0, 1]]])
fliplr(...)
fliplr(input) -> Tensor
Flip tensor in the left/right direction, returning a new tensor.
Flip the entries in each row in the left/right direction.
Columns are preserved, but appear in a different order than before.
Note:
Requires the tensor to be at least 2-D.
.. note::
`torch.fliplr` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.fliplr`,
which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
`torch.fliplr` is expected to be slower than `np.fliplr`.
Args:
input (Tensor): Must be at least 2-dimensional.
Example::
>>> x = torch.arange(4).view(2, 2)
>>> x
tensor([[0, 1],
[2, 3]])
>>> torch.fliplr(x)
tensor([[1, 0],
[3, 2]])
flipud(...)
flipud(input) -> Tensor
Flip tensor in the up/down direction, returning a new tensor.
Flip the entries in each column in the up/down direction.
Rows are preserved, but appear in a different order than before.
Note:
Requires the tensor to be at least 1-D.
.. note::
`torch.flipud` makes a copy of :attr:`input`'s data. This is different from NumPy's `np.flipud`,
which returns a view in constant time. Since copying a tensor's data is more work than viewing that data,
`torch.flipud` is expected to be slower than `np.flipud`.
Args:
input (Tensor): Must be at least 1-dimensional.
Example::
>>> x = torch.arange(4).view(2, 2)
>>> x
tensor([[0, 1],
[2, 3]])
>>> torch.flipud(x)
tensor([[2, 3],
[0, 1]])
float_power(...)
float_power(input, exponent, *, out=None) -> Tensor
Raises :attr:`input` to the power of :attr:`exponent`, elementwise, in double precision.
If neither input is complex returns a ``torch.float64`` tensor,
and if one or more inputs is complex returns a ``torch.complex128`` tensor.
.. note::
This function always computes in double precision, unlike :func:`torch.pow`,
which implements more typical :ref:`type promotion <type-promotion-doc>`.
This is useful when the computation needs to be performed in a wider or more precise dtype,
or the results of the computation may contain fractional values not representable in the input dtypes,
like when an integer base is raised to a negative integer exponent.
Args:
input (Tensor or Number): the base value(s)
exponent (Tensor or Number): the exponent value(s)
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randint(10, (4,))
>>> a
tensor([6, 4, 7, 1])
>>> torch.float_power(a, 2)
tensor([36., 16., 49., 1.], dtype=torch.float64)
>>> a = torch.arange(1, 5)
>>> a
tensor([ 1, 2, 3, 4])
>>> exp = torch.tensor([2, -3, 4, -5])
>>> exp
tensor([ 2, -3, 4, -5])
>>> torch.float_power(a, exp)
tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=torch.float64)
floor(...)
floor(input, *, out=None) -> Tensor
Returns a new tensor with the floor of the elements of :attr:`input`,
the largest integer less than or equal to each element.
For integer inputs, follows the array-api convention of returning a
copy of the input tensor.
.. math::
\text{out}_{i} = \left\lfloor \text{input}_{i} \right\rfloor
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-0.8166, 1.5308, -0.2530, -0.2091])
>>> torch.floor(a)
tensor([-1., 1., -1., -1.])
floor_(...)
floor_divide(...)
floor_divide(input, other, *, out=None) -> Tensor
.. note::
Before PyTorch 1.13 :func:`torch.floor_divide` incorrectly performed
truncation division. To restore the previous behavior use
:func:`torch.div` with ``rounding_mode='trunc'``.
Computes :attr:`input` divided by :attr:`other`, elementwise, and floors
the result.
.. math::
\text{{out}}_i = \text{floor} \left( \frac{{\text{{input}}_i}}{{\text{{other}}_i}} \right)
Supports broadcasting to a common shape, type promotion, and integer and float inputs.
Args:
input (Tensor or Number): the dividend
other (Tensor or Number): the divisor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([4.0, 3.0])
>>> b = torch.tensor([2.0, 2.0])
>>> torch.floor_divide(a, b)
tensor([2.0, 1.0])
>>> torch.floor_divide(a, 1.4)
tensor([2.0, 2.0])
fmax(...)
fmax(input, other, *, out=None) -> Tensor
Computes the element-wise maximum of :attr:`input` and :attr:`other`.
This is like :func:`torch.maximum` except it handles NaNs differently:
if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the maximum.
Only if both elements are NaN is NaN propagated.
This function is a wrapper around C++'s ``std::fmax`` and is similar to NumPy's ``fmax`` function.
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer and floating-point inputs.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([9.7, float('nan'), 3.1, float('nan')])
>>> b = torch.tensor([-2.2, 0.5, float('nan'), float('nan')])
>>> torch.fmax(a, b)
tensor([9.7000, 0.5000, 3.1000, nan])
fmin(...)
fmin(input, other, *, out=None) -> Tensor
Computes the element-wise minimum of :attr:`input` and :attr:`other`.
This is like :func:`torch.minimum` except it handles NaNs differently:
if exactly one of the two elements being compared is a NaN then the non-NaN element is taken as the minimum.
Only if both elements are NaN is NaN propagated.
This function is a wrapper around C++'s ``std::fmin`` and is similar to NumPy's ``fmin`` function.
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer and floating-point inputs.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([2.2, float('nan'), 2.1, float('nan')])
>>> b = torch.tensor([-9.3, 0.1, float('nan'), float('nan')])
>>> torch.fmin(a, b)
tensor([-9.3000, 0.1000, 2.1000, nan])
fmod(...)
fmod(input, other, *, out=None) -> Tensor
Applies C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_ entrywise.
The result has the same sign as the dividend :attr:`input` and its absolute value
is less than that of :attr:`other`.
This function may be defined in terms of :func:`torch.div` as
.. code:: python
torch.fmod(a, b) == a - a.div(b, rounding_mode="trunc") * b
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
.. note::
When the divisor is zero, returns ``NaN`` for floating point dtypes
on both CPU and GPU; raises ``RuntimeError`` for integer division by
zero on CPU; Integer division by zero on GPU may return any value.
.. note::
Complex inputs are not supported. In some cases, it is not mathematically
possible to satisfy the definition of a modulo operation with complex numbers.
.. seealso::
:func:`torch.remainder` which implements Python's modulus operator.
This one is defined using division rounding down the result.
Args:
input (Tensor): the dividend
other (Tensor or Scalar): the divisor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.fmod(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
tensor([-1., -0., -1., 1., 0., 1.])
>>> torch.fmod(torch.tensor([1, 2, 3, 4, 5]), -1.5)
tensor([1.0000, 0.5000, 0.0000, 1.0000, 0.5000])
fork(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
fork(*args, **kwargs) -> torch._C.Future
frac(...)
frac(input, *, out=None) -> Tensor
Computes the fractional portion of each element in :attr:`input`.
.. math::
\text{out}_{i} = \text{input}_{i} - \left\lfloor |\text{input}_{i}| \right\rfloor * \operatorname{sgn}(\text{input}_{i})
Example::
>>> torch.frac(torch.tensor([1, 2.5, -3.2]))
tensor([ 0.0000, 0.5000, -0.2000])
frac_(...)
frexp(...)
frexp(input, *, out=None) -> (Tensor mantissa, Tensor exponent)
Decomposes :attr:`input` into mantissa and exponent tensors
such that :math:`\text{input} = \text{mantissa} \times 2^{\text{exponent}}`.
The range of mantissa is the open interval (-1, 1).
Supports float inputs.
Args:
input (Tensor): the input tensor
Keyword args:
out (tuple, optional): the output tensors
Example::
>>> x = torch.arange(9.)
>>> mantissa, exponent = torch.frexp(x)
>>> mantissa
tensor([0.0000, 0.5000, 0.5000, 0.7500, 0.5000, 0.6250, 0.7500, 0.8750, 0.5000])
>>> exponent
tensor([0, 1, 2, 2, 3, 3, 3, 3, 4], dtype=torch.int32)
>>> torch.ldexp(mantissa, exponent)
tensor([0., 1., 2., 3., 4., 5., 6., 7., 8.])
frobenius_norm(...)
from_file(...)
from_file(filename, shared=None, size=0, *, dtype=None, layout=None, device=None, pin_memory=False)
Creates a CPU tensor with a storage backed by a memory-mapped file.
If ``shared`` is True, then memory is shared between processes. All changes are written to the file.
If ``shared`` is False, then changes to the tensor do not affect the file.
``size`` is the number of elements in the Tensor. If ``shared`` is ``False``, then the file must contain
at least ``size * sizeof(dtype)`` bytes. If ``shared`` is ``True`` the file will be created if needed.
.. note::
Only CPU tensors can be mapped to files.
.. note::
For now, tensors with storages backed by a memory-mapped file cannot be created in pinned memory.
Args:
filename (str): file name to map
shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
size (int): number of elements in the tensor
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> t = torch.randn(2, 5, dtype=torch.float64)
>>> t.numpy().tofile('storage.pt')
>>> t_mapped = torch.from_file('storage.pt', shared=False, size=10, dtype=torch.float64)
from_numpy(...)
from_numpy(ndarray) -> Tensor
Creates a :class:`Tensor` from a :class:`numpy.ndarray`.
The returned tensor and :attr:`ndarray` share the same memory. Modifications to
the tensor will be reflected in the :attr:`ndarray` and vice versa. The returned
tensor is not resizable.
It currently accepts :attr:`ndarray` with dtypes of ``numpy.float64``,
``numpy.float32``, ``numpy.float16``, ``numpy.complex64``, ``numpy.complex128``,
``numpy.int64``, ``numpy.int32``, ``numpy.int16``, ``numpy.int8``, ``numpy.uint8``,
and ``bool``.
.. warning::
Writing to a tensor created from a read-only NumPy array is not supported and will result in undefined behavior.
Example::
>>> a = numpy.array([1, 2, 3])
>>> t = torch.from_numpy(a)
>>> t
tensor([ 1, 2, 3])
>>> t[0] = -1
>>> a
array([-1, 2, 3])
frombuffer(...)
frombuffer(buffer, *, dtype, count=-1, offset=0, requires_grad=False) -> Tensor
Creates a 1-dimensional :class:`Tensor` from an object that implements
the Python buffer protocol.
Skips the first :attr:`offset` bytes in the buffer, and interprets the rest of
the raw bytes as a 1-dimensional tensor of type :attr:`dtype` with :attr:`count`
elements.
Note that either of the following must be true:
1. :attr:`count` is a positive non-zero number, and the total number of bytes
in the buffer is more than :attr:`offset` plus :attr:`count` times the size
(in bytes) of :attr:`dtype`.
2. :attr:`count` is negative, and the length (number of bytes) of the buffer
subtracted by the :attr:`offset` is a multiple of the size (in bytes) of
:attr:`dtype`.
The returned tensor and buffer share the same memory. Modifications to
the tensor will be reflected in the buffer and vice versa. The returned
tensor is not resizable.
.. note::
This function increments the reference count for the object that
owns the shared memory. Therefore, such memory will not be deallocated
before the returned tensor goes out of scope.
.. warning::
This function's behavior is undefined when passed an object implementing
the buffer protocol whose data is not on the CPU. Doing so is likely to
cause a segmentation fault.
.. warning::
This function does not try to infer the :attr:`dtype` (hence, it is not
optional). Passing a different :attr:`dtype` than its source may result
in unexpected behavior.
Args:
buffer (object): a Python object that exposes the buffer interface.
Keyword args:
dtype (:class:`torch.dtype`): the desired data type of returned tensor.
count (int, optional): the number of desired elements to be read.
If negative, all the elements (until the end of the buffer) will be
read. Default: -1.
offset (int, optional): the number of bytes to skip at the start of
the buffer. Default: 0.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> import array
>>> a = array.array('i', [1, 2, 3])
>>> t = torch.frombuffer(a, dtype=torch.int32)
>>> t
tensor([ 1, 2, 3])
>>> t[0] = -1
>>> a
array([-1, 2, 3])
>>> # Interprets the signed char bytes as 32-bit integers.
>>> # Each 4 signed char elements will be interpreted as
>>> # 1 signed 32-bit integer.
>>> import array
>>> a = array.array('b', [-1, 0, 0, 0])
>>> torch.frombuffer(a, dtype=torch.int32)
tensor([255], dtype=torch.int32)
full(...)
full(size, fill_value, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Creates a tensor of size :attr:`size` filled with :attr:`fill_value`. The
tensor's dtype is inferred from :attr:`fill_value`.
Args:
size (int...): a list, tuple, or :class:`torch.Size` of integers defining the
shape of the output tensor.
fill_value (Scalar): the value to fill the output tensor with.
Keyword args:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.full((2, 3), 3.141592)
tensor([[ 3.1416, 3.1416, 3.1416],
[ 3.1416, 3.1416, 3.1416]])
full_like(...)
full_like(input, fill_value, \*, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns a tensor with the same size as :attr:`input` filled with :attr:`fill_value`.
``torch.full_like(input, fill_value)`` is equivalent to
``torch.full(input.size(), fill_value, dtype=input.dtype, layout=input.layout, device=input.device)``.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
fill_value: the number to fill the output tensor with.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
Example::
>>> x = torch.ones(2, 3)
>>> torch.full_like(x, 3.141592)
tensor([[ 3.1416, 3.1416, 3.1416],
[ 3.1416, 3.1416, 3.1416]])
>>> torch.full_like(x, 7)
tensor([[7., 7., 7.],
[7., 7., 7.]])
>>> torch.full_like(x, 0.5, dtype=torch.int32)
tensor([[0, 0, 0],
[0, 0, 0]], dtype=torch.int32)
>>> y = torch.randn(3, 4, dtype=torch.float64)
>>> torch.full_like(y, -1.0)
tensor([[-1., -1., -1., -1.],
[-1., -1., -1., -1.],
[-1., -1., -1., -1.]], dtype=torch.float64)
fused_moving_avg_obs_fake_quant(...)
gather(...)
gather(input, dim, index, *, sparse_grad=False, out=None) -> Tensor
Gathers values along an axis specified by `dim`.
For a 3-D tensor the output is specified by::
out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0
out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1
out[i][j][k] = input[i][j][index[i][j][k]] # if dim == 2
:attr:`input` and :attr:`index` must have the same number of dimensions.
It is also required that ``index.size(d) <= input.size(d)`` for all
dimensions ``d != dim``. :attr:`out` will have the same shape as :attr:`index`.
Note that ``input`` and ``index`` do not broadcast against each other.
When :attr:`index` is empty, we always return an empty output with the same shape
without further error checking.
Args:
input (Tensor): the source tensor
dim (int): the axis along which to index
index (LongTensor): the indices of elements to gather
Keyword arguments:
sparse_grad (bool, optional): If ``True``, gradient w.r.t. :attr:`input` will be a sparse tensor.
out (Tensor, optional): the destination tensor
Example::
>>> t = torch.tensor([[1, 2], [3, 4]])
>>> torch.gather(t, 1, torch.tensor([[0, 0], [1, 0]]))
tensor([[ 1, 1],
[ 4, 3]])
gcd(...)
gcd(input, other, *, out=None) -> Tensor
Computes the element-wise greatest common divisor (GCD) of :attr:`input` and :attr:`other`.
Both :attr:`input` and :attr:`other` must have integer types.
.. note::
This defines :math:`gcd(0, 0) = 0`.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([5, 10, 15])
>>> b = torch.tensor([3, 4, 5])
>>> torch.gcd(a, b)
tensor([1, 2, 5])
>>> c = torch.tensor([3])
>>> torch.gcd(a, c)
tensor([1, 1, 3])
gcd_(...)
ge(...)
ge(input, other, *, out=None) -> Tensor
Computes :math:`\text{input} \geq \text{other}` element-wise.
The second argument can be a number or a tensor whose shape is
:ref:`broadcastable <broadcasting-semantics>` with the first argument.
Args:
input (Tensor): the tensor to compare
other (Tensor or float): the tensor or value to compare
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
A boolean tensor that is True where :attr:`input` is greater than or equal to :attr:`other` and False elsewhere
Example::
>>> torch.ge(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[True, True], [False, True]])
geqrf(...)
geqrf(input, *, out=None) -> (Tensor, Tensor)
This is a low-level function for calling LAPACK's geqrf directly. This function
returns a namedtuple (a, tau) as defined in `LAPACK documentation for geqrf`_ .
Computes a QR decomposition of :attr:`input`.
Both `Q` and `R` matrices are stored in the same output tensor `a`.
The elements of `R` are stored on and above the diagonal.
Elementary reflectors (or Householder vectors) implicitly defining matrix `Q`
are stored below the diagonal.
The results of this function can be used together with :func:`torch.linalg.householder_product`
to obtain the `Q` matrix or
with :func:`torch.ormqr`, which uses an implicit representation of the `Q` matrix,
for an efficient matrix-matrix multiplication.
See `LAPACK documentation for geqrf`_ for further details.
.. note::
See also :func:`torch.linalg.qr`, which computes Q and R matrices, and :func:`torch.linalg.lstsq`
with the ``driver="gels"`` option for a function that can solve matrix equations using a QR decomposition.
Args:
input (Tensor): the input matrix
Keyword args:
out (tuple, optional): the output tuple of (Tensor, Tensor). Ignored if `None`. Default: `None`.
.. _LAPACK documentation for geqrf:
http://www.netlib.org/lapack/explore-html/df/dc5/group__variants_g_ecomputational_ga3766ea903391b5cf9008132f7440ec7b.html
ger(...)
ger(input, vec2, *, out=None) -> Tensor
Alias of :func:`torch.outer`.
.. warning::
This function is deprecated and will be removed in a future PyTorch release.
Use :func:`torch.outer` instead.
get_autocast_cpu_dtype(...)
get_autocast_dtype(...)
get_autocast_gpu_dtype(...)
get_autocast_ipu_dtype(...)
get_autocast_xla_dtype(...)
get_default_device() -> 'torch.device'
Gets the default ``torch.Tensor`` to be allocated on ``device``
get_default_dtype(...)
get_default_dtype() -> torch.dtype
Get the current default floating point :class:`torch.dtype`.
Example::
>>> torch.get_default_dtype() # initial default for floating point is torch.float32
torch.float32
>>> torch.set_default_dtype(torch.float64)
>>> torch.get_default_dtype() # default is now changed to torch.float64
torch.float64
get_deterministic_debug_mode() -> int
Returns the current value of the debug mode for deterministic
operations. Refer to :func:`torch.set_deterministic_debug_mode`
documentation for more details.
get_device(...)
get_device_module(device: torch.device | str | None = None)
Returns the module associated with a given device(e.g., torch.device('cuda'), "mtia:0", "xpu", ...).
If no device is given, return the module for the current accelerator or CPU if none is present.
get_float32_matmul_precision() -> str
Returns the current value of float32 matrix multiplication precision. Refer to
:func:`torch.set_float32_matmul_precision` documentation for more details.
get_num_interop_threads(...)
get_num_interop_threads() -> int
Returns the number of threads used for inter-op parallelism on CPU
(e.g. in JIT interpreter)
get_num_threads(...)
get_num_threads() -> int
Returns the number of threads used for parallelizing CPU operations
get_rng_state() -> torch.Tensor
Returns the random number generator state as a `torch.ByteTensor`.
.. note:: The returned state is for the default generator on CPU only.
See also: :func:`torch.random.fork_rng`.
gradient(...)
gradient(input, *, spacing=1, dim=None, edge_order=1) -> List of Tensors
Estimates the gradient of a function :math:`g : \mathbb{R}^n \rightarrow \mathbb{R}` in
one or more dimensions using the `second-order accurate central differences method
<https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ and
either first or second order estimates at the boundaries.
The gradient of :math:`g` is estimated using samples. By default, when :attr:`spacing` is not
specified, the samples are entirely described by :attr:`input`, and the mapping of input coordinates
to an output is the same as the tensor's mapping of indices to values. For example, for a three-dimensional
:attr:`input` the function described is :math:`g : \mathbb{R}^3 \rightarrow \mathbb{R}`, and
:math:`g(1, 2, 3)\ == input[1, 2, 3]`.
When :attr:`spacing` is specified, it modifies the relationship between :attr:`input` and input coordinates.
This is detailed in the "Keyword Arguments" section below.
The gradient is estimated by estimating each partial derivative of :math:`g` independently. This estimation is
accurate if :math:`g` is in :math:`C^3` (it has at least 3 continuous derivatives), and the estimation can be
improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative
is estimated using `Taylor's theorem with remainder <https://en.wikipedia.org/wiki/Taylor%27s_theorem>`_.
Letting :math:`x` be an interior point with :math:`x-h_l` and :math:`x+h_r` be points neighboring
it to the left and right respectively, :math:`f(x+h_r)` and :math:`f(x-h_l)` can be estimated using:
.. math::
\begin{aligned}
f(x+h_r) = f(x) + h_r f'(x) + {h_r}^2 \frac{f''(x)}{2} + {h_r}^3 \frac{f'''(\xi_1)}{6}, \xi_1 \in (x, x+h_r) \\
f(x-h_l) = f(x) - h_l f'(x) + {h_l}^2 \frac{f''(x)}{2} - {h_l}^3 \frac{f'''(\xi_2)}{6}, \xi_2 \in (x, x-h_l) \\
\end{aligned}
Using the fact that :math:`f \in C^3` and solving the linear system, we derive:
.. math::
f'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l)
+ ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }
.. note::
We estimate the gradient of functions in complex domain
:math:`g : \mathbb{C}^n \rightarrow \mathbb{C}` in the same way.
The value of each partial derivative at the boundary points is computed differently. See edge_order below.
Args:
input (``Tensor``): the tensor that represents the values of the function
Keyword args:
spacing (``scalar``, ``list of scalar``, ``list of Tensor``, optional): :attr:`spacing` can be used to modify
how the :attr:`input` tensor's indices relate to sample coordinates. If :attr:`spacing` is a scalar then
the indices are multiplied by the scalar to produce the coordinates. For example, if :attr:`spacing=2` the
indices (1, 2, 3) become coordinates (2, 4, 6). If :attr:`spacing` is a list of scalars then the corresponding
indices are multiplied. For example, if :attr:`spacing=(2, -1, 3)` the indices (1, 2, 3) become coordinates (2, -2, 9).
Finally, if :attr:`spacing` is a list of one-dimensional tensors then each tensor specifies the coordinates for
the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then
the coordinates are (t0[1], t1[2], t2[3])
dim (``int``, ``list of int``, optional): the dimension or dimensions to approximate the gradient over. By default
the partial gradient in every dimension is computed. Note that when :attr:`dim` is specified the elements of
the :attr:`spacing` argument must correspond with the specified dims."
edge_order (``int``, optional): 1 or 2, for `first-order
<https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_ or
`second-order <https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_
estimation of the boundary ("edge") values, respectively. Note that when :attr:`edge_order` is specified, each
dimension size of :attr:`input` should be at least edge_order+1
Examples::
>>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
>>> coordinates = (torch.tensor([-2., -1., 1., 4.]),)
>>> values = torch.tensor([4., 1., 1., 16.], )
>>> torch.gradient(values, spacing = coordinates)
(tensor([-3., -2., 2., 5.]),)
>>> # Estimates the gradient of the R^2 -> R function whose samples are
>>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
>>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
>>> # partial derivative for both dimensions.
>>> t = torch.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
>>> torch.gradient(t)
(tensor([[ 9., 18., 36., 72.],
[ 9., 18., 36., 72.]]),
tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
[10.0000, 15.0000, 30.0000, 40.0000]]))
>>> # A scalar value for spacing modifies the relationship between tensor indices
>>> # and input coordinates by multiplying the indices to find the
>>> # coordinates. For example, below the indices of the innermost
>>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
>>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
>>> torch.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
(tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
[ 4.5000, 9.0000, 18.0000, 36.0000]]),
tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
[ 5.0000, 7.5000, 15.0000, 20.0000]]))
>>> # doubling the spacing between samples halves the estimated partial gradients.
>>>
>>> # Estimates only the partial derivative for dimension 1
>>> torch.gradient(t, dim = 1) # spacing = None (implicitly 1.)
(tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
[10.0000, 15.0000, 30.0000, 40.0000]]),)
>>> # When spacing is a list of scalars, the relationship between the tensor
>>> # indices and input coordinates changes based on dimension.
>>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
>>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
>>> # 0, 1 translate to coordinates of [0, 2].
>>> torch.gradient(t, spacing = [3., 2.])
(tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
[ 4.5000, 9.0000, 18.0000, 36.0000]]),
tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
[ 3.3333, 5.0000, 10.0000, 13.3333]]))
>>> # The following example is a replication of the previous one with explicit
>>> # coordinates.
>>> coords = (torch.tensor([0, 2]), torch.tensor([0, 3, 6, 9]))
>>> torch.gradient(t, spacing = coords)
(tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
[ 4.5000, 9.0000, 18.0000, 36.0000]]),
tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
[ 3.3333, 5.0000, 10.0000, 13.3333]]))
greater(...)
greater(input, other, *, out=None) -> Tensor
Alias for :func:`torch.gt`.
greater_equal(...)
greater_equal(input, other, *, out=None) -> Tensor
Alias for :func:`torch.ge`.
grid_sampler(...)
grid_sampler_2d(...)
grid_sampler_3d(...)
group_norm(...)
gru(...)
gru_cell(...)
gt(...)
gt(input, other, *, out=None) -> Tensor
Computes :math:`\text{input} > \text{other}` element-wise.
The second argument can be a number or a tensor whose shape is
:ref:`broadcastable <broadcasting-semantics>` with the first argument.
Args:
input (Tensor): the tensor to compare
other (Tensor or float): the tensor or value to compare
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
A boolean tensor that is True where :attr:`input` is greater than :attr:`other` and False elsewhere
Example::
>>> torch.gt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[False, True], [False, False]])
hamming_window(...)
hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) -> Tensor
Hamming window function.
.. math::
w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),
where :math:`N` is the full window size.
The input :attr:`window_length` is a positive integer controlling the
returned window size. :attr:`periodic` flag determines whether the returned
window trims off the last duplicate value from the symmetric window and is
ready to be used as a periodic window with functions like
:meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
``torch.hamming_window(L, periodic=True)`` equal to
``torch.hamming_window(L + 1, periodic=False)[:-1])``.
.. note::
If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
.. note::
This is a generalized version of :meth:`torch.hann_window`.
Arguments:
window_length (int): the size of returned window
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
.. function:: hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, \
pin_memory=False, requires_grad=False) -> Tensor
:noindex:
Hamming window function with periodic specified.
Arguments:
window_length (int): the size of returned window
periodic (bool): If True, returns a window to be used as periodic
function. If False, return a symmetric window.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
.. function:: hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, \
pin_memory=False, requires_grad=False) -> Tensor
:noindex:
Hamming window function with periodic and alpha specified.
Arguments:
window_length (int): the size of returned window
periodic (bool): If True, returns a window to be used as periodic
function. If False, return a symmetric window.
alpha (float): The coefficient :math:`\alpha` in the equation above
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
.. function:: hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, \
device=None, pin_memory=False, requires_grad=False) -> Tensor
:noindex:
Hamming window function with periodic, alpha and beta specified.
Arguments:
window_length (int): the size of returned window
periodic (bool): If True, returns a window to be used as periodic
function. If False, return a symmetric window.
alpha (float): The coefficient :math:`\alpha` in the equation above
beta (float): The coefficient :math:`\beta` in the equation above
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window.
hann_window(...)
hann_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Hann window function.
.. math::
w[n] = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{N - 1} \right)\right] =
\sin^2 \left( \frac{\pi n}{N - 1} \right),
where :math:`N` is the full window size.
The input :attr:`window_length` is a positive integer controlling the
returned window size. :attr:`periodic` flag determines whether the returned
window trims off the last duplicate value from the symmetric window and is
ready to be used as a periodic window with functions like
:meth:`torch.stft`. Therefore, if :attr:`periodic` is true, the :math:`N` in
above formula is in fact :math:`\text{window\_length} + 1`. Also, we always have
``torch.hann_window(L, periodic=True)`` equal to
``torch.hann_window(L + 1, periodic=False)[:-1])``.
.. note::
If :attr:`window_length` :math:`=1`, the returned window contains a single value 1.
Arguments:
window_length (int): the size of returned window
periodic (bool, optional): If True, returns a window to be used as periodic
function. If False, return a symmetric window.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). Only floating point types are supported.
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Returns:
Tensor: A 1-D tensor of size :math:`(\text{window\_length},)` containing the window
hardshrink(...)
hardshrink(input, lambd=0.5) -> Tensor
Applies the hard shrinkage function element-wise
See :class:`~torch.nn.Hardshrink` for more details.
hash_tensor(...)
hash_tensor(input, *, mode=0) -> Tensor
Returns a hash of all elements in the :attr:`input` tensor.
Currently only mode=0 (reduction via xor) is supported. The output will always
be of type ``torch.uint64``. The elements of ``input`` are upcasted to their
64 bit float / integer equivalent and bitcasted to ``torch.uint64`` before
reduction via xor.
Args:
input (Tensor): the input tensor.
Keyword Args:
mode (int) : The hash to use. Default: 0 (xor_reduction)
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 1.1918, -1.1813, 0.3373]])
>>> torch.hash_tensor(a)
tensor(13822780554648485888, dtype=torch.uint64)
.. function:: hash_tensor(input, dim, *, keepdim=False, mode=0) -> Tensor
:noindex:
Returns the hash of each row of the :attr:`input` tensor in the given
dimension :attr:`dim` given by mode. If :attr:`dim` is a list of dimensions,
reduce over all of them.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword Args:
mode (int) : The hash to use. Default: 0 (xor_reduction)
Example::
>>> a = torch.randn(2, 4)
>>> a
tensor([[ 0.1317, -0.5554, -1.4724, -1.1391],
[ 0.0778, -0.6070, 0.6375, 0.1798]])
>>> torch.hash_tensor(a, 1)
tensor([9233691267014066176, 9255993250844508160], dtype=torch.uint64)
heaviside(...)
heaviside(input, values, *, out=None) -> Tensor
Computes the Heaviside step function for each element in :attr:`input`.
The Heaviside step function is defined as:
.. math::
\text{{heaviside}}(input, values) = \begin{cases}
0, & \text{if input < 0}\\
values, & \text{if input == 0}\\
1, & \text{if input > 0}
\end{cases}
Args:
input (Tensor): the input tensor.
values (Tensor): The values to use where :attr:`input` is zero.
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> input = torch.tensor([-1.5, 0, 2.0])
>>> values = torch.tensor([0.5])
>>> torch.heaviside(input, values)
tensor([0.0000, 0.5000, 1.0000])
>>> values = torch.tensor([1.2, -2.0, 3.5])
>>> torch.heaviside(input, values)
tensor([0., -2., 1.])
hinge_embedding_loss(...)
histc(...)
histc(input, bins=100, min=0, max=0, *, out=None) -> Tensor
Computes the histogram of a tensor.
The elements are sorted into equal width bins between :attr:`min` and
:attr:`max`. If :attr:`min` and :attr:`max` are both zero, the minimum and
maximum values of the data are used.
Elements lower than min and higher than max and ``NaN`` elements are ignored.
Args:
input (Tensor): the input tensor.
bins (int): number of histogram bins
min (Scalar): lower end of the range (inclusive)
max (Scalar): upper end of the range (inclusive)
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
Tensor: Histogram represented as a tensor
Example::
>>> torch.histc(torch.tensor([1., 2, 1]), bins=4, min=0, max=3)
tensor([ 0., 2., 1., 0.])
histogram(...)
histogram(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor)
Computes a histogram of the values in a tensor.
:attr:`bins` can be an integer or a 1D tensor.
If :attr:`bins` is an int, it specifies the number of equal-width bins.
By default, the lower and upper range of the bins is determined by the
minimum and maximum elements of the input tensor. The :attr:`range`
argument can be provided to specify a range for the bins.
If :attr:`bins` is a 1D tensor, it specifies the sequence of bin edges
including the rightmost edge. It should contain at least 2 elements
and its elements should be increasing.
Args:
input (Tensor): the input tensor.
bins: int or 1D Tensor. If int, defines the number of equal-width bins. If tensor,
defines the sequence of bin edges including the rightmost edge.
Keyword args:
range (tuple of float): Defines the range of the bins.
weight (Tensor): If provided, weight should have the same shape as input. Each value in
input contributes its associated weight towards its bin's result.
density (bool): If False, the result will contain the count (or total weight) in each bin.
If True, the result is the value of the probability density function over the bins,
normalized such that the integral over the range of the bins is 1.
out (Tensor, optional): the output tensor. (tuple, optional): The result tuple of two output tensors (hist, bin_edges).
Returns:
hist (Tensor): 1D Tensor containing the values of the histogram.
bin_edges(Tensor): 1D Tensor containing the edges of the histogram bins.
Example::
>>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]))
(tensor([ 0., 5., 2., 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
>>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]), density=True)
(tensor([ 0., 0.9524, 0.3810, 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
histogramdd(...)
histogramdd(input, bins, *, range=None, weight=None, density=False, out=None) -> (Tensor, Tensor[])
Computes a multi-dimensional histogram of the values in a tensor.
Interprets the elements of an input tensor whose innermost dimension has size N
as a collection of N-dimensional points. Maps each of the points into a set of
N-dimensional bins and returns the number of points (or total weight) in each bin.
:attr:`input` must be a tensor with at least 2 dimensions.
If input has shape (M, N), each of its M rows defines a point in N-dimensional space.
If input has three or more dimensions, all but the last dimension are flattened.
Each dimension is independently associated with its own strictly increasing sequence
of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D
tensors. Alternatively, bin edges may be constructed automatically by passing a
sequence of integers specifying the number of equal-width bins in each dimension.
For each N-dimensional point in input:
- Each of its coordinates is binned independently among the bin edges
corresponding to its dimension
- Binning results are combined to identify the N-dimensional bin (if any)
into which the point falls
- If the point falls into a bin, the bin's count (or total weight) is incremented
- Points which do not fall into any bin do not contribute to the output
:attr:`bins` can be a sequence of N 1D tensors, a sequence of N ints, or a single int.
If :attr:`bins` is a sequence of N 1D tensors, it explicitly specifies the N sequences
of bin edges. Each 1D tensor should contain a strictly increasing sequence with at
least one element. A sequence of K bin edges defines K-1 bins, explicitly specifying
the left and right edges of all bins. Every bin is inclusive of its left edge. Only
the rightmost bin is inclusive of its right edge.
If :attr:`bins` is a sequence of N ints, it specifies the number of equal-width bins
in each dimension. By default, the leftmost and rightmost bin edges in each dimension
are determined by the minimum and maximum elements of the input tensor in the
corresponding dimension. The :attr:`range` argument can be provided to manually
specify the leftmost and rightmost bin edges in each dimension.
If :attr:`bins` is an int, it specifies the number of equal-width bins for all dimensions.
.. note::
See also :func:`torch.histogram`, which specifically computes 1D histograms.
While :func:`torch.histogramdd` infers the dimensionality of its bins and
binned values from the shape of :attr:`input`, :func:`torch.histogram`
accepts and flattens :attr:`input` of any shape.
Args:
input (Tensor): the input tensor.
bins: Tensor[], int[], or int.
If Tensor[], defines the sequences of bin edges.
If int[], defines the number of equal-width bins in each dimension.
If int, defines the number of equal-width bins for all dimensions.
Keyword args:
range (sequence of float): Defines the leftmost and rightmost bin edges
in each dimension.
weight (Tensor): By default, each value in the input has weight 1. If a weight
tensor is passed, each N-dimensional coordinate in input
contributes its associated weight towards its bin's result.
The weight tensor should have the same shape as the :attr:`input`
tensor excluding its innermost dimension N.
density (bool): If False (default), the result will contain the count (or total weight)
in each bin. If True, each count (weight) is divided by the total count
(total weight), then divided by the volume of its associated bin.
Returns:
hist (Tensor): N-dimensional Tensor containing the values of the histogram.
bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
Example::
>>> torch.histogramdd(torch.tensor([[0., 1.], [1., 0.], [2., 0.], [2., 2.]]), bins=[3, 3],
... weight=torch.tensor([1., 2., 4., 8.]))
torch.return_types.histogramdd(
hist=tensor([[0., 1., 0.],
[2., 0., 0.],
[4., 0., 8.]]),
bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]),
tensor([0.0000, 0.6667, 1.3333, 2.0000])))
>>> torch.histogramdd(torch.tensor([[0., 0.], [1., 1.], [2., 2.]]), bins=[2, 2],
... range=[0., 1., 0., 1.], density=True)
torch.return_types.histogramdd(
hist=tensor([[2., 0.],
[0., 2.]]),
bin_edges=(tensor([0.0000, 0.5000, 1.0000]),
tensor([0.0000, 0.5000, 1.0000])))
hsmm(...)
hsplit(...)
hsplit(input, indices_or_sections) -> List of Tensors
Splits :attr:`input`, a tensor with one or more dimensions, into multiple tensors
horizontally according to :attr:`indices_or_sections`. Each split is a view of
:attr:`input`.
If :attr:`input` is one dimensional this is equivalent to calling
torch.tensor_split(input, indices_or_sections, dim=0) (the split dimension is
zero), and if :attr:`input` has two or more dimensions it's equivalent to calling
torch.tensor_split(input, indices_or_sections, dim=1) (the split dimension is 1),
except that if :attr:`indices_or_sections` is an integer it must evenly divide
the split dimension or a runtime error will be thrown.
This function is based on NumPy's :func:`numpy.hsplit`.
Args:
input (Tensor): tensor to split.
indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
Example::
>>> t = torch.arange(16.0).reshape(4,4)
>>> t
tensor([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.],
[12., 13., 14., 15.]])
>>> torch.hsplit(t, 2)
(tensor([[ 0., 1.],
[ 4., 5.],
[ 8., 9.],
[12., 13.]]),
tensor([[ 2., 3.],
[ 6., 7.],
[10., 11.],
[14., 15.]]))
>>> torch.hsplit(t, [3, 6])
(tensor([[ 0., 1., 2.],
[ 4., 5., 6.],
[ 8., 9., 10.],
[12., 13., 14.]]),
tensor([[ 3.],
[ 7.],
[11.],
[15.]]),
tensor([], size=(4, 0)))
hspmm(...)
hspmm(mat1, mat2, *, out=None) -> Tensor
Performs a matrix multiplication of a :ref:`sparse COO matrix
<sparse-coo-docs>` :attr:`mat1` and a strided matrix :attr:`mat2`. The
result is a (1 + 1)-dimensional :ref:`hybrid COO matrix
<sparse-hybrid-coo-docs>`.
Args:
mat1 (Tensor): the first sparse matrix to be matrix multiplied
mat2 (Tensor): the second strided matrix to be matrix multiplied
Keyword args:
out (Tensor, optional): the output tensor.
hstack(...)
hstack(tensors, *, out=None) -> Tensor
Stack tensors in sequence horizontally (column wise).
This is equivalent to concatenation along the first axis for 1-D tensors, and along the second axis for all other tensors.
Args:
tensors (sequence of Tensors): sequence of tensors to concatenate
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([1, 2, 3])
>>> b = torch.tensor([4, 5, 6])
>>> torch.hstack((a,b))
tensor([1, 2, 3, 4, 5, 6])
>>> a = torch.tensor([[1],[2],[3]])
>>> b = torch.tensor([[4],[5],[6]])
>>> torch.hstack((a,b))
tensor([[1, 4],
[2, 5],
[3, 6]])
hypot(...)
hypot(input, other, *, out=None) -> Tensor
Given the legs of a right triangle, return its hypotenuse.
.. math::
\text{out}_{i} = \sqrt{\text{input}_{i}^{2} + \text{other}_{i}^{2}}
The shapes of ``input`` and ``other`` must be
:ref:`broadcastable <broadcasting-semantics>`.
Args:
input (Tensor): the first input tensor
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.hypot(torch.tensor([4.0]), torch.tensor([3.0, 4.0, 5.0]))
tensor([5.0000, 5.6569, 6.4031])
i0(...)
i0(input, *, out=None) -> Tensor
Alias for :func:`torch.special.i0`.
i0_(...)
igamma(...)
igamma(input, other, *, out=None) -> Tensor
Alias for :func:`torch.special.gammainc`.
igammac(...)
igammac(input, other, *, out=None) -> Tensor
Alias for :func:`torch.special.gammaincc`.
imag(...)
imag(input) -> Tensor
Returns a new tensor containing imaginary values of the :attr:`self` tensor.
The returned tensor and :attr:`self` share the same underlying storage.
.. warning::
:func:`imag` is only supported for tensors with complex dtypes.
Args:
input (Tensor): the input tensor.
Example::
>>> x=torch.randn(4, dtype=torch.cfloat)
>>> x
tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
>>> x.imag
tensor([ 0.3553, -0.7896, -0.0633, -0.8119])
import_ir_module(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
import_ir_module(arg0: torch._C.CompilationUnit, arg1: str, arg2: object, arg3: dict, arg4: bool) -> torch._C.ScriptModule
import_ir_module_from_buffer(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
import_ir_module_from_buffer(arg0: torch._C.CompilationUnit, arg1: str, arg2: object, arg3: dict, arg4: bool) -> torch._C.ScriptModule
index_add(...)
index_add(input: Tensor, dim: int, index: Tensor, source: Tensor, *, alpha: Union[Number, _complex] = 1, out: Optional[Tensor]) -> Tensor # noqa: B950
See :meth:`~Tensor.index_add_` for function description.
index_copy(...)
index_copy(input: Tensor, dim: int, index: Tensor, source: Tensor, *, out: Optional[Tensor]) -> Tensor
See :meth:`~Tensor.index_copy_` for function description.
index_fill(...)
index_put(...)
index_put_(...)
index_reduce(...)
index_reduce(input: Tensor, dim: int, index: Tensor, source: Tensor, reduce: str, *, include_self: bool = True, out: Optional[Tensor]) -> Tensor # noqa: B950
See :meth:`~Tensor.index_reduce_` for function description.
index_select(...)
index_select(input, dim, index, *, out=None) -> Tensor
Returns a new tensor which indexes the :attr:`input` tensor along dimension
:attr:`dim` using the entries in :attr:`index`.
The returned tensor has the same number of dimensions as the original tensor
(:attr:`input`). The :attr:`dim`\ th dimension has the same size as the length
of :attr:`index`; other dimensions have the same size as in the original tensor.
.. note:: The returned tensor does **not** use the same storage as the original
tensor. If :attr:`out` has a different shape than expected, we
silently change it to the correct shape, reallocating the underlying
storage if necessary.
Args:
input (Tensor): the input tensor.
dim (int): the dimension in which we index
index (IntTensor or LongTensor): the 1-D tensor containing the indices to index
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.randn(3, 4)
>>> x
tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
[-0.4664, 0.2647, -0.1228, -1.1068],
[-1.1734, -0.6571, 0.7230, -0.6004]])
>>> indices = torch.tensor([0, 2])
>>> torch.index_select(x, 0, indices)
tensor([[ 0.1427, 0.0231, -0.5414, -1.0009],
[-1.1734, -0.6571, 0.7230, -0.6004]])
>>> torch.index_select(x, 1, indices)
tensor([[ 0.1427, -0.5414],
[-0.4664, -0.1228],
[-1.1734, 0.7230]])
indices_copy(...)
Performs the same operation as :func:`torch.indices`, but all output tensors
are freshly created instead of aliasing the input.
init_num_threads(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
init_num_threads() -> None
init_num_threads()
Initializes the number of parallel threads used on the current thread.
Call this whenever a new thread is created in order to propagate values from
:func:`torch.set_num_threads` onto the new thread.
initial_seed() -> int
Returns the initial seed for generating random numbers as a
Python `long`.
.. note:: The returned seed is for the default generator on CPU only.
inner(...)
inner(input, other, *, out=None) -> Tensor
Computes the dot product for 1D tensors. For higher dimensions, sums the product
of elements from :attr:`input` and :attr:`other` along their last dimension.
.. note::
If either :attr:`input` or :attr:`other` is a scalar, the result is equivalent
to `torch.mul(input, other)`.
If both :attr:`input` and :attr:`other` are non-scalars, the size of their last
dimension must match and the result is equivalent to `torch.tensordot(input,
other, dims=([-1], [-1]))`
Args:
input (Tensor): First input tensor
other (Tensor): Second input tensor
Keyword args:
out (Tensor, optional): Optional output tensor to write result into. The output
shape is `input.shape[:-1] + other.shape[:-1]`.
Example::
# Dot product
>>> torch.inner(torch.tensor([1, 2, 3]), torch.tensor([0, 2, 1]))
tensor(7)
# Multidimensional input tensors
>>> a = torch.randn(2, 3)
>>> a
tensor([[0.8173, 1.0874, 1.1784],
[0.3279, 0.1234, 2.7894]])
>>> b = torch.randn(2, 4, 3)
>>> b
tensor([[[-0.4682, -0.7159, 0.1506],
[ 0.4034, -0.3657, 1.0387],
[ 0.9892, -0.6684, 0.1774],
[ 0.9482, 1.3261, 0.3917]],
[[ 0.4537, 0.7493, 1.1724],
[ 0.2291, 0.5749, -0.2267],
[-0.7920, 0.3607, -0.3701],
[ 1.3666, -0.5850, -1.7242]]])
>>> torch.inner(a, b)
tensor([[[-0.9837, 1.1560, 0.2907, 2.6785],
[ 2.5671, 0.5452, -0.6912, -1.5509]],
[[ 0.1782, 2.9843, 0.7366, 1.5672],
[ 3.5115, -0.4864, -1.2476, -4.4337]]])
# Scalar input
>>> torch.inner(a, torch.tensor(2))
tensor([[1.6347, 2.1748, 2.3567],
[0.6558, 0.2469, 5.5787]])
instance_norm(...)
int_repr(...)
inverse(...)
inverse(input, *, out=None) -> Tensor
Alias for :func:`torch.linalg.inv`
is_anomaly_check_nan_enabled(...)
is_anomaly_enabled(...)
is_autocast_cache_enabled(...)
is_autocast_cpu_enabled(...)
is_autocast_enabled(...)
is_autocast_ipu_enabled(...)
is_autocast_xla_enabled(...)
is_complex(...)
is_complex(input: Tensor) -> bool
Returns True if the data type of :attr:`input` is a complex data type i.e.,
one of ``torch.complex64``, and ``torch.complex128``.
Args:
input (Tensor): the input tensor.
Example::
>>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.complex64))
True
>>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.complex128))
True
>>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.int32))
False
>>> torch.is_complex(torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16))
False
is_conj(...)
is_conj(input) -> (bool)
Returns True if the :attr:`input` is a conjugated tensor, i.e. its conjugate bit is set to `True`.
Args:
input (Tensor): the input tensor.
is_deterministic_algorithms_warn_only_enabled() -> bool
Returns True if the global deterministic flag is set to warn only.
Refer to :func:`torch.use_deterministic_algorithms` documentation for more
details.
is_distributed(...)
is_floating_point(...)
is_floating_point(input: Tensor) -> bool
Returns True if the data type of :attr:`input` is a floating point data type i.e.,
one of ``torch.float64``, ``torch.float32``, ``torch.float16``, and ``torch.bfloat16``.
Args:
input (Tensor): the input tensor.
Example::
>>> torch.is_floating_point(torch.tensor([1.0, 2.0, 3.0]))
True
>>> torch.is_floating_point(torch.tensor([1, 2, 3], dtype=torch.int32))
False
>>> torch.is_floating_point(torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16))
True
>>> torch.is_floating_point(torch.tensor([1, 2, 3], dtype=torch.complex64))
False
is_grad_enabled(...)
is_grad_enabled() -> (bool)
Returns True if grad mode is currently enabled.
is_inference(...)
is_inference(input) -> (bool)
Returns True if :attr:`input` is an inference tensor.
A non-view tensor is an inference tensor if and only if it was
allocated during inference mode. A view tensor is an inference
tensor if and only if the tensor it is a view of is an inference tensor.
For details on inference mode please see
`Inference Mode <https://pytorch.org/cppdocs/notes/inference_mode.html>`_.
Args:
input (Tensor): the input tensor.
is_inference_mode_enabled(...)
is_inference_mode_enabled() -> (bool)
Returns True if inference mode is currently enabled.
is_neg(...)
is_nonzero(...)
is_nonzero(input) -> (bool)
Returns True if the :attr:`input` is a single element tensor which is not equal to zero
after type conversions.
i.e. not equal to ``torch.tensor([0.])`` or ``torch.tensor([0])`` or
``torch.tensor([False])``.
Throws a ``RuntimeError`` if ``torch.numel() != 1`` (even in case
of sparse tensors).
Args:
input (Tensor): the input tensor.
Examples::
>>> torch.is_nonzero(torch.tensor([0.]))
False
>>> torch.is_nonzero(torch.tensor([1.5]))
True
>>> torch.is_nonzero(torch.tensor([False]))
False
>>> torch.is_nonzero(torch.tensor([3]))
True
>>> torch.is_nonzero(torch.tensor([1, 3, 5]))
Traceback (most recent call last):
...
RuntimeError: Boolean value of Tensor with more than one value is ambiguous
>>> torch.is_nonzero(torch.tensor([]))
Traceback (most recent call last):
...
RuntimeError: Boolean value of Tensor with no values is ambiguous
is_same_size(...)
is_signed(...)
is_storage(obj: Any, /) -> TypeGuard[ForwardRef('TypedStorage | UntypedStorage')]
Returns True if `obj` is a PyTorch storage object.
Args:
obj (Object): Object to test
Example::
>>> import torch
>>> # UntypedStorage (recommended)
>>> tensor = torch.tensor([1, 2, 3])
>>> storage = tensor.untyped_storage()
>>> torch.is_storage(storage)
True
>>>
>>> # TypedStorage (legacy)
>>> typed_storage = torch.TypedStorage(5, dtype=torch.float32)
>>> torch.is_storage(typed_storage)
True
>>>
>>> # regular tensor (should return False)
>>> torch.is_storage(tensor)
False
>>>
>>> # non-storage object
>>> torch.is_storage([1, 2, 3])
False
is_tensor(obj: Any, /) -> typing_extensions.TypeIs[ForwardRef('torch.Tensor')]
Returns True if `obj` is a PyTorch tensor.
Args:
obj (object): Object to test
Example::
>>> x = torch.tensor([1, 2, 3])
>>> torch.is_tensor(x)
True
is_vulkan_available(...)
is_warn_always_enabled() -> bool
Returns True if the global warn_always flag is turned on. Refer to
:func:`torch.set_warn_always` documentation for more details.
isclose(...)
isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
Returns a new tensor with boolean elements representing if each element of
:attr:`input` is "close" to the corresponding element of :attr:`other`.
Closeness is defined as:
.. math::
\lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{rtol} \times \lvert \text{other}_i \rvert + \texttt{atol}
where :attr:`input` and :attr:`other` are finite. Where :attr:`input`
and/or :attr:`other` are nonfinite they are close if and only if
they are equal, with NaNs being considered equal to each other when
:attr:`equal_nan` is True.
Args:
input (Tensor): first tensor to compare
other (Tensor): second tensor to compare
rtol (float, optional): relative tolerance. Default: 1e-05
atol (float, optional): absolute tolerance. Default: 1e-08
equal_nan (bool, optional): if ``True``, then two ``NaN`` s will be considered equal. Default: ``False``
Examples::
>>> torch.isclose(torch.tensor((1., 2, 3)), torch.tensor((1 + 1e-10, 3, 4)))
tensor([ True, False, False])
>>> torch.isclose(torch.tensor((float('inf'), 4)), torch.tensor((float('inf'), 6)), rtol=.5)
tensor([True, True])
isfinite(...)
isfinite(input) -> Tensor
Returns a new tensor with boolean elements representing if each element is `finite` or not.
Real values are finite when they are not NaN, negative infinity, or infinity.
Complex values are finite when both their real and imaginary parts are finite.
Args:
input (Tensor): the input tensor.
Returns:
A boolean tensor that is True where :attr:`input` is finite and False elsewhere
Example::
>>> torch.isfinite(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
tensor([True, False, True, False, False])
isin(...)
isin(elements, test_elements, *, assume_unique=False, invert=False) -> Tensor
Tests if each element of :attr:`elements` is in :attr:`test_elements`. Returns
a boolean tensor of the same shape as :attr:`elements` that is True for elements
in :attr:`test_elements` and False otherwise.
.. note::
One of :attr:`elements` or :attr:`test_elements` can be a scalar, but not both.
Args:
elements (Tensor or Scalar): Input elements
test_elements (Tensor or Scalar): Values against which to test for each input element
assume_unique (bool, optional): If True, assumes both :attr:`elements` and
:attr:`test_elements` contain unique elements, which can speed up the
calculation. Default: False
invert (bool, optional): If True, inverts the boolean return tensor, resulting in True
values for elements *not* in :attr:`test_elements`. Default: False
Returns:
A boolean tensor of the same shape as :attr:`elements` that is True for elements in
:attr:`test_elements` and False otherwise
Example:
>>> torch.isin(torch.tensor([[1, 2], [3, 4]]), torch.tensor([2, 3]))
tensor([[False, True],
[ True, False]])
isinf(...)
isinf(input) -> Tensor
Tests if each element of :attr:`input` is infinite
(positive or negative infinity) or not.
.. note::
Complex values are infinite when their real or imaginary part is
infinite.
Args:
input (Tensor): the input tensor.
Returns:
A boolean tensor that is True where :attr:`input` is infinite and False elsewhere
Example::
>>> torch.isinf(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
tensor([False, True, False, True, False])
isnan(...)
isnan(input) -> Tensor
Returns a new tensor with boolean elements representing if each element of :attr:`input`
is NaN or not. Complex values are considered NaN when either their real
and/or imaginary part is NaN.
Arguments:
input (Tensor): the input tensor.
Returns:
A boolean tensor that is True where :attr:`input` is NaN and False elsewhere
Example::
>>> torch.isnan(torch.tensor([1, float('nan'), 2]))
tensor([False, True, False])
isneginf(...)
isneginf(input, *, out=None) -> Tensor
Tests if each element of :attr:`input` is negative infinity or not.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([-float('inf'), float('inf'), 1.2])
>>> torch.isneginf(a)
tensor([ True, False, False])
isposinf(...)
isposinf(input, *, out=None) -> Tensor
Tests if each element of :attr:`input` is positive infinity or not.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([-float('inf'), float('inf'), 1.2])
>>> torch.isposinf(a)
tensor([False, True, False])
isreal(...)
isreal(input) -> Tensor
Returns a new tensor with boolean elements representing if each element of :attr:`input` is real-valued or not.
All real-valued types are considered real. Complex values are considered real when their imaginary part is 0.
Arguments:
input (Tensor): the input tensor.
Returns:
A boolean tensor that is True where :attr:`input` is real and False elsewhere
Example::
>>> torch.isreal(torch.tensor([1, 1+1j, 2+0j]))
tensor([True, False, True])
istft(...)
istft(input, n_fft, hop_length=None, win_length=None, window=None, center=True, normalized=False, onesided=None, length=None, return_complex=False) -> Tensor:
Inverse short time Fourier Transform. This is expected to be the inverse of :func:`~torch.stft`.
.. warning::
From version 2.1, a warning will be provided if a :attr:`window` is
not specified. In a future release, this attribute will be required.
Please provide the same window used in the stft call.
It has the same parameters (+ additional optional parameter of :attr:`length`) and it should return the
least squares estimation of the original signal. The algorithm will check using the NOLA condition (
nonzero overlap).
Important consideration in the parameters :attr:`window` and :attr:`center` so that the envelope
created by the summation of all the windows is never zero at certain point in time. Specifically,
:math:`\sum_{t=-\infty}^{\infty} |w|^2[n-t\times hop\_length] \cancel{=} 0`.
Since :func:`~torch.stft` discards elements at the end of the signal if they do not fit in a frame,
``istft`` may return a shorter signal than the original signal (can occur if :attr:`center` is False
since the signal isn't padded). If `length` is given in the arguments and is longer than expected,
``istft`` will pad zeros to the end of the returned signal.
If :attr:`center` is ``True``, then there will be padding e.g. ``'constant'``, ``'reflect'``, etc.
Left padding can be trimmed off exactly because they can be calculated but right padding cannot be
calculated without additional information.
Example: Suppose the last window is:
``[17, 18, 0, 0, 0]`` vs ``[18, 0, 0, 0, 0]``
The :attr:`n_fft`, :attr:`hop_length`, :attr:`win_length` are all the same which prevents the calculation
of right padding. These additional values could be zeros or a reflection of the signal so providing
:attr:`length` could be useful. If :attr:`length` is ``None`` then padding will be aggressively removed
(some loss of signal).
[1] D. W. Griffin and J. S. Lim, "Signal estimation from modified short-time Fourier transform,"
IEEE Trans. ASSP, vol.32, no.2, pp.236-243, Apr. 1984.
Args:
input (Tensor): The input tensor. Expected to be in the format of :func:`~torch.stft`,
output. That is a complex tensor of shape `(B?, N, T)` where
- `B?` is an optional batch dimension
- `N` is the number of frequency samples, `(n_fft // 2) + 1`
for onesided input, or otherwise `n_fft`.
- `T` is the number of frames, `1 + length // hop_length` for centered stft,
or `1 + (length - n_fft) // hop_length` otherwise.
.. versionchanged:: 2.0
Real datatype inputs are no longer supported. Input must now have a
complex datatype, as returned by ``stft(..., return_complex=True)``.
n_fft (int): Size of Fourier transform
hop_length (Optional[int]): The distance between neighboring sliding window frames.
(Default: ``n_fft // 4``)
win_length (Optional[int]): The size of window frame and STFT filter. (Default: ``n_fft``)
window (Optional[torch.Tensor]): The optional window function.
Shape must be 1d and `<= n_fft`
(Default: ``torch.ones(win_length)``)
center (bool): Whether :attr:`input` was padded on both sides so that the :math:`t`-th frame is
centered at time :math:`t \times \text{hop\_length}`.
(Default: ``True``)
normalized (bool): Whether the STFT was normalized. (Default: ``False``)
onesided (Optional[bool]): Whether the STFT was onesided.
(Default: ``True`` if `n_fft != fft_size` in the input size)
length (Optional[int]): The amount to trim the signal by (i.e. the
original signal length). Defaults to `(T - 1) * hop_length` for
centered stft, or `n_fft + (T - 1) * hop_length` otherwise, where `T`
is the number of input frames.
return_complex (Optional[bool]):
Whether the output should be complex, or if the input should be
assumed to derive from a real signal and window.
Note that this is incompatible with ``onesided=True``.
(Default: ``False``)
Returns:
Tensor: Least squares estimation of the original signal of shape `(B?, length)` where
`B?` is an optional batch dimension from the input tensor.
kaiser_window(...)
kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Computes the Kaiser window with window length :attr:`window_length` and shape parameter :attr:`beta`.
Let I_0 be the zeroth order modified Bessel function of the first kind (see :func:`torch.i0`) and
``N = L - 1`` if :attr:`periodic` is False and ``L`` if :attr:`periodic` is True,
where ``L`` is the :attr:`window_length`. This function computes:
.. math::
out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )
Calling ``torch.kaiser_window(L, B, periodic=True)`` is equivalent to calling
``torch.kaiser_window(L + 1, B, periodic=False)[:-1])``.
The :attr:`periodic` argument is intended as a helpful shorthand
to produce a periodic window as input to functions like :func:`torch.stft`.
.. note::
If :attr:`window_length` is one, then the returned window is a single element tensor containing a one.
Args:
window_length (int): length of the window.
periodic (bool, optional): If True, returns a periodic window suitable for use in spectral analysis.
If False, returns a symmetric window suitable for use in filter design.
beta (float, optional): shape parameter for the window.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned window tensor. Only
``torch.strided`` (dense layout) is supported.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
kl_div(...)
kron(...)
kron(input, other, *, out=None) -> Tensor
Computes the Kronecker product, denoted by :math:`\otimes`, of :attr:`input` and :attr:`other`.
If :attr:`input` is a :math:`(a_0 \times a_1 \times \dots \times a_n)` tensor and :attr:`other` is a
:math:`(b_0 \times b_1 \times \dots \times b_n)` tensor, the result will be a
:math:`(a_0*b_0 \times a_1*b_1 \times \dots \times a_n*b_n)` tensor with the following entries:
.. math::
(\text{input} \otimes \text{other})_{k_0, k_1, \dots, k_n} =
\text{input}_{i_0, i_1, \dots, i_n} * \text{other}_{j_0, j_1, \dots, j_n},
where :math:`k_t = i_t * b_t + j_t` for :math:`0 \leq t \leq n`.
If one tensor has fewer dimensions than the other it is unsqueezed until it has the same number of dimensions.
Supports real-valued and complex-valued inputs.
.. note::
This function generalizes the typical definition of the Kronecker product for two matrices to two tensors,
as described above. When :attr:`input` is a :math:`(m \times n)` matrix and :attr:`other` is a
:math:`(p \times q)` matrix, the result will be a :math:`(p*m \times q*n)` block matrix:
.. math::
\mathbf{A} \otimes \mathbf{B}=\begin{bmatrix}
a_{11} \mathbf{B} & \cdots & a_{1 n} \mathbf{B} \\
\vdots & \ddots & \vdots \\
a_{m 1} \mathbf{B} & \cdots & a_{m n} \mathbf{B} \end{bmatrix}
where :attr:`input` is :math:`\mathbf{A}` and :attr:`other` is :math:`\mathbf{B}`.
Arguments:
input (Tensor)
other (Tensor)
Keyword args:
out (Tensor, optional): The output tensor. Ignored if ``None``. Default: ``None``
Examples::
>>> mat1 = torch.eye(2)
>>> mat2 = torch.ones(2, 2)
>>> torch.kron(mat1, mat2)
tensor([[1., 1., 0., 0.],
[1., 1., 0., 0.],
[0., 0., 1., 1.],
[0., 0., 1., 1.]])
>>> mat1 = torch.eye(2)
>>> mat2 = torch.arange(1, 5).reshape(2, 2)
>>> torch.kron(mat1, mat2)
tensor([[1., 2., 0., 0.],
[3., 4., 0., 0.],
[0., 0., 1., 2.],
[0., 0., 3., 4.]])
kthvalue(...)
kthvalue(input, k, dim=None, keepdim=False, *, out=None) -> (Tensor, LongTensor)
Returns a namedtuple ``(values, indices)`` where ``values`` is the :attr:`k` th
smallest element of each row of the :attr:`input` tensor in the given dimension
:attr:`dim`. And ``indices`` is the index location of each element found.
If :attr:`dim` is not given, the last dimension of the `input` is chosen.
If :attr:`keepdim` is ``True``, both the :attr:`values` and :attr:`indices` tensors
are the same size as :attr:`input`, except in the dimension :attr:`dim` where
they are of size 1. Otherwise, :attr:`dim` is squeezed
(see :func:`torch.squeeze`), resulting in both the :attr:`values` and
:attr:`indices` tensors having 1 fewer dimension than the :attr:`input` tensor.
.. note::
When :attr:`input` is a CUDA tensor and there are multiple valid
:attr:`k` th values, this function may nondeterministically return
:attr:`indices` for any of them.
Args:
input (Tensor): the input tensor.
k (int): k for the k-th smallest element
dim (int, optional): the dimension to find the kth value along
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (tuple, optional): the output tuple of (Tensor, LongTensor)
can be optionally given to be used as output buffers
Example::
>>> x = torch.arange(1., 6.)
>>> x
tensor([ 1., 2., 3., 4., 5.])
>>> torch.kthvalue(x, 4)
torch.return_types.kthvalue(values=tensor(4.), indices=tensor(3))
>>> x=torch.arange(1.,7.).resize_(2,3)
>>> x
tensor([[ 1., 2., 3.],
[ 4., 5., 6.]])
>>> torch.kthvalue(x, 2, 0, True)
torch.return_types.kthvalue(values=tensor([[4., 5., 6.]]), indices=tensor([[1, 1, 1]]))
layer_norm(...)
lcm(...)
lcm(input, other, *, out=None) -> Tensor
Computes the element-wise least common multiple (LCM) of :attr:`input` and :attr:`other`.
Both :attr:`input` and :attr:`other` must have integer types.
.. note::
This defines :math:`lcm(0, 0) = 0` and :math:`lcm(0, a) = 0`.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([5, 10, 15])
>>> b = torch.tensor([3, 4, 5])
>>> torch.lcm(a, b)
tensor([15, 20, 15])
>>> c = torch.tensor([3])
>>> torch.lcm(a, c)
tensor([15, 30, 15])
lcm_(...)
ldexp(...)
ldexp(input, other, *, out=None) -> Tensor
Multiplies :attr:`input` by 2 ** :attr:`other`.
.. math::
\text{{out}}_i = \text{{input}}_i * 2^\text{{other}}_i
Typically this function is used to construct floating point numbers by multiplying
mantissas in :attr:`input` with integral powers of two created from the exponents
in :attr:`other`.
Args:
input (Tensor): the input tensor.
other (Tensor): a tensor of exponents, typically integers.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.ldexp(torch.tensor([1.]), torch.tensor([1]))
tensor([2.])
>>> torch.ldexp(torch.tensor([1.0]), torch.tensor([1, 2, 3, 4]))
tensor([ 2., 4., 8., 16.])
ldexp_(...)
le(...)
le(input, other, *, out=None) -> Tensor
Computes :math:`\text{input} \leq \text{other}` element-wise.
The second argument can be a number or a tensor whose shape is
:ref:`broadcastable <broadcasting-semantics>` with the first argument.
Args:
input (Tensor): the tensor to compare
other (Tensor or Scalar): the tensor or value to compare
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
A boolean tensor that is True where :attr:`input` is less than or equal to
:attr:`other` and False elsewhere
Example::
>>> torch.le(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[True, False], [True, True]])
lerp(...)
lerp(input, end, weight, *, out=None)
Does a linear interpolation of two tensors :attr:`start` (given by :attr:`input`) and :attr:`end` based
on a scalar or tensor :attr:`weight` and returns the resulting :attr:`out` tensor.
.. math::
\text{out}_i = \text{start}_i + \text{weight}_i \times (\text{end}_i - \text{start}_i)
The shapes of :attr:`start` and :attr:`end` must be
:ref:`broadcastable <broadcasting-semantics>`. If :attr:`weight` is a tensor, then
the shapes of :attr:`weight`, :attr:`start`, and :attr:`end` must be :ref:`broadcastable <broadcasting-semantics>`.
Args:
input (Tensor): the tensor with the starting points
end (Tensor): the tensor with the ending points
weight (float or tensor): the weight for the interpolation formula
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> start = torch.arange(1., 5.)
>>> end = torch.empty(4).fill_(10)
>>> start
tensor([ 1., 2., 3., 4.])
>>> end
tensor([ 10., 10., 10., 10.])
>>> torch.lerp(start, end, 0.5)
tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
>>> torch.lerp(start, end, torch.full_like(start, 0.5))
tensor([ 5.5000, 6.0000, 6.5000, 7.0000])
less(...)
less(input, other, *, out=None) -> Tensor
Alias for :func:`torch.lt`.
less_equal(...)
less_equal(input, other, *, out=None) -> Tensor
Alias for :func:`torch.le`.
lgamma(...)
lgamma(input, *, out=None) -> Tensor
Computes the natural logarithm of the absolute value of the gamma function on :attr:`input`.
.. math::
\text{out}_{i} = \ln |\Gamma(\text{input}_{i})|
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.arange(0.5, 2, 0.5)
>>> torch.lgamma(a)
tensor([ 0.5724, 0.0000, -0.1208])
linspace(...)
linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
spaced from :attr:`start` to :attr:`end`, inclusive. That is, the value are:
.. math::
(\text{start},
\text{start} + \frac{\text{end} - \text{start}}{\text{steps} - 1},
\ldots,
\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{\text{steps} - 1},
\text{end})
From PyTorch 1.11 linspace requires the steps argument. Use steps=100 to restore the previous behavior.
Args:
start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
steps (int): size of the constructed tensor
Keyword arguments:
out (Tensor, optional): the output tensor.
dtype (torch.dtype, optional): the data type to perform the computation in.
Default: if None, uses the global default dtype (see torch.get_default_dtype())
when both :attr:`start` and :attr:`end` are real,
and corresponding complex dtype when either is complex.
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.linspace(3, 10, steps=5)
tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])
>>> torch.linspace(-10, 10, steps=5)
tensor([-10., -5., 0., 5., 10.])
>>> torch.linspace(start=-10, end=10, steps=5)
tensor([-10., -5., 0., 5., 10.])
>>> torch.linspace(start=-10, end=10, steps=1)
tensor([-10.])
load(f: Union[str, os.PathLike[str], IO[bytes]], map_location: collections.abc.Callable[[torch.types.Storage, str], torch.types.Storage] | torch.device | str | dict[str, str] | None = None, pickle_module: Any = None, *, weights_only: bool | None = None, mmap: bool | None = None, **pickle_load_args: Any) -> Any
load(f, map_location=None, pickle_module=pickle, *, weights_only=True, mmap=None, **pickle_load_args)
Loads an object saved with :func:`torch.save` from a file.
.. warning::
:func:`torch.load()` uses an unpickler under the hood. **Never load data from an untrusted source.**
See :ref:`weights-only-security` for more details.
:func:`torch.load` uses Python's unpickling facilities but treats storages,
which underlie tensors, specially. They are first deserialized on the
CPU and are then moved to the device they were saved from. If this fails
(e.g. because the run time system doesn't have certain devices), an exception
is raised. However, storages can be dynamically remapped to an alternative
set of devices using the :attr:`map_location` argument.
If :attr:`map_location` is a callable, it will be called once for each serialized
storage with two arguments: storage and location. The storage argument
will be the initial deserialization of the storage, residing on the CPU.
Each serialized storage has a location tag associated with it which
identifies the device it was saved from, and this tag is the second
argument passed to :attr:`map_location`. The builtin location tags are ``'cpu'``
for CPU tensors and ``'cuda:device_id'`` (e.g. ``'cuda:2'``) for CUDA tensors.
:attr:`map_location` should return either ``None`` or a storage. If
:attr:`map_location` returns a storage, it will be used as the final deserialized
object, already moved to the right device. Otherwise, :func:`torch.load` will
fall back to the default behavior, as if :attr:`map_location` wasn't specified.
If :attr:`map_location` is a :class:`torch.device` object or a string containing
a device tag, it indicates the location where all tensors should be loaded.
Otherwise, if :attr:`map_location` is a dict, it will be used to remap location tags
appearing in the file (keys), to ones that specify where to put the
storages (values).
User extensions can register their own location tags and tagging and
deserialization methods using :func:`torch.serialization.register_package`.
See :ref:`layout-control` for more advanced tools to manipulate a checkpoint.
Args:
f: a file-like object (has to implement :meth:`read`, :meth:`readline`, :meth:`tell`, and :meth:`seek`),
or a string or os.PathLike object containing a file name
map_location: a function, :class:`torch.device`, string or a dict specifying how to remap storage
locations
pickle_module: module used for unpickling metadata and objects (has to
match the :attr:`pickle_module` used to serialize file)
weights_only: Indicates whether unpickler should be restricted to
loading only tensors, primitive types, dictionaries
and any types added via :func:`torch.serialization.add_safe_globals`.
See :ref:`weights-only` for more details.
mmap: Indicates whether the file should be mapped rather than loading all the storages into memory.
Typically, tensor storages in the file will first be moved from disk to CPU memory, after which they
are moved to the location that they were tagged with when saving, or specified by ``map_location``. This
second step is a no-op if the final location is CPU. When the ``mmap`` flag is set, instead of copying the
tensor storages from disk to CPU memory in the first step, ``f`` is mapped, which means tensor storages
will be lazily loaded when their data is accessed.
pickle_load_args: optional keyword arguments passed over to
:func:`pickle_module.load` and :func:`pickle_module.Unpickler`,
only works if :attr:`weights_only=False`, e.g., :attr:`errors=...`.
.. note::
When you call :func:`torch.load()` on a file which contains GPU tensors, those tensors
will be loaded to GPU by default. You can call ``torch.load(.., map_location='cpu')``
and then :meth:`load_state_dict` to avoid GPU RAM surge when loading a model checkpoint.
.. note::
By default, we decode byte strings as ``utf-8``. This is to avoid a common error
case ``UnicodeDecodeError: 'ascii' codec can't decode byte 0x...``
when loading files saved by Python 2 in Python 3. If this default
is incorrect, you may use an extra :attr:`encoding` keyword argument to specify how
these objects should be loaded, e.g., :attr:`encoding='latin1'` decodes them
to strings using ``latin1`` encoding, and :attr:`encoding='bytes'` keeps them
as byte arrays which can be decoded later with ``byte_array.decode(...)``.
Example:
>>> # xdoctest: +SKIP("undefined filepaths")
>>> torch.load("tensors.pt", weights_only=True)
# Load all tensors onto the CPU
>>> torch.load(
... "tensors.pt",
... map_location=torch.device("cpu"),
... weights_only=True,
... )
# Load all tensors onto the CPU, using a function
>>> torch.load(
... "tensors.pt",
... map_location=lambda storage, loc: storage,
... weights_only=True,
... )
# Load all tensors onto GPU 1
>>> torch.load(
... "tensors.pt",
... map_location=lambda storage, loc: storage.cuda(1), # type: ignore[attr-defined]
... weights_only=True,
... ) # type: ignore[attr-defined]
# Map tensors from GPU 1 to GPU 0
>>> torch.load(
... "tensors.pt",
... map_location={"cuda:1": "cuda:0"},
... weights_only=True,
... )
# Load tensor from io.BytesIO object
# Loading from a buffer setting weights_only=False, warning this can be unsafe
>>> with open("tensor.pt", "rb") as f:
... buffer = io.BytesIO(f.read())
>>> torch.load(buffer, weights_only=False)
# Load a module with 'ascii' encoding for unpickling
# Loading from a module setting weights_only=False, warning this can be unsafe
>>> torch.load("module.pt", encoding="ascii", weights_only=False)
lobpcg(A: torch.Tensor, k: int | None = None, B: torch.Tensor | None = None, X: torch.Tensor | None = None, n: int | None = None, iK: torch.Tensor | None = None, niter: int | None = None, tol: float | None = None, largest: bool | None = None, method: str | None = None, tracker: None = None, ortho_iparams: dict[str, int] | None = None, ortho_fparams: dict[str, float] | None = None, ortho_bparams: dict[str, bool] | None = None) -> tuple[torch.Tensor, torch.Tensor]
Find the k largest (or smallest) eigenvalues and the corresponding
eigenvectors of a symmetric positive definite generalized
eigenvalue problem using matrix-free LOBPCG methods.
This function is a front-end to the following LOBPCG algorithms
selectable via `method` argument:
`method="basic"` - the LOBPCG method introduced by Andrew
Knyazev, see [Knyazev2001]. A less robust method, may fail when
Cholesky is applied to singular input.
`method="ortho"` - the LOBPCG method with orthogonal basis
selection [StathopoulosEtal2002]. A robust method.
Supported inputs are dense, sparse, and batches of dense matrices.
.. note:: In general, the basic method spends least time per
iteration. However, the robust methods converge much faster and
are more stable. So, the usage of the basic method is generally
not recommended but there exist cases where the usage of the
basic method may be preferred.
.. warning:: The backward method does not support sparse and complex inputs.
It works only when `B` is not provided (i.e. `B == None`).
We are actively working on extensions, and the details of
the algorithms are going to be published promptly.
.. warning:: While it is assumed that `A` is symmetric, `A.grad` is not.
To make sure that `A.grad` is symmetric, so that `A - t * A.grad` is symmetric
in first-order optimization routines, prior to running `lobpcg`
we do the following symmetrization map: `A -> (A + A.t()) / 2`.
The map is performed only when the `A` requires gradients.
.. warning:: LOBPCG algorithm is not applicable when the number of `A`'s rows
is smaller than 3x the number of requested eigenpairs `n`.
Args:
A (Tensor): the input tensor of size :math:`(*, m, m)`
k (integer, optional): the number of requested
eigenpairs. Default is the number of :math:`X`
columns (when specified) or `1`.
B (Tensor, optional): the input tensor of size :math:`(*, m,
m)`. When not specified, `B` is interpreted as
identity matrix.
X (tensor, optional): the input tensor of size :math:`(*, m, n)`
where `k <= n <= m`. When specified, it is used as
initial approximation of eigenvectors. X must be a
dense tensor.
n (integer, optional): if :math:`X` is not specified then `n`
specifies the size of the generated random
approximation of eigenvectors. Default value for `n`
is `k`. If :math:`X` is specified, any provided value of `n` is
ignored and `n` is automatically set to the number of
columns in :math:`X`.
iK (tensor, optional): the input tensor of size :math:`(*, m,
m)`. When specified, it will be used as preconditioner.
niter (int, optional): maximum number of iterations. When
reached, the iteration process is hard-stopped and
the current approximation of eigenpairs is returned.
For infinite iteration but until convergence criteria
is met, use `-1`.
tol (float, optional): residual tolerance for stopping
criterion. Default is `feps ** 0.5` where `feps` is
smallest non-zero floating-point number of the given
input tensor `A` data type.
largest (bool, optional): when True, solve the eigenproblem for
the largest eigenvalues. Otherwise, solve the
eigenproblem for smallest eigenvalues. Default is
`True`.
method (str, optional): select LOBPCG method. See the
description of the function above. Default is
"ortho".
tracker (callable, optional) : a function for tracing the
iteration process. When specified, it is called at
each iteration step with LOBPCG instance as an
argument. The LOBPCG instance holds the full state of
the iteration process in the following attributes:
`iparams`, `fparams`, `bparams` - dictionaries of
integer, float, and boolean valued input
parameters, respectively
`ivars`, `fvars`, `bvars`, `tvars` - dictionaries
of integer, float, boolean, and Tensor valued
iteration variables, respectively.
`A`, `B`, `iK` - input Tensor arguments.
`E`, `X`, `S`, `R` - iteration Tensor variables.
For instance:
`ivars["istep"]` - the current iteration step
`X` - the current approximation of eigenvectors
`E` - the current approximation of eigenvalues
`R` - the current residual
`ivars["converged_count"]` - the current number of converged eigenpairs
`tvars["rerr"]` - the current state of convergence criteria
Note that when `tracker` stores Tensor objects from
the LOBPCG instance, it must make copies of these.
If `tracker` sets `bvars["force_stop"] = True`, the
iteration process will be hard-stopped.
ortho_iparams, ortho_fparams, ortho_bparams (dict, optional):
various parameters to LOBPCG algorithm when using
`method="ortho"`.
Returns:
E (Tensor): tensor of eigenvalues of size :math:`(*, k)`
X (Tensor): tensor of eigenvectors of size :math:`(*, m, k)`
References:
[Knyazev2001] Andrew V. Knyazev. (2001) Toward the Optimal
Preconditioned Eigensolver: Locally Optimal Block Preconditioned
Conjugate Gradient Method. SIAM J. Sci. Comput., 23(2),
517-541. (25 pages)
https://epubs.siam.org/doi/abs/10.1137/S1064827500366124
[StathopoulosEtal2002] Andreas Stathopoulos and Kesheng
Wu. (2002) A Block Orthogonalization Procedure with Constant
Synchronization Requirements. SIAM J. Sci. Comput., 23(6),
2165-2182. (18 pages)
https://epubs.siam.org/doi/10.1137/S1064827500370883
[DuerschEtal2018] Jed A. Duersch, Meiyue Shao, Chao Yang, Ming
Gu. (2018) A Robust and Efficient Implementation of LOBPCG.
SIAM J. Sci. Comput., 40(5), C655-C676. (22 pages)
https://arxiv.org/abs/1704.07458
log(...)
log(input, *, out=None) -> Tensor
Returns a new tensor with the natural logarithm of the elements
of :attr:`input`.
.. math::
y_{i} = \log_{e} (x_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(5) * 5
>>> a
tensor([4.7767, 4.3234, 1.2156, 0.2411, 4.5739])
>>> torch.log(a)
tensor([ 1.5637, 1.4640, 0.1952, -1.4226, 1.5204])
log10(...)
log10(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the logarithm to the base 10 of the elements
of :attr:`input`.
.. math::
y_{i} = \log_{10} (x_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(5)
>>> a
tensor([ 0.5224, 0.9354, 0.7257, 0.1301, 0.2251])
>>> torch.log10(a)
tensor([-0.2820, -0.0290, -0.1392, -0.8857, -0.6476])
log10_(...)
log1p(...)
log1p(input, *, out=None) -> Tensor
Returns a new tensor with the natural logarithm of (1 + :attr:`input`).
.. math::
y_i = \log_{e} (x_i + 1)
.. note:: This function is more accurate than :func:`torch.log` for small
values of :attr:`input`
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(5)
>>> a
tensor([-1.0090, -0.9923, 1.0249, -0.5372, 0.2492])
>>> torch.log1p(a)
tensor([ nan, -4.8653, 0.7055, -0.7705, 0.2225])
log1p_(...)
log2(...)
log2(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the logarithm to the base 2 of the elements
of :attr:`input`.
.. math::
y_{i} = \log_{2} (x_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.rand(5)
>>> a
tensor([ 0.8419, 0.8003, 0.9971, 0.5287, 0.0490])
>>> torch.log2(a)
tensor([-0.2483, -0.3213, -0.0042, -0.9196, -4.3504])
log2_(...)
log_(...)
log_softmax(...)
logaddexp(...)
logaddexp(input, other, *, out=None) -> Tensor
Logarithm of the sum of exponentiations of the inputs.
Calculates pointwise :math:`\log\left(e^x + e^y\right)`. This function is useful
in statistics where the calculated probabilities of events may be so small as to
exceed the range of normal floating point numbers. In such cases the logarithm
of the calculated probability is stored. This function allows adding
probabilities stored in such a fashion.
This op should be disambiguated with :func:`torch.logsumexp` which performs a
reduction on a single tensor.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> torch.logaddexp(torch.tensor([-1.0]), torch.tensor([-1.0, -2, -3]))
tensor([-0.3069, -0.6867, -0.8731])
>>> torch.logaddexp(torch.tensor([-100.0, -200, -300]), torch.tensor([-1.0, -2, -3]))
tensor([-1., -2., -3.])
>>> torch.logaddexp(torch.tensor([1.0, 2000, 30000]), torch.tensor([-1.0, -2, -3]))
tensor([1.1269e+00, 2.0000e+03, 3.0000e+04])
logaddexp2(...)
logaddexp2(input, other, *, out=None) -> Tensor
Logarithm of the sum of exponentiations of the inputs in base-2.
Calculates pointwise :math:`\log_2\left(2^x + 2^y\right)`. See
:func:`torch.logaddexp` for more details.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword arguments:
out (Tensor, optional): the output tensor.
logcumsumexp(...)
logcumsumexp(input, dim, *, out=None) -> Tensor
Returns the logarithm of the cumulative summation of the exponentiation of
elements of :attr:`input` in the dimension :attr:`dim`.
For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
.. math::
\text{logcumsumexp}(x)_{ij} = \log \sum\limits_{k=0}^{j} \exp(x_{ik})
Args:
input (Tensor): the input tensor.
dim (int): the dimension to do the operation over
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(10)
>>> torch.logcumsumexp(a, dim=0)
tensor([-0.42296738, -0.04462666, 0.86278635, 0.94622083, 1.05277811,
1.39202815, 1.83525007, 1.84492621, 2.06084887, 2.06844475]))
logdet(...)
logdet(input) -> Tensor
Calculates log determinant of a square matrix or batches of square matrices.
It returns ``-inf`` if the input has a determinant of zero, and ``NaN`` if it has
a negative determinant.
.. note::
Backward through :meth:`logdet` internally uses SVD results when :attr:`input`
is not invertible. In this case, double backward through :meth:`logdet` will
be unstable in when :attr:`input` doesn't have distinct singular values. See
:func:`torch.linalg.svd` for details.
.. seealso::
:func:`torch.linalg.slogdet` computes the sign (resp. angle) and natural logarithm of the
absolute value of the determinant of real-valued (resp. complex) square matrices.
Arguments:
input (Tensor): the input tensor of size ``(*, n, n)`` where ``*`` is zero or more
batch dimensions.
Example::
>>> A = torch.randn(3, 3)
>>> torch.det(A)
tensor(0.2611)
>>> torch.logdet(A)
tensor(-1.3430)
>>> A
tensor([[[ 0.9254, -0.6213],
[-0.5787, 1.6843]],
[[ 0.3242, -0.9665],
[ 0.4539, -0.0887]],
[[ 1.1336, -0.4025],
[-0.7089, 0.9032]]])
>>> A.det()
tensor([1.1990, 0.4099, 0.7386])
>>> A.det().log()
tensor([ 0.1815, -0.8917, -0.3031])
logical_and(...)
logical_and(input, other, *, out=None) -> Tensor
Computes the element-wise logical AND of the given input tensors. Zeros are treated as ``False`` and nonzeros are
treated as ``True``.
Args:
input (Tensor): the input tensor.
other (Tensor): the tensor to compute AND with
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.logical_and(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
tensor([ True, False, False])
>>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
>>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
>>> torch.logical_and(a, b)
tensor([False, False, True, False])
>>> torch.logical_and(a.double(), b.double())
tensor([False, False, True, False])
>>> torch.logical_and(a.double(), b)
tensor([False, False, True, False])
>>> torch.logical_and(a, b, out=torch.empty(4, dtype=torch.bool))
tensor([False, False, True, False])
logical_not(...)
logical_not(input, *, out=None) -> Tensor
Computes the element-wise logical NOT of the given input tensor. If not specified, the output tensor will have the bool
dtype. If the input tensor is not a bool tensor, zeros are treated as ``False`` and non-zeros are treated as ``True``.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.logical_not(torch.tensor([True, False]))
tensor([False, True])
>>> torch.logical_not(torch.tensor([0, 1, -10], dtype=torch.int8))
tensor([ True, False, False])
>>> torch.logical_not(torch.tensor([0., 1.5, -10.], dtype=torch.double))
tensor([ True, False, False])
>>> torch.logical_not(torch.tensor([0., 1., -10.], dtype=torch.double), out=torch.empty(3, dtype=torch.int16))
tensor([1, 0, 0], dtype=torch.int16)
logical_or(...)
logical_or(input, other, *, out=None) -> Tensor
Computes the element-wise logical OR of the given input tensors. Zeros are treated as ``False`` and nonzeros are
treated as ``True``.
Args:
input (Tensor): the input tensor.
other (Tensor): the tensor to compute OR with
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.logical_or(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
tensor([ True, False, True])
>>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
>>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
>>> torch.logical_or(a, b)
tensor([ True, True, True, False])
>>> torch.logical_or(a.double(), b.double())
tensor([ True, True, True, False])
>>> torch.logical_or(a.double(), b)
tensor([ True, True, True, False])
>>> torch.logical_or(a, b, out=torch.empty(4, dtype=torch.bool))
tensor([ True, True, True, False])
logical_xor(...)
logical_xor(input: Tensor, other: Tensor, *, out: Optional[Tensor]) -> Tensor
Computes the element-wise logical XOR of the given input tensors. Zeros are treated as ``False`` and nonzeros are
treated as ``True``.
Args:
input (Tensor): the input tensor.
other (Tensor): the tensor to compute XOR with
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.logical_xor(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
tensor([False, False, True])
>>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
>>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
>>> torch.logical_xor(a, b)
tensor([ True, True, False, False])
>>> torch.logical_xor(a.double(), b.double())
tensor([ True, True, False, False])
>>> torch.logical_xor(a.double(), b)
tensor([ True, True, False, False])
>>> torch.logical_xor(a, b, out=torch.empty(4, dtype=torch.bool))
tensor([ True, True, False, False])
logit(...)
logit(input, eps=None, *, out=None) -> Tensor
Alias for :func:`torch.special.logit`.
logit_(...)
logspace(...)
logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Creates a one-dimensional tensor of size :attr:`steps` whose values are evenly
spaced from :math:`{{\text{{base}}}}^{{\text{{start}}}}` to
:math:`{{\text{{base}}}}^{{\text{{end}}}}`, inclusive, on a logarithmic scale
with base :attr:`base`. That is, the values are:
.. math::
(\text{base}^{\text{start}},
\text{base}^{(\text{start} + \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
\ldots,
\text{base}^{(\text{start} + (\text{steps} - 2) * \frac{\text{end} - \text{start}}{ \text{steps} - 1})},
\text{base}^{\text{end}})
From PyTorch 1.11 logspace requires the steps argument. Use steps=100 to restore the previous behavior.
Args:
start (float or Tensor): the starting value for the set of points. If `Tensor`, it must be 0-dimensional
end (float or Tensor): the ending value for the set of points. If `Tensor`, it must be 0-dimensional
steps (int): size of the constructed tensor
base (float, optional): base of the logarithm function. Default: ``10.0``.
Keyword arguments:
out (Tensor, optional): the output tensor.
dtype (torch.dtype, optional): the data type to perform the computation in.
Default: if None, uses the global default dtype (see torch.get_default_dtype())
when both :attr:`start` and :attr:`end` are real,
and corresponding complex dtype when either is complex.
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.logspace(start=-10, end=10, steps=5)
tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10])
>>> torch.logspace(start=0.1, end=1.0, steps=5)
tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000])
>>> torch.logspace(start=0.1, end=1.0, steps=1)
tensor([1.2589])
>>> torch.logspace(start=2, end=2, steps=1, base=2)
tensor([4.0])
logsumexp(...)
logsumexp(input, dim, keepdim=False, *, out=None)
Returns the log of summed exponentials of each row of the :attr:`input`
tensor in the given dimension :attr:`dim`. The computation is numerically
stabilized.
For summation index :math:`j` given by `dim` and other indices :math:`i`, the result is
.. math::
\text{logsumexp}(x)_{i} = \log \sum_j \exp(x_{ij})
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints): the dimension or dimensions to reduce.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(3, 3)
>>> torch.logsumexp(a, 1)
tensor([1.4907, 1.0593, 1.5696])
>>> torch.dist(torch.logsumexp(a, 1), torch.log(torch.sum(torch.exp(a), 1)))
tensor(1.6859e-07)
lstm(...)
lstm_cell(...)
lt(...)
lt(input, other, *, out=None) -> Tensor
Computes :math:`\text{input} < \text{other}` element-wise.
The second argument can be a number or a tensor whose shape is
:ref:`broadcastable <broadcasting-semantics>` with the first argument.
Args:
input (Tensor): the tensor to compare
other (Tensor or float): the tensor or value to compare
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
A boolean tensor that is True where :attr:`input` is less than :attr:`other` and False elsewhere
Example::
>>> torch.lt(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[False, False], [True, False]])
lu_solve(...)
lu_solve(b, LU_data, LU_pivots, *, out=None) -> Tensor
Returns the LU solve of the linear system :math:`Ax = b` using the partially pivoted
LU factorization of A from :func:`~linalg.lu_factor`.
This function supports ``float``, ``double``, ``cfloat`` and ``cdouble`` dtypes for :attr:`input`.
.. warning::
:func:`torch.lu_solve` is deprecated in favor of :func:`torch.linalg.lu_solve`.
:func:`torch.lu_solve` will be removed in a future PyTorch release.
``X = torch.lu_solve(B, LU, pivots)`` should be replaced with
.. code:: python
X = linalg.lu_solve(LU, pivots, B)
Arguments:
b (Tensor): the RHS tensor of size :math:`(*, m, k)`, where :math:`*`
is zero or more batch dimensions.
LU_data (Tensor): the pivoted LU factorization of A from :meth:`~linalg.lu_factor` of size :math:`(*, m, m)`,
where :math:`*` is zero or more batch dimensions.
LU_pivots (IntTensor): the pivots of the LU factorization from :meth:`~linalg.lu_factor` of size :math:`(*, m)`,
where :math:`*` is zero or more batch dimensions.
The batch dimensions of :attr:`LU_pivots` must be equal to the batch dimensions of
:attr:`LU_data`.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> A = torch.randn(2, 3, 3)
>>> b = torch.randn(2, 3, 1)
>>> LU, pivots = torch.linalg.lu_factor(A)
>>> x = torch.lu_solve(b, LU, pivots)
>>> torch.dist(A @ x, b)
tensor(1.00000e-07 *
2.8312)
lu_unpack(...)
lu_unpack(LU_data, LU_pivots, unpack_data=True, unpack_pivots=True, *, out=None) -> (Tensor, Tensor, Tensor)
Unpacks the LU decomposition returned by :func:`~linalg.lu_factor` into the `P, L, U` matrices.
.. seealso::
:func:`~linalg.lu` returns the matrices from the LU decomposition. Its gradient formula is more efficient
than that of doing :func:`~linalg.lu_factor` followed by :func:`~linalg.lu_unpack`.
Args:
LU_data (Tensor): the packed LU factorization data
LU_pivots (Tensor): the packed LU factorization pivots
unpack_data (bool): flag indicating if the data should be unpacked.
If ``False``, then the returned ``L`` and ``U`` are empty tensors.
Default: ``True``
unpack_pivots (bool): flag indicating if the pivots should be unpacked into a permutation matrix ``P``.
If ``False``, then the returned ``P`` is an empty tensor.
Default: ``True``
Keyword args:
out (tuple, optional): output tuple of three tensors. Ignored if `None`.
Returns:
A namedtuple ``(P, L, U)``
Examples::
>>> A = torch.randn(2, 3, 3)
>>> LU, pivots = torch.linalg.lu_factor(A)
>>> P, L, U = torch.lu_unpack(LU, pivots)
>>> # We can recover A from the factorization
>>> A_ = P @ L @ U
>>> torch.allclose(A, A_)
True
>>> # LU factorization of a rectangular matrix:
>>> A = torch.randn(2, 3, 2)
>>> LU, pivots = torch.linalg.lu_factor(A)
>>> P, L, U = torch.lu_unpack(LU, pivots)
>>> # P, L, U are the same as returned by linalg.lu
>>> P_, L_, U_ = torch.linalg.lu(A)
>>> torch.allclose(P, P_) and torch.allclose(L, L_) and torch.allclose(U, U_)
True
manual_seed(seed) -> torch._C.Generator
Sets the seed for generating random numbers on all devices. Returns a
`torch.Generator` object.
Args:
seed (int): The desired seed. Value must be within the inclusive range
`[-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]`. Otherwise, a RuntimeError
is raised. Negative inputs are remapped to positive values with the formula
`0xffff_ffff_ffff_ffff + seed`.
margin_ranking_loss(...)
masked_fill(...)
masked_scatter(...)
masked_select(...)
masked_select(input, mask, *, out=None) -> Tensor
Returns a new 1-D tensor which indexes the :attr:`input` tensor according to
the boolean mask :attr:`mask` which is a `BoolTensor`.
The shapes of the :attr:`mask` tensor and the :attr:`input` tensor don't need
to match, but they must be :ref:`broadcastable <broadcasting-semantics>`.
.. note:: The returned tensor does **not** use the same storage
as the original tensor
Args:
input (Tensor): the input tensor.
mask (BoolTensor): the tensor containing the binary mask to index with
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.randn(3, 4)
>>> x
tensor([[ 0.3552, -2.3825, -0.8297, 0.3477],
[-1.2035, 1.2252, 0.5002, 0.6248],
[ 0.1307, -2.0608, 0.1244, 2.0139]])
>>> mask = x.ge(0.5)
>>> mask
tensor([[False, False, False, False],
[False, True, True, True],
[False, False, False, True]])
>>> torch.masked_select(x, mask)
tensor([ 1.2252, 0.5002, 0.6248, 2.0139])
matmul(...)
matmul(input, other, *, out=None) -> Tensor
Matrix product of two tensors.
The behavior depends on the dimensionality of the tensors as follows:
- If both tensors are 1-dimensional, the dot product (scalar) is returned.
- If both arguments are 2-dimensional, the matrix-matrix product is returned.
- If the first argument is 1-dimensional and the second argument is 2-dimensional,
a 1 is prepended to its dimension for the purpose of the matrix multiply.
After the matrix multiply, the prepended dimension is removed.
- If the first argument is 2-dimensional and the second argument is 1-dimensional,
the matrix-vector product is returned.
- If both arguments are at least 1-dimensional and at least one argument is
N-dimensional (where N > 2), then a batched matrix multiply is returned. If the first
argument is 1-dimensional, a 1 is prepended to its dimension for the purpose of the
batched matrix multiply and removed after. If the second argument is 1-dimensional, a
1 is appended to its dimension for the purpose of the batched matrix multiply and removed after.
The first N-2 dimensions of each argument, the batch dimensions, are
:ref:`broadcast <broadcasting-semantics>` (and thus must be broadcastable).
The last 2, the matrix dimensions, are handled as in the matrix-matrix product.
For example, if :attr:`input` is a
:math:`(j \times 1 \times n \times m)` tensor and :attr:`other` is a :math:`(k \times m \times p)`
tensor, the batch dimensions are :math:`(j \times 1)` and :math:`(k)`,
and the matrix dimensions are :math:`(n \times m)` and :math:`(m \times p)`.
:attr:`out` will be a :math:`(j \times k \times n \times p)` tensor.
This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`. In particular the
matrix-matrix (both arguments 2-dimensional) supports sparse arguments with the same restrictions
as :func:`torch.mm`
.. warning::
Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
or may not have autograd support. If you notice missing functionality please
open a feature request.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
.. note::
The 1-dimensional dot product version of this function does not support an :attr:`out` parameter.
Arguments:
input (Tensor): the first tensor to be multiplied
other (Tensor): the second tensor to be multiplied
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> # vector x vector
>>> tensor1 = torch.randn(3)
>>> tensor2 = torch.randn(3)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([])
>>> # matrix x vector
>>> tensor1 = torch.randn(3, 4)
>>> tensor2 = torch.randn(4)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([3])
>>> # batched matrix x broadcasted vector
>>> tensor1 = torch.randn(10, 3, 4)
>>> tensor2 = torch.randn(4)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([10, 3])
>>> # batched matrix x batched matrix
>>> tensor1 = torch.randn(10, 3, 4)
>>> tensor2 = torch.randn(10, 4, 5)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([10, 3, 5])
>>> # batched matrix x broadcasted matrix
>>> tensor1 = torch.randn(10, 3, 4)
>>> tensor2 = torch.randn(4, 5)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([10, 3, 5])
matrix_exp(...)
matrix_exp(A) -> Tensor
Alias for :func:`torch.linalg.matrix_exp`.
matrix_power(...)
matrix_power(input, n, *, out=None) -> Tensor
Alias for :func:`torch.linalg.matrix_power`
max(...)
max(input, *, out=None) -> Tensor
Returns the maximum value of all elements in the ``input`` tensor.
.. note::
The difference between ``max``/``min`` and ``amax``/``amin`` is:
- ``amax``/``amin`` supports reducing on multiple dimensions,
- ``amax``/``amin`` does not return indices.
Both ``amax``/``amin`` evenly distribute gradients between equal values
when there are multiple input elements with the same minimum or maximum value.
For ``max``/``min``:
- If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
- If reduce over one specified axis, only propagate to the indexed element.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.6763, 0.7445, -2.2369]])
>>> torch.max(a)
tensor(0.7445)
.. function:: max(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
:noindex:
Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
value of each row of the :attr:`input` tensor in the given dimension
:attr:`dim`. And ``indices`` is the index location of each maximum value found
(argmax).
If ``keepdim`` is ``True``, the output tensors are of the same size
as ``input`` except in the dimension ``dim`` where they are of size 1.
Otherwise, ``dim`` is squeezed (see :func:`torch.squeeze`), resulting
in the output tensors having 1 fewer dimension than ``input``.
.. note:: If there are multiple maximal values in a reduced row then
the indices of the first maximal value are returned.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (tuple, optional): the result tuple of two output tensors (max, max_indices)
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
[ 1.1949, -1.1127, -2.2379, -0.6702],
[ 1.5717, -0.9207, 0.1297, -1.8768],
[-0.6172, 1.0036, -0.6060, -0.2432]])
>>> torch.max(a, 1)
torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
>>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
>>> a.max(dim=1, keepdim=True)
torch.return_types.max(
values=tensor([[2.], [4.]]),
indices=tensor([[1], [1]]))
>>> a.max(dim=1, keepdim=False)
torch.return_types.max(
values=tensor([2., 4.]),
indices=tensor([1, 1]))
.. function:: max(input, other, *, out=None) -> Tensor
:noindex:
See :func:`torch.maximum`.
max_pool1d(...)
max_pool1d_with_indices(...)
max_pool2d(...)
max_pool3d(...)
maximum(...)
maximum(input, other, *, out=None) -> Tensor
Computes the element-wise maximum of :attr:`input` and :attr:`other`.
.. note::
If one of the elements being compared is a NaN, then that element is returned.
:func:`maximum` is not supported for tensors with complex dtypes.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor((1, 2, -1))
>>> b = torch.tensor((3, 0, 4))
>>> torch.maximum(a, b)
tensor([3, 2, 4])
mean(...)
mean(input, *, dtype=None) -> Tensor
.. note::
If the `input` tensor is empty, ``torch.mean()`` returns ``nan``.
This behavior is consistent with NumPy and follows the definition
that the mean over an empty set is undefined.
Returns the mean value of all elements in the :attr:`input` tensor. Input must be floating point or complex.
Args:
input (Tensor):
the input tensor, either of floating point or complex dtype
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.2294, -0.5481, 1.3288]])
>>> torch.mean(a)
tensor(0.3367)
.. function:: mean(input, dim, keepdim=False, *, dtype=None, out=None) -> Tensor
:noindex:
Returns the mean value of each row of the :attr:`input` tensor in the given
dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
reduce over all of them.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
out (Tensor, optional): the output tensor.
.. seealso::
:func:`torch.nanmean` computes the mean value of `non-NaN` elements.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[-0.3841, 0.6320, 0.4254, -0.7384],
[-0.9644, 1.0131, -0.6549, -1.4279],
[-0.2951, -1.3350, -0.7694, 0.5600],
[ 1.0842, -0.9580, 0.3623, 0.2343]])
>>> torch.mean(a, 1)
tensor([-0.0163, -0.5085, -0.4599, 0.1807])
>>> torch.mean(a, 1, True)
tensor([[-0.0163],
[-0.5085],
[-0.4599],
[ 0.1807]])
median(...)
median(input) -> Tensor
Returns the median of the values in :attr:`input`.
.. note::
The median is not unique for :attr:`input` tensors with an even number
of elements. In this case the lower of the two medians is returned. To
compute the mean of both medians, use :func:`torch.quantile` with ``q=0.5`` instead.
.. warning::
This function produces deterministic (sub)gradients unlike ``median(dim=0)``
Args:
input (Tensor): the input tensor.
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 1.5219, -1.5212, 0.2202]])
>>> torch.median(a)
tensor(0.2202)
.. function:: median(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
:noindex:
Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
in the dimension :attr:`dim`, and ``indices`` contains the index of the median values found in the dimension :attr:`dim`.
By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
If :attr:`keepdim` is ``True``, the output tensors are of the same size
as :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
the outputs tensor having 1 fewer dimension than :attr:`input`.
.. note::
The median is not unique for :attr:`input` tensors with an even number
of elements in the dimension :attr:`dim`. In this case the lower of the
two medians is returned. To compute the mean of both medians in
:attr:`input`, use :func:`torch.quantile` with ``q=0.5`` instead.
.. warning::
``indices`` does not necessarily contain the first occurrence of each
median value found, unless it is unique.
The exact implementation details are device-specific.
Do not expect the same result when run on CPU and GPU in general.
For the same reason do not expect the gradients to be deterministic.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
tensor, which must have dtype long, with their indices in the dimension
:attr:`dim` of :attr:`input`.
Example::
>>> a = torch.randn(4, 5)
>>> a
tensor([[ 0.2505, -0.3982, -0.9948, 0.3518, -1.3131],
[ 0.3180, -0.6993, 1.0436, 0.0438, 0.2270],
[-0.2751, 0.7303, 0.2192, 0.3321, 0.2488],
[ 1.0778, -1.9510, 0.7048, 0.4742, -0.7125]])
>>> torch.median(a, 1)
torch.return_types.median(values=tensor([-0.3982, 0.2270, 0.2488, 0.4742]), indices=tensor([1, 4, 4, 3]))
merge_type_from_type_comment(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
merge_type_from_type_comment(arg0: torch._C._jit_tree_views.Decl, arg1: torch._C._jit_tree_views.Decl, arg2: bool) -> torch._C._jit_tree_views.Decl
meshgrid(*tensors, indexing: str | None = None) -> tuple[torch.Tensor, ...]
Creates grids of coordinates specified by the 1D inputs in `attr`:tensors.
This is helpful when you want to visualize data over some
range of inputs. See below for a plotting example.
Given :math:`N` 1D tensors :math:`T_0 \ldots T_{N-1}` as
inputs with corresponding sizes :math:`S_0 \ldots S_{N-1}`,
this creates :math:`N` N-dimensional tensors :math:`G_0 \ldots
G_{N-1}`, each with shape :math:`(S_0, ..., S_{N-1})` where
the output :math:`G_i` is constructed by expanding :math:`T_i`
to the result shape.
.. note::
0D inputs are treated equivalently to 1D inputs of a
single element.
.. warning::
`torch.meshgrid(*tensors)` currently has the same behavior
as calling `numpy.meshgrid(*arrays, indexing='ij')`.
In the future `torch.meshgrid` will transition to
`indexing='xy'` as the default.
https://github.com/pytorch/pytorch/issues/50276 tracks
this issue with the goal of migrating to NumPy's behavior.
.. seealso::
:func:`torch.cartesian_prod` has the same effect but it
collects the data in a tensor of vectors.
Args:
tensors (list of Tensor): list of scalars or 1 dimensional tensors. Scalars will be
treated as tensors of size :math:`(1,)` automatically
indexing: (str, optional): the indexing mode, either "xy"
or "ij", defaults to "ij". See warning for future changes.
If "xy" is selected, the first dimension corresponds
to the cardinality of the second input and the second
dimension corresponds to the cardinality of the first
input.
If "ij" is selected, the dimensions are in the same
order as the cardinality of the inputs.
Returns:
seq (sequence of Tensors): If the input has :math:`N`
tensors of size :math:`S_0 \ldots S_{N-1}``, then the
output will also have :math:`N` tensors, where each tensor
is of shape :math:`(S_0, ..., S_{N-1})`.
Example::
>>> x = torch.tensor([1, 2, 3])
>>> y = torch.tensor([4, 5, 6])
Observe the element-wise pairings across the grid, (1, 4),
(1, 5), ..., (3, 6). This is the same thing as the
cartesian product.
>>> grid_x, grid_y = torch.meshgrid(x, y, indexing='ij')
>>> grid_x
tensor([[1, 1, 1],
[2, 2, 2],
[3, 3, 3]])
>>> grid_y
tensor([[4, 5, 6],
[4, 5, 6],
[4, 5, 6]])
This correspondence can be seen when these grids are
stacked properly.
>>> torch.equal(torch.cat(tuple(torch.dstack([grid_x, grid_y]))),
... torch.cartesian_prod(x, y))
True
`torch.meshgrid` is commonly used to produce a grid for
plotting.
>>> # xdoctest: +REQUIRES(module:matplotlib)
>>> # xdoctest: +REQUIRES(env:DOCTEST_SHOW)
>>> import matplotlib.pyplot as plt
>>> xs = torch.linspace(-5, 5, steps=100)
>>> ys = torch.linspace(-5, 5, steps=100)
>>> x, y = torch.meshgrid(xs, ys, indexing='xy')
>>> z = torch.sin(torch.sqrt(x * x + y * y))
>>> ax = plt.axes(projection='3d')
>>> ax.plot_surface(x.numpy(), y.numpy(), z.numpy())
>>> plt.show()
.. image:: ../_static/img/meshgrid.png
:width: 512
min(...)
min(input, *, out=None) -> Tensor
Returns the minimum value of all elements in the :attr:`input` tensor.
.. note::
The difference between ``max``/``min`` and ``amax``/``amin`` is:
- ``amax``/``amin`` supports reducing on multiple dimensions,
- ``amax``/``amin`` does not return indices.
Both ``amax``/``amin`` evenly distribute gradients between equal values
when there are multiple input elements with the same minimum or maximum value.
For ``max``/``min``:
- If reduce over all dimensions(no dim specified), gradients evenly distribute between equally ``max``/``min`` values.
- If reduce over one specified axis, only propagate to the indexed element.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.6750, 1.0857, 1.7197]])
>>> torch.min(a)
tensor(0.6750)
.. function:: min(input, dim, keepdim=False, *, out=None) -> (Tensor, LongTensor)
:noindex:
Returns a namedtuple ``(values, indices)`` where ``values`` is the minimum
value of each row of the :attr:`input` tensor in the given dimension
:attr:`dim`. And ``indices`` is the index location of each minimum value found
(argmin).
If :attr:`keepdim` is ``True``, the output tensors are of the same size as
:attr:`input` except in the dimension :attr:`dim` where they are of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
the output tensors having 1 fewer dimension than :attr:`input`.
.. note:: If there are multiple minimal values in a reduced row then
the indices of the first minimal value are returned.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce. If omitted, all dimensions are reduced. Explicit ``None`` is not supported.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (tuple, optional): the tuple of two output tensors (min, min_indices)
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[-0.6248, 1.1334, -1.1899, -0.2803],
[-1.4644, -0.2635, -0.3651, 0.6134],
[ 0.2457, 0.0384, 1.0128, 0.7015],
[-0.1153, 2.9849, 2.1458, 0.5788]])
>>> torch.min(a, 1)
torch.return_types.min(values=tensor([-1.1899, -1.4644, 0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
.. function:: min(input, other, *, out=None) -> Tensor
:noindex:
See :func:`torch.minimum`.
minimum(...)
minimum(input, other, *, out=None) -> Tensor
Computes the element-wise minimum of :attr:`input` and :attr:`other`.
.. note::
If one of the elements being compared is a NaN, then that element is returned.
:func:`minimum` is not supported for tensors with complex dtypes.
Args:
input (Tensor): the input tensor.
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor((1, 2, -1))
>>> b = torch.tensor((3, 0, 4))
>>> torch.minimum(a, b)
tensor([1, 0, -1])
miopen_batch_norm(...)
miopen_convolution(...)
miopen_convolution_add_relu(...)
miopen_convolution_relu(...)
miopen_convolution_transpose(...)
miopen_ctc_loss(...)
miopen_depthwise_convolution(...)
miopen_rnn(...)
mkldnn_adaptive_avg_pool2d(...)
mkldnn_convolution(...)
mkldnn_linear_backward_weights(...)
mkldnn_max_pool2d(...)
mkldnn_max_pool3d(...)
mkldnn_rnn_layer(...)
mm(...)
mm(input, mat2, *, out=None) -> Tensor
Performs a matrix multiplication of the matrices :attr:`input` and :attr:`mat2`.
If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`mat2` is a
:math:`(m \times p)` tensor, :attr:`out` will be a :math:`(n \times p)` tensor.
.. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
For broadcasting matrix products, see :func:`torch.matmul`.
Supports strided and sparse 2-D tensors as inputs, autograd with
respect to strided inputs.
This operation has support for arguments with :ref:`sparse layouts<sparse-docs>`.
If :attr:`out` is provided its layout will be used. Otherwise, the result
layout will be deduced from that of :attr:`input`.
.. warning::
Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,
or may not have autograd support. If you notice missing functionality please
open a feature request.
This operator supports :ref:`TensorFloat32<tf32_on_ampere>`.
On certain ROCm devices, when using float16 inputs this module will use :ref:`different precision<fp16_on_mi200>` for backward.
Args:
input (Tensor): the first matrix to be matrix multiplied
mat2 (Tensor): the second matrix to be matrix multiplied
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> mat1 = torch.randn(2, 3)
>>> mat2 = torch.randn(3, 3)
>>> torch.mm(mat1, mat2)
tensor([[ 0.4851, 0.5037, -0.3633],
[-0.0760, -3.6705, 2.4784]])
.. function:: mm(input, mat2, out_dtype, *, out=None) -> Tensor
:noindex:
Args:
input (Tensor): the first matrix to be matrix multiplied
mat2 (Tensor): the second matrix to be matrix multiplied
out_dtype (dtype): the dtype of the output tensor.
Supported only on CUDA and for torch.float32 given
torch.float16/torch.bfloat16 input dtypes.
Keyword args:
out (Tensor, optional): the output tensor.
mode(...)
mode(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
Returns a namedtuple ``(values, indices)`` where ``values`` is the mode
value of each row of the :attr:`input` tensor in the given dimension
:attr:`dim`, i.e. a value which appears most often
in that row, and ``indices`` is the index location of each mode value found.
By default, :attr:`dim` is the last dimension of the :attr:`input` tensor.
If :attr:`keepdim` is ``True``, the output tensors are of the same size as
:attr:`input` except in the dimension :attr:`dim` where they are of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting
in the output tensors having 1 fewer dimension than :attr:`input`.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out (tuple, optional): the result tuple of two output tensors (values, indices)
Example::
>>> b = torch.tensor([[0, 0, 0, 2, 0, 0, 2],
... [0, 3, 0, 0, 2, 0, 1],
... [2, 2, 2, 0, 0, 0, 3],
... [2, 2, 3, 0, 1, 1, 0],
... [1, 1, 0, 0, 2, 0, 2]])
>>> torch.mode(b, 0)
torch.return_types.mode(
values=tensor([0, 2, 0, 0, 0, 0, 2]),
indices=tensor([1, 3, 4, 4, 2, 4, 4]))
moveaxis(...)
moveaxis(input, source, destination) -> Tensor
Alias for :func:`torch.movedim`.
This function is equivalent to NumPy's moveaxis function.
Examples::
>>> t = torch.randn(3,2,1)
>>> t
tensor([[[-0.3362],
[-0.8437]],
[[-0.9627],
[ 0.1727]],
[[ 0.5173],
[-0.1398]]])
>>> torch.moveaxis(t, 1, 0).shape
torch.Size([2, 3, 1])
>>> torch.moveaxis(t, 1, 0)
tensor([[[-0.3362],
[-0.9627],
[ 0.5173]],
[[-0.8437],
[ 0.1727],
[-0.1398]]])
>>> torch.moveaxis(t, (1, 2), (0, 1)).shape
torch.Size([2, 1, 3])
>>> torch.moveaxis(t, (1, 2), (0, 1))
tensor([[[-0.3362, -0.9627, 0.5173]],
[[-0.8437, 0.1727, -0.1398]]])
movedim(...)
movedim(input, source, destination) -> Tensor
Moves the dimension(s) of :attr:`input` at the position(s) in :attr:`source`
to the position(s) in :attr:`destination`.
Other dimensions of :attr:`input` that are not explicitly moved remain in
their original order and appear at the positions not specified in :attr:`destination`.
Args:
input (Tensor): the input tensor.
source (int or tuple of ints): Original positions of the dims to move. These must be unique.
destination (int or tuple of ints): Destination positions for each of the original dims. These must also be unique.
Examples::
>>> t = torch.randn(3,2,1)
>>> t
tensor([[[-0.3362],
[-0.8437]],
[[-0.9627],
[ 0.1727]],
[[ 0.5173],
[-0.1398]]])
>>> torch.movedim(t, 1, 0).shape
torch.Size([2, 3, 1])
>>> torch.movedim(t, 1, 0)
tensor([[[-0.3362],
[-0.9627],
[ 0.5173]],
[[-0.8437],
[ 0.1727],
[-0.1398]]])
>>> torch.movedim(t, (1, 2), (0, 1)).shape
torch.Size([2, 1, 3])
>>> torch.movedim(t, (1, 2), (0, 1))
tensor([[[-0.3362, -0.9627, 0.5173]],
[[-0.8437, 0.1727, -0.1398]]])
msort(...)
msort(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Sorts the elements of the :attr:`input` tensor along its first dimension
in ascending order by value.
.. note:: `torch.msort(t)` is equivalent to `torch.sort(t, dim=0)[0]`.
See also :func:`torch.sort`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.randn(3, 4)
>>> t
tensor([[-0.1321, 0.4370, -1.2631, -1.1289],
[-2.0527, -1.1250, 0.2275, 0.3077],
[-0.0881, -0.1259, -0.5495, 1.0284]])
>>> torch.msort(t)
tensor([[-2.0527, -1.1250, -1.2631, -1.1289],
[-0.1321, -0.1259, -0.5495, 0.3077],
[-0.0881, 0.4370, 0.2275, 1.0284]])
mul(...)
mul(input, other, *, out=None) -> Tensor
Multiplies :attr:`input` by :attr:`other`.
.. math::
\text{out}_i = \text{input}_i \times \text{other}_i
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
Args:
input (Tensor): the input tensor.
other (Tensor or Number): the tensor or number to multiply input by.
Keyword args:
out (Tensor, optional): the output tensor.
Examples::
>>> a = torch.randn(3)
>>> a
tensor([ 0.2015, -0.4255, 2.6087])
>>> torch.mul(a, 100)
tensor([ 20.1494, -42.5491, 260.8663])
>>> b = torch.randn(4, 1)
>>> b
tensor([[ 1.1207],
[-0.3137],
[ 0.0700],
[ 0.8378]])
>>> c = torch.randn(1, 4)
>>> c
tensor([[ 0.5146, 0.1216, -0.5244, 2.2382]])
>>> torch.mul(b, c)
tensor([[ 0.5767, 0.1363, -0.5877, 2.5083],
[-0.1614, -0.0382, 0.1645, -0.7021],
[ 0.0360, 0.0085, -0.0367, 0.1567],
[ 0.4312, 0.1019, -0.4394, 1.8753]])
multinomial(...)
multinomial(input, num_samples, replacement=False, *, generator=None, out=None) -> LongTensor
Returns a tensor where each row contains :attr:`num_samples` indices sampled
from the multinomial (a stricter definition would be multivariate,
refer to :class:`torch.distributions.multinomial.Multinomial` for more details)
probability distribution located in the corresponding row
of tensor :attr:`input`.
.. note::
The rows of :attr:`input` do not need to sum to one (in which case we use
the values as weights), but must be non-negative, finite and have
a non-zero sum.
Indices are ordered from left to right according to when each was sampled
(first samples are placed in first column).
If :attr:`input` is a vector, :attr:`out` is a vector of size :attr:`num_samples`.
If :attr:`input` is a matrix with `m` rows, :attr:`out` is an matrix of shape
:math:`(m \times \text{num\_samples})`.
If replacement is ``True``, samples are drawn with replacement.
If not, they are drawn without replacement, which means that when a
sample index is drawn for a row, it cannot be drawn again for that row.
.. note::
When drawn without replacement, :attr:`num_samples` must be lower than
number of non-zero elements in :attr:`input` (or the min number of non-zero
elements in each row of :attr:`input` if it is a matrix).
Args:
input (Tensor): the input tensor containing probabilities
num_samples (int): number of samples to draw
replacement (bool, optional): whether to draw with replacement or not
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
Example::
>>> weights = torch.tensor([0, 10, 3, 0], dtype=torch.float) # create a tensor of weights
>>> torch.multinomial(weights, 2)
tensor([1, 2])
>>> torch.multinomial(weights, 5) # ERROR!
RuntimeError: cannot sample n_sample > prob_dist.size(-1) samples without replacement
>>> torch.multinomial(weights, 4, replacement=True)
tensor([ 2, 1, 1, 1])
multiply(...)
multiply(input, other, *, out=None)
Alias for :func:`torch.mul`.
mv(...)
mv(input, vec, *, out=None) -> Tensor
Performs a matrix-vector product of the matrix :attr:`input` and the vector
:attr:`vec`.
If :attr:`input` is a :math:`(n \times m)` tensor, :attr:`vec` is a 1-D tensor of
size :math:`m`, :attr:`out` will be 1-D of size :math:`n`.
.. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
Args:
input (Tensor): matrix to be multiplied
vec (Tensor): vector to be multiplied
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> mat = torch.randn(2, 3)
>>> vec = torch.randn(3)
>>> torch.mv(mat, vec)
tensor([ 1.0404, -0.6361])
mvlgamma(...)
mvlgamma(input, p, *, out=None) -> Tensor
Alias for :func:`torch.special.multigammaln`.
nan_to_num(...)
nan_to_num(input, nan=0.0, posinf=None, neginf=None, *, out=None) -> Tensor
Replaces :literal:`NaN`, positive infinity, and negative infinity values in :attr:`input`
with the values specified by :attr:`nan`, :attr:`posinf`, and :attr:`neginf`, respectively.
By default, :literal:`NaN`\ s are replaced with zero, positive infinity is replaced with the
greatest finite value representable by :attr:`input`'s dtype, and negative infinity
is replaced with the least finite value representable by :attr:`input`'s dtype.
Args:
input (Tensor): the input tensor.
nan (Number, optional): the value to replace :literal:`NaN`\s with. Default is zero.
posinf (Number, optional): if a Number, the value to replace positive infinity values with.
If None, positive infinity values are replaced with the greatest finite value representable by :attr:`input`'s dtype.
Default is None.
neginf (Number, optional): if a Number, the value to replace negative infinity values with.
If None, negative infinity values are replaced with the lowest finite value representable by :attr:`input`'s dtype.
Default is None.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.tensor([float('nan'), float('inf'), -float('inf'), 3.14])
>>> torch.nan_to_num(x)
tensor([ 0.0000e+00, 3.4028e+38, -3.4028e+38, 3.1400e+00])
>>> torch.nan_to_num(x, nan=2.0)
tensor([ 2.0000e+00, 3.4028e+38, -3.4028e+38, 3.1400e+00])
>>> torch.nan_to_num(x, nan=2.0, posinf=1.0)
tensor([ 2.0000e+00, 1.0000e+00, -3.4028e+38, 3.1400e+00])
nan_to_num_(...)
nanmean(...)
nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None) -> Tensor
Computes the mean of all `non-NaN` elements along the specified dimensions.
Input must be floating point or complex.
This function is identical to :func:`torch.mean` when there are no `NaN` values
in the :attr:`input` tensor. In the presence of `NaN`, :func:`torch.mean` will
propagate the `NaN` to the output whereas :func:`torch.nanmean` will ignore the
`NaN` values (`torch.nanmean(a)` is equivalent to `torch.mean(a[~a.isnan()])`).
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor, either of floating point or complex dtype
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
out (Tensor, optional): the output tensor.
.. seealso::
:func:`torch.mean` computes the mean value, propagating `NaN`.
Example::
>>> x = torch.tensor([[torch.nan, 1, 2], [1, 2, 3]])
>>> x.mean()
tensor(nan)
>>> x.nanmean()
tensor(1.8000)
>>> x.mean(dim=0)
tensor([ nan, 1.5000, 2.5000])
>>> x.nanmean(dim=0)
tensor([1.0000, 1.5000, 2.5000])
# If all elements in the reduced dimensions are NaN then the result is NaN
>>> torch.tensor([torch.nan]).nanmean()
tensor(nan)
nanmedian(...)
nanmedian(input) -> Tensor
Returns the median of the values in :attr:`input`, ignoring ``NaN`` values.
This function is identical to :func:`torch.median` when there are no ``NaN`` values in :attr:`input`.
When :attr:`input` has one or more ``NaN`` values, :func:`torch.median` will always return ``NaN``,
while this function will return the median of the non-``NaN`` elements in :attr:`input`.
If all the elements in :attr:`input` are ``NaN`` it will also return ``NaN``.
Args:
input (Tensor): the input tensor.
Example::
>>> a = torch.tensor([1, float('nan'), 3, 2])
>>> a.median()
tensor(nan)
>>> a.nanmedian()
tensor(2.)
.. function:: nanmedian(input, dim=-1, keepdim=False, *, out=None) -> (Tensor, LongTensor)
:noindex:
Returns a namedtuple ``(values, indices)`` where ``values`` contains the median of each row of :attr:`input`
in the dimension :attr:`dim`, ignoring ``NaN`` values, and ``indices`` contains the index of the median values
found in the dimension :attr:`dim`.
This function is identical to :func:`torch.median` when there are no ``NaN`` values in a reduced row. When a reduced row has
one or more ``NaN`` values, :func:`torch.median` will always reduce it to ``NaN``, while this function will reduce it to the
median of the non-``NaN`` elements. If all the elements in a reduced row are ``NaN`` then it will be reduced to ``NaN``, too.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
out ((Tensor, Tensor), optional): The first tensor will be populated with the median values and the second
tensor, which must have dtype long, with their indices in the dimension
:attr:`dim` of :attr:`input`.
Example::
>>> a = torch.tensor([[2, 3, 1], [float('nan'), 1, float('nan')]])
>>> a
tensor([[2., 3., 1.],
[nan, 1., nan]])
>>> a.median(0)
torch.return_types.median(values=tensor([nan, 1., nan]), indices=tensor([1, 1, 1]))
>>> a.nanmedian(0)
torch.return_types.nanmedian(values=tensor([2., 1., 1.]), indices=tensor([0, 1, 0]))
nanquantile(...)
nanquantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
This is a variant of :func:`torch.quantile` that "ignores" ``NaN`` values,
computing the quantiles :attr:`q` as if ``NaN`` values in :attr:`input` did
not exist. If all values in a reduced row are ``NaN`` then the quantiles for
that reduction will be ``NaN``. See the documentation for :func:`torch.quantile`.
Args:
input (Tensor): the input tensor.
q (float or Tensor): a scalar or 1D tensor of quantile values in the range [0, 1]
dim (int, optional): the dimension to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword arguments:
interpolation (str): interpolation method to use when the desired quantile lies between two data points.
Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
Default is ``linear``.
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.tensor([float('nan'), 1, 2])
>>> t.quantile(0.5)
tensor(nan)
>>> t.nanquantile(0.5)
tensor(1.5000)
>>> t = torch.tensor([[float('nan'), float('nan')], [1, 2]])
>>> t
tensor([[nan, nan],
[1., 2.]])
>>> t.nanquantile(0.5, dim=0)
tensor([1., 2.])
>>> t.nanquantile(0.5, dim=1)
tensor([ nan, 1.5000])
nansum(...)
nansum(input, *, dtype=None) -> Tensor
Returns the sum of all elements, treating Not a Numbers (NaNs) as zero.
Args:
input (Tensor): the input tensor.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> a = torch.tensor([1., 2., float('nan'), 4.])
>>> torch.nansum(a)
tensor(7.)
.. function:: nansum(input, dim, keepdim=False, *, dtype=None) -> Tensor
:noindex:
Returns the sum of each row of the :attr:`input` tensor in the given
dimension :attr:`dim`, treating Not a Numbers (NaNs) as zero.
If :attr:`dim` is a list of dimensions, reduce over all of them.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> torch.nansum(torch.tensor([1., float("nan")]))
tensor(1.)
>>> a = torch.tensor([[1, 2], [3., float("nan")]])
>>> torch.nansum(a)
tensor(6.)
>>> torch.nansum(a, dim=0)
tensor([4., 2.])
>>> torch.nansum(a, dim=1)
tensor([3., 3.])
narrow(...)
narrow(input, dim, start, length) -> Tensor
Returns a new tensor that is a narrowed version of :attr:`input` tensor. The
dimension :attr:`dim` is input from :attr:`start` to ``start + length``. The
returned tensor and :attr:`input` tensor share the same underlying storage.
Args:
input (Tensor): the tensor to narrow
dim (int): the dimension along which to narrow
start (int or Tensor): index of the element to start the narrowed dimension
from. Can be negative, which means indexing from the end of `dim`. If
`Tensor`, it must be an 0-dim integral `Tensor` (bools not allowed)
length (int): length of the narrowed dimension, must be weakly positive
Example::
>>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> torch.narrow(x, 0, 0, 2)
tensor([[ 1, 2, 3],
[ 4, 5, 6]])
>>> torch.narrow(x, 1, 1, 2)
tensor([[ 2, 3],
[ 5, 6],
[ 8, 9]])
>>> torch.narrow(x, -1, torch.tensor(-1), 1)
tensor([[3],
[6],
[9]])
narrow_copy(...)
narrow_copy(input, dim, start, length, *, out=None) -> Tensor
Same as :meth:`Tensor.narrow` except this returns a copy rather
than shared storage. This is primarily for sparse tensors, which
do not have a shared-storage narrow method.
Args:
input (Tensor): the tensor to narrow
dim (int): the dimension along which to narrow
start (int): index of the element to start the narrowed dimension from. Can
be negative, which means indexing from the end of `dim`
length (int): length of the narrowed dimension, must be weakly positive
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> torch.narrow_copy(x, 0, 0, 2)
tensor([[ 1, 2, 3],
[ 4, 5, 6]])
>>> torch.narrow_copy(x, 1, 1, 2)
tensor([[ 2, 3],
[ 5, 6],
[ 8, 9]])
>>> s = torch.arange(16).reshape(2, 2, 2, 2).to_sparse(2)
>>> torch.narrow_copy(s, 0, 0, 1)
tensor(indices=tensor([[0, 0],
[0, 1]]),
values=tensor([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]]),
size=(1, 2, 2, 2), nnz=2, layout=torch.sparse_coo)
.. seealso::
:func:`torch.narrow` for a non copy variant
native_batch_norm(...)
native_channel_shuffle(...)
native_channel_shuffle(input, groups) -> Tensor
Native kernel level implementation of the `channel_shuffle`.
This function might become private in future releases, use with caution.
Divide the channels in a tensor of shape :math:`(*, C , H, W)`
into g groups and rearrange them as :math:`(*, C \frac g, g, H, W)`,
while keeping the original tensor shape.
See :class:`~torch.nn.ChannelShuffle` for details.
Args:
input (Tensor): the input tensor
groups (int): number of groups to divide channels in and rearrange.
Examples::
>>> input = torch.randn(1, 4, 2, 2)
>>> print(input)
[[[[1, 2],
[3, 4]],
[[5, 6],
[7, 8]],
[[9, 10],
[11, 12]],
[[13, 14],
[15, 16]],
]]
>>> output = torch.nn.functional.native_channel_shuffle(input, 2)
>>> print(output)
[[[[1, 2],
[3, 4]],
[[9, 10],
[11, 12]],
[[5, 6],
[7, 8]],
[[13, 14],
[15, 16]],
]]
native_dropout(...)
native_group_norm(...)
native_layer_norm(...)
native_norm(...)
ne(...)
ne(input, other, *, out=None) -> Tensor
Computes :math:`\text{input} \neq \text{other}` element-wise.
The second argument can be a number or a tensor whose shape is
:ref:`broadcastable <broadcasting-semantics>` with the first argument.
Args:
input (Tensor): the tensor to compare
other (Tensor or float): the tensor or value to compare
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
A boolean tensor that is True where :attr:`input` is not equal to :attr:`other` and False elsewhere
Example::
>>> torch.ne(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[False, True], [True, False]])
neg(...)
neg(input, *, out=None) -> Tensor
Returns a new tensor with the negative of the elements of :attr:`input`.
.. math::
\text{out} = -1 \times \text{input}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(5)
>>> a
tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
>>> torch.neg(a)
tensor([-0.0090, 0.2262, 0.0682, 0.2866, -0.3940])
neg_(...)
negative(...)
negative(input, *, out=None) -> Tensor
Alias for :func:`torch.neg`
negative_(...)
nextafter(...)
nextafter(input, other, *, out=None) -> Tensor
Return the next floating-point value after :attr:`input` towards :attr:`other`, elementwise.
The shapes of ``input`` and ``other`` must be
:ref:`broadcastable <broadcasting-semantics>`.
Args:
input (Tensor): the first input tensor
other (Tensor): the second input tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> eps = torch.finfo(torch.float32).eps
>>> torch.nextafter(torch.tensor([1.0, 2.0]), torch.tensor([2.0, 1.0])) == torch.tensor([eps + 1, 2 - eps])
tensor([True, True])
nonzero(...)
nonzero(input, *, out=None, as_tuple=False) -> LongTensor or tuple of LongTensors
.. note::
:func:`torch.nonzero(..., as_tuple=False) <torch.nonzero>` (default) returns a
2-D tensor where each row is the index for a nonzero value.
:func:`torch.nonzero(..., as_tuple=True) <torch.nonzero>` returns a tuple of 1-D
index tensors, allowing for advanced indexing, so ``x[x.nonzero(as_tuple=True)]``
gives all nonzero values of tensor ``x``. Of the returned tuple, each index tensor
contains nonzero indices for a certain dimension.
See below for more details on the two behaviors.
When :attr:`input` is on CUDA, :func:`torch.nonzero() <torch.nonzero>` causes
host-device synchronization.
**When** :attr:`as_tuple` **is** ``False`` **(default)**:
Returns a tensor containing the indices of all non-zero elements of
:attr:`input`. Each row in the result contains the indices of a non-zero
element in :attr:`input`. The result is sorted lexicographically, with
the last index changing the fastest (C-style).
If :attr:`input` has :math:`n` dimensions, then the resulting indices tensor
:attr:`out` is of size :math:`(z \times n)`, where :math:`z` is the total number of
non-zero elements in the :attr:`input` tensor.
**When** :attr:`as_tuple` **is** ``True``:
Returns a tuple of 1-D tensors, one for each dimension in :attr:`input`,
each containing the indices (in that dimension) of all non-zero elements of
:attr:`input` .
If :attr:`input` has :math:`n` dimensions, then the resulting tuple contains :math:`n`
tensors of size :math:`z`, where :math:`z` is the total number of
non-zero elements in the :attr:`input` tensor.
As a special case, when :attr:`input` has zero dimensions and a nonzero scalar
value, it is treated as a one-dimensional tensor with one element.
Args:
input (Tensor): the input tensor.
Keyword args:
out (LongTensor, optional): the output tensor containing indices
Returns:
LongTensor or tuple of LongTensor: If :attr:`as_tuple` is ``False``, the output
tensor containing indices. If :attr:`as_tuple` is ``True``, one 1-D tensor for
each dimension, containing the indices of each nonzero element along that
dimension.
Example::
>>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]))
tensor([[ 0],
[ 1],
[ 2],
[ 4]])
>>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
... [0.0, 0.4, 0.0, 0.0],
... [0.0, 0.0, 1.2, 0.0],
... [0.0, 0.0, 0.0,-0.4]]))
tensor([[ 0, 0],
[ 1, 1],
[ 2, 2],
[ 3, 3]])
>>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]), as_tuple=True)
(tensor([0, 1, 2, 4]),)
>>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.0, 0.0],
... [0.0, 0.4, 0.0, 0.0],
... [0.0, 0.0, 1.2, 0.0],
... [0.0, 0.0, 0.0,-0.4]]), as_tuple=True)
(tensor([0, 1, 2, 3]), tensor([0, 1, 2, 3]))
>>> torch.nonzero(torch.tensor(5), as_tuple=True)
(tensor([0]),)
nonzero_static(...)
nonzero_static(input, *, size, fill_value=-1) -> Tensor
Returns a 2-D tensor where each row is the index for a non-zero value.
The returned Tensor has the same `torch.dtype` as `torch.nonzero()`.
Args:
input (Tensor): the input tensor.
Keyword args:
size (int): the size of non-zero elements expected to be included in the out
tensor. Pad the out tensor with `fill_value` if the `size` is larger
than total number of non-zero elements, truncate out tensor if `size`
is smaller. The size must be a non-negative integer.
fill_value (int, optional): the value to fill the output tensor with when `size` is larger
than the total number of non-zero elements. Default is `-1` to represent
invalid index.
Example::
# Example 1: Padding
>>> input_tensor = torch.tensor([[1, 0], [3, 2]])
>>> static_size = 4
>>> t = torch.nonzero_static(input_tensor, size=static_size)
tensor([[ 0, 0],
[ 1, 0],
[ 1, 1],
[ -1, -1]], dtype=torch.int64)
# Example 2: Truncating
>>> input_tensor = torch.tensor([[1, 0], [3, 2]])
>>> static_size = 2
>>> t = torch.nonzero_static(input_tensor, size=static_size)
tensor([[ 0, 0],
[ 1, 0]], dtype=torch.int64)
# Example 3: 0 size
>>> input_tensor = torch.tensor([10])
>>> static_size = 0
>>> t = torch.nonzero_static(input_tensor, size=static_size)
tensor([], size=(0, 1), dtype=torch.int64)
# Example 4: 0 rank input
>>> input_tensor = torch.tensor(10)
>>> static_size = 2
>>> t = torch.nonzero_static(input_tensor, size=static_size)
tensor([], size=(2, 0), dtype=torch.int64)
norm(input, p: float | str | None = 'fro', dim=None, keepdim=False, out=None, dtype=None)
Returns the matrix norm or vector norm of a given tensor.
.. warning::
torch.norm is deprecated and may be removed in a future PyTorch release.
Its documentation and behavior may be incorrect, and it is no longer
actively maintained.
Use :func:`torch.linalg.vector_norm` when computing vector norms and
:func:`torch.linalg.matrix_norm` when computing matrix norms.
For a function with a similar behavior as this one see :func:`torch.linalg.norm`.
Note, however, the signature for these functions is slightly different than the
signature for ``torch.norm``.
Args:
input (Tensor): The input tensor. Its data type must be either a floating
point or complex type. For complex inputs, the norm is calculated using the
absolute value of each element. If the input is complex and neither
:attr:`dtype` nor :attr:`out` is specified, the result's data type will
be the corresponding floating point type (e.g. float if :attr:`input` is
complexfloat).
p (int, float, inf, -inf, 'fro', 'nuc', optional): the order of norm. Default: ``'fro'``
The following norms can be calculated:
====== ============== ==========================
ord matrix norm vector norm
====== ============== ==========================
'fro' Frobenius norm --
'nuc' nuclear norm --
Number -- sum(abs(x)**ord)**(1./ord)
====== ============== ==========================
The vector norm can be calculated across any number of dimensions.
The corresponding dimensions of :attr:`input` are flattened into
one dimension, and the norm is calculated on the flattened
dimension.
Frobenius norm produces the same result as ``p=2`` in all cases
except when :attr:`dim` is a list of three or more dims, in which
case Frobenius norm throws an error.
Nuclear norm can only be calculated across exactly two dimensions.
dim (int, tuple of ints, list of ints, optional):
Specifies which dimension or dimensions of :attr:`input` to
calculate the norm across. If :attr:`dim` is ``None``, the norm will
be calculated across all dimensions of :attr:`input`. If the norm
type indicated by :attr:`p` does not support the specified number of
dimensions, an error will occur.
keepdim (bool, optional): whether the output tensors have :attr:`dim`
retained or not. Ignored if :attr:`dim` = ``None`` and
:attr:`out` = ``None``. Default: ``False``
out (Tensor, optional): the output tensor. Ignored if
:attr:`dim` = ``None`` and :attr:`out` = ``None``.
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. If specified, the input tensor is casted to
:attr:`dtype` while performing the operation. Default: None.
.. note::
Even though ``p='fro'`` supports any number of dimensions, the true
mathematical definition of Frobenius norm only applies to tensors with
exactly two dimensions. :func:`torch.linalg.matrix_norm` with ``ord='fro'``
aligns with the mathematical definition, since it can only be applied across
exactly two dimensions.
Example::
>>> import torch
>>> a = torch.arange(9, dtype= torch.float) - 4
>>> b = a.reshape((3, 3))
>>> torch.norm(a)
tensor(7.7460)
>>> torch.norm(b)
tensor(7.7460)
>>> torch.norm(a, float('inf'))
tensor(4.)
>>> torch.norm(b, float('inf'))
tensor(4.)
>>> c = torch.tensor([[ 1, 2, 3], [-1, 1, 4]] , dtype=torch.float)
>>> torch.norm(c, dim=0)
tensor([1.4142, 2.2361, 5.0000])
>>> torch.norm(c, dim=1)
tensor([3.7417, 4.2426])
>>> torch.norm(c, p=1, dim=1)
tensor([6., 6.])
>>> d = torch.arange(8, dtype=torch.float).reshape(2, 2, 2)
>>> torch.norm(d, dim=(1, 2))
tensor([ 3.7417, 11.2250])
>>> torch.norm(d[0, :, :]), torch.norm(d[1, :, :])
(tensor(3.7417), tensor(11.2250))
norm_except_dim(...)
normal(...)
normal(mean, std, *, generator=None, out=None) -> Tensor
Returns a tensor of random numbers drawn from separate normal distributions
whose mean and standard deviation are given.
The :attr:`mean` is a tensor with the mean of
each output element's normal distribution
The :attr:`std` is a tensor with the standard deviation of
each output element's normal distribution
The shapes of :attr:`mean` and :attr:`std` don't need to match, but the
total number of elements in each tensor need to be the same.
.. note:: When the shapes do not match, the shape of :attr:`mean`
is used as the shape for the returned output tensor
.. note:: When :attr:`std` is a CUDA tensor, this function synchronizes
its device with the CPU.
Args:
mean (float or Tensor): per-element mean(s). Only floating point types are supported.
std (float or Tensor): per-element standard deviation(s). Only floating point types are supported.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
Example::
>>> torch.normal(mean=torch.arange(1., 11.), std=torch.arange(1, 0, -0.1))
tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134,
8.0505, 8.1408, 9.0563, 10.0566])
.. function:: normal(mean=0.0, std, *, out=None) -> Tensor
:noindex:
Similar to the function above, but the means are shared among all drawn
elements.
Args:
mean (float, optional): the mean for all distributions
std (Tensor): the tensor of per-element standard deviations
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.normal(mean=0.5, std=torch.arange(1., 6.))
tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303])
.. function:: normal(mean, std=1.0, *, out=None) -> Tensor
:noindex:
Similar to the function above, but the standard deviations are shared among
all drawn elements.
Args:
mean (Tensor): the tensor of per-element means
std (float, optional): the standard deviation for all distributions
Keyword args:
out (Tensor, optional): the output tensor
Example::
>>> torch.normal(mean=torch.arange(1., 6.))
tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361])
.. function:: normal(mean, std, size, *, out=None) -> Tensor
:noindex:
Similar to the function above, but the means and standard deviations are shared
among all drawn elements. The resulting tensor has size given by :attr:`size`.
Args:
mean (float): the mean for all distributions
std (float): the standard deviation for all distributions
size (int...): a sequence of integers defining the shape of the output tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.normal(2, 3, size=(1, 4))
tensor([[-1.3987, -1.9544, 3.6048, 0.7909]])
not_equal(...)
not_equal(input, other, *, out=None) -> Tensor
Alias for :func:`torch.ne`.
nuclear_norm(...)
numel(...)
numel(input: Tensor) -> int
Returns the total number of elements in the :attr:`input` tensor.
Args:
input (Tensor): the input tensor.
Example::
>>> a = torch.randn(1, 2, 3, 4, 5)
>>> torch.numel(a)
120
>>> a = torch.zeros(4,4)
>>> torch.numel(a)
16
ones(...)
ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a tensor filled with the scalar value `1`, with the shape defined
by the variable argument :attr:`size`.
Args:
size (int...): a sequence of integers defining the shape of the output tensor.
Can be a variable number of arguments or a collection like a list or tuple.
Keyword arguments:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.ones(2, 3)
tensor([[ 1., 1., 1.],
[ 1., 1., 1.]])
>>> torch.ones(5)
tensor([ 1., 1., 1., 1., 1.])
ones_like(...)
ones_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns a tensor filled with the scalar value `1`, with the same size as
:attr:`input`. ``torch.ones_like(input)`` is equivalent to
``torch.ones(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
.. warning::
As of 0.4, this function does not support an :attr:`out` keyword. As an alternative,
the old ``torch.ones_like(input, out=output)`` is equivalent to
``torch.ones(input.size(), out=output)``.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
Keyword arguments:
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
Example::
>>> input = torch.empty(2, 3)
>>> torch.ones_like(input)
tensor([[ 1., 1., 1.],
[ 1., 1., 1.]])
orgqr(...)
orgqr(input, tau) -> Tensor
Alias for :func:`torch.linalg.householder_product`.
ormqr(...)
ormqr(input, tau, other, left=True, transpose=False, *, out=None) -> Tensor
Computes the matrix-matrix multiplication of a product of Householder matrices with a general matrix.
Multiplies a :math:`m \times n` matrix `C` (given by :attr:`other`) with a matrix `Q`,
where `Q` is represented using Householder reflectors `(input, tau)`.
See `Representation of Orthogonal or Unitary Matrices`_ for further details.
If :attr:`left` is `True` then `op(Q)` times `C` is computed, otherwise the result is `C` times `op(Q)`.
When :attr:`left` is `True`, the implicit matrix `Q` has size :math:`m \times m`.
It has size :math:`n \times n` otherwise.
If :attr:`transpose` is `True` then `op` is the conjugate transpose operation, otherwise it's a no-op.
Supports inputs of float, double, cfloat and cdouble dtypes.
Also supports batched inputs, and, if the input is batched, the output is batched with the same dimensions.
.. seealso::
:func:`torch.geqrf` can be used to form the Householder representation `(input, tau)` of matrix `Q`
from the QR decomposition.
.. note::
This function supports backward but it is only fast when ``(input, tau)`` do not require gradients
and/or ``tau.size(-1)`` is very small.
``
Args:
input (Tensor): tensor of shape `(*, mn, k)` where `*` is zero or more batch dimensions
and `mn` equals to `m` or `n` depending on the :attr:`left`.
tau (Tensor): tensor of shape `(*, min(mn, k))` where `*` is zero or more batch dimensions.
other (Tensor): tensor of shape `(*, m, n)` where `*` is zero or more batch dimensions.
left (bool): controls the order of multiplication.
transpose (bool): controls whether the matrix `Q` is conjugate transposed or not.
Keyword args:
out (Tensor, optional): the output Tensor. Ignored if `None`. Default: `None`.
.. _Representation of Orthogonal or Unitary Matrices:
https://www.netlib.org/lapack/lug/node128.html
outer(...)
outer(input, vec2, *, out=None) -> Tensor
Outer product of :attr:`input` and :attr:`vec2`.
If :attr:`input` is a vector of size :math:`n` and :attr:`vec2` is a vector of
size :math:`m`, then :attr:`out` must be a matrix of size :math:`(n \times m)`.
.. note:: This function does not :ref:`broadcast <broadcasting-semantics>`.
Args:
input (Tensor): 1-D input vector
vec2 (Tensor): 1-D input vector
Keyword args:
out (Tensor, optional): optional output matrix
Example::
>>> v1 = torch.arange(1., 5.)
>>> v2 = torch.arange(1., 4.)
>>> torch.outer(v1, v2)
tensor([[ 1., 2., 3.],
[ 2., 4., 6.],
[ 3., 6., 9.],
[ 4., 8., 12.]])
pairwise_distance(...)
pairwise_distance(x1, x2, p=2.0, eps=1e-6, keepdim=False) -> Tensor
See :class:`torch.nn.PairwiseDistance` for details
parse_ir(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
parse_ir(input: str, parse_tensor_constants: bool = False) -> torch::jit::Graph
parse_schema(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
parse_schema(schema: str, allow_typevars: bool = True) -> c10::FunctionSchema
parse_type_comment(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
parse_type_comment(arg0: str) -> torch._C._jit_tree_views.Decl
pdist(...)
pdist(input, p=2) -> Tensor
Computes the p-norm distance between every pair of row vectors in the input.
This is identical to the upper triangular portion, excluding the diagonal, of
`torch.norm(input[:, None] - input, dim=2, p=p)`. This function will be faster
if the rows are contiguous.
If input has shape :math:`N \times M` then the output will have shape
:math:`\frac{1}{2} N (N - 1)`.
This function is equivalent to ``scipy.spatial.distance.pdist(input,
'minkowski', p=p)`` if :math:`p \in (0, \infty)`. When :math:`p = 0` it is
equivalent to ``scipy.spatial.distance.pdist(input, 'hamming') * M``.
When :math:`p = \infty`, the closest scipy function is
``scipy.spatial.distance.pdist(xn, lambda x, y: np.abs(x - y).max())``.
Args:
input: input tensor of shape :math:`N \times M`.
p: p value for the p-norm distance to calculate between each vector pair
:math:`\in [0, \infty]`.
permute(...)
permute(input, dims) -> Tensor
Returns a view of the original tensor :attr:`input` with its dimensions permuted.
Args:
input (Tensor): the input tensor.
dims (torch.Size, tuple of int or list of int): the desired ordering of dimensions.
Example:
>>> x = torch.randn(2, 3, 5)
>>> x.size()
torch.Size([2, 3, 5])
>>> torch.permute(x, (2, 0, 1)).size()
torch.Size([5, 2, 3])
permute_copy(...)
Performs the same operation as :func:`torch.permute`, but all output tensors
are freshly created instead of aliasing the input.
pinverse(...)
pinverse(input, rcond=1e-15) -> Tensor
Alias for :func:`torch.linalg.pinv`
pixel_shuffle(...)
pixel_shuffle(input, upscale_factor) -> Tensor
Rearranges elements in a tensor of shape :math:`(*, C \times r^2, H, W)` to a
tensor of shape :math:`(*, C, H \times r, W \times r)`, where r is the :attr:`upscale_factor`.
See :class:`~torch.nn.PixelShuffle` for details.
Args:
input (Tensor): the input tensor
upscale_factor (int): factor to increase spatial resolution by
Examples::
>>> input = torch.randn(1, 9, 4, 4)
>>> output = torch.nn.functional.pixel_shuffle(input, 3)
>>> print(output.size())
torch.Size([1, 1, 12, 12])
pixel_unshuffle(...)
pixel_unshuffle(input, downscale_factor) -> Tensor
Reverses the :class:`~torch.nn.PixelShuffle` operation by rearranging elements in a
tensor of shape :math:`(*, C, H \times r, W \times r)` to a tensor of shape
:math:`(*, C \times r^2, H, W)`, where r is the :attr:`downscale_factor`.
See :class:`~torch.nn.PixelUnshuffle` for details.
Args:
input (Tensor): the input tensor
downscale_factor (int): factor to increase spatial resolution by
Examples::
>>> input = torch.randn(1, 1, 12, 12)
>>> output = torch.nn.functional.pixel_unshuffle(input, 3)
>>> print(output.size())
torch.Size([1, 9, 4, 4])
poisson(...)
poisson(input, generator=None) -> Tensor
Returns a tensor of the same size as :attr:`input` with each element
sampled from a Poisson distribution with rate parameter given by the corresponding
element in :attr:`input` i.e.,
.. math::
\text{out}_i \sim \text{Poisson}(\text{input}_i)
:attr:`input` must be non-negative.
Args:
input (Tensor): the input tensor containing the rates of the Poisson distribution
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
Example::
>>> rates = torch.rand(4, 4) * 5 # rate parameter between 0 and 5
>>> torch.poisson(rates)
tensor([[9., 1., 3., 5.],
[8., 6., 6., 0.],
[0., 4., 5., 3.],
[2., 1., 4., 2.]])
poisson_nll_loss(...)
polar(...)
polar(abs, angle, *, out=None) -> Tensor
Constructs a complex tensor whose elements are Cartesian coordinates
corresponding to the polar coordinates with absolute value :attr:`abs` and angle
:attr:`angle`.
.. math::
\text{out} = \text{abs} \cdot \cos(\text{angle}) + \text{abs} \cdot \sin(\text{angle}) \cdot j
.. note::
`torch.polar` is similar to
`std::polar <https://en.cppreference.com/w/cpp/numeric/complex/polar>`_
and does not compute the polar decomposition
of a complex tensor like Python's `cmath.polar` and SciPy's `linalg.polar` do.
The behavior of this function is undefined if `abs` is negative or NaN, or if `angle` is
infinite.
Args:
abs (Tensor): The absolute value the complex tensor. Must be float or double.
angle (Tensor): The angle of the complex tensor. Must be same dtype as
:attr:`abs`.
Keyword args:
out (Tensor): If the inputs are ``torch.float32``, must be
``torch.complex64``. If the inputs are ``torch.float64``, must be
``torch.complex128``.
Example::
>>> import numpy as np
>>> abs = torch.tensor([1, 2], dtype=torch.float64)
>>> angle = torch.tensor([np.pi / 2, 5 * np.pi / 4], dtype=torch.float64)
>>> z = torch.polar(abs, angle)
>>> z
tensor([(0.0000+1.0000j), (-1.4142-1.4142j)], dtype=torch.complex128)
polygamma(...)
polygamma(n, input, *, out=None) -> Tensor
Alias for :func:`torch.special.polygamma`.
positive(...)
positive(input) -> Tensor
Returns :attr:`input`.
Throws a runtime error if :attr:`input` is a bool tensor.
Args:
input (Tensor): the input tensor.
Example::
>>> t = torch.randn(5)
>>> t
tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
>>> torch.positive(t)
tensor([ 0.0090, -0.2262, -0.0682, -0.2866, 0.3940])
pow(...)
pow(input, exponent, *, out=None) -> Tensor
Takes the power of each element in :attr:`input` with :attr:`exponent` and
returns a tensor with the result.
:attr:`exponent` can be either a single ``float`` number or a `Tensor`
with the same number of elements as :attr:`input`.
When :attr:`exponent` is a scalar value, the operation applied is:
.. math::
\text{out}_i = x_i ^ \text{exponent}
When :attr:`exponent` is a tensor, the operation applied is:
.. math::
\text{out}_i = x_i ^ {\text{exponent}_i}
When :attr:`exponent` is a tensor, the shapes of :attr:`input`
and :attr:`exponent` must be :ref:`broadcastable <broadcasting-semantics>`.
Args:
input (Tensor): the input tensor.
exponent (float or tensor): the exponent value
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.4331, 1.2475, 0.6834, -0.2791])
>>> torch.pow(a, 2)
tensor([ 0.1875, 1.5561, 0.4670, 0.0779])
>>> exp = torch.arange(1., 5.)
>>> a = torch.arange(1., 5.)
>>> a
tensor([ 1., 2., 3., 4.])
>>> exp
tensor([ 1., 2., 3., 4.])
>>> torch.pow(a, exp)
tensor([ 1., 4., 27., 256.])
.. function:: pow(self, exponent, *, out=None) -> Tensor
:noindex:
:attr:`self` is a scalar ``float`` value, and :attr:`exponent` is a tensor.
The returned tensor :attr:`out` is of the same shape as :attr:`exponent`
The operation applied is:
.. math::
\text{out}_i = \text{self} ^ {\text{exponent}_i}
Args:
self (float): the scalar base value for the power operation
exponent (Tensor): the exponent tensor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> exp = torch.arange(1., 5.)
>>> base = 2
>>> torch.pow(base, exp)
tensor([ 2., 4., 8., 16.])
prelu(...)
prelu(input, weight) -> Tensor
Applies element-wise the function
:math:`\text{PReLU}(x) = \max(0,x) + \text{weight} * \min(0,x)` where weight is a
learnable parameter.
.. note::
`weight` is expected to be a scalar or 1-D tensor. If `weight` is 1-D,
its size must match the number of input channels, determined by
`input.size(1)` when `input.dim() >= 2`, otherwise 1.
In the 1-D case, note that when `input` has dim > 2, `weight` can be expanded
to the shape of `input` in a way that is not possible using normal
:ref:`broadcasting semantics<broadcasting-semantics>`.
See :class:`~torch.nn.PReLU` for more details.
prod(...)
prod(input: Tensor, *, dtype: Optional[_dtype]) -> Tensor
Returns the product of all elements in the :attr:`input` tensor.
Args:
input (Tensor): the input tensor.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[-0.8020, 0.5428, -1.5854]])
>>> torch.prod(a)
tensor(0.6902)
.. function:: prod(input, dim, keepdim=False, *, dtype=None) -> Tensor
:noindex:
Returns the product of each row of the :attr:`input` tensor in the given
dimension :attr:`dim`.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in
the output tensor having 1 fewer dimension than :attr:`input`.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> a = torch.randn(4, 2)
>>> a
tensor([[ 0.5261, -0.3837],
[ 1.1857, -0.2498],
[-1.1646, 0.0705],
[ 1.1131, -1.0629]])
>>> torch.prod(a, 1)
tensor([-0.2018, -0.2962, -0.0821, -1.1831])
promote_types(...)
promote_types(type1, type2) -> dtype
Returns the :class:`torch.dtype` with the smallest size and scalar kind that is
not smaller nor of lower kind than either `type1` or `type2`. See type promotion
:ref:`documentation <type-promotion-doc>` for more information on the type
promotion logic.
Args:
type1 (:class:`torch.dtype`)
type2 (:class:`torch.dtype`)
Example::
>>> torch.promote_types(torch.int32, torch.float32)
torch.float32
>>> torch.promote_types(torch.uint8, torch.long)
torch.long
put(...)
q_per_channel_axis(...)
q_per_channel_scales(...)
q_per_channel_zero_points(...)
q_scale(...)
q_zero_point(...)
qr(...)
qr(input: Tensor, some: bool = True, *, out: Union[Tensor, Tuple[Tensor, ...], List[Tensor], None]) -> (Tensor, Tensor)
Computes the QR decomposition of a matrix or a batch of matrices :attr:`input`,
and returns a namedtuple (Q, R) of tensors such that :math:`\text{input} = Q R`
with :math:`Q` being an orthogonal matrix or batch of orthogonal matrices and
:math:`R` being an upper triangular matrix or batch of upper triangular matrices.
If :attr:`some` is ``True``, then this function returns the thin (reduced) QR factorization.
Otherwise, if :attr:`some` is ``False``, this function returns the complete QR factorization.
.. warning::
:func:`torch.qr` is deprecated in favor of :func:`torch.linalg.qr`
and will be removed in a future PyTorch release. The boolean parameter :attr:`some` has been
replaced with a string parameter :attr:`mode`.
``Q, R = torch.qr(A)`` should be replaced with
.. code:: python
Q, R = torch.linalg.qr(A)
``Q, R = torch.qr(A, some=False)`` should be replaced with
.. code:: python
Q, R = torch.linalg.qr(A, mode="complete")
.. warning::
If you plan to backpropagate through QR, note that the current backward implementation
is only well-defined when the first :math:`\min(input.size(-1), input.size(-2))`
columns of :attr:`input` are linearly independent.
This behavior will probably change once QR supports pivoting.
.. note:: This function uses LAPACK for CPU inputs and MAGMA for CUDA inputs,
and may produce different (valid) decompositions on different device types
or different platforms.
Args:
input (Tensor): the input tensor of size :math:`(*, m, n)` where `*` is zero or more
batch dimensions consisting of matrices of dimension :math:`m \times n`.
some (bool, optional): Set to ``True`` for reduced QR decomposition and ``False`` for
complete QR decomposition. If `k = min(m, n)` then:
* ``some=True`` : returns `(Q, R)` with dimensions (m, k), (k, n) (default)
* ``'some=False'``: returns `(Q, R)` with dimensions (m, m), (m, n)
Keyword args:
out (tuple, optional): tuple of `Q` and `R` tensors.
The dimensions of `Q` and `R` are detailed in the description of :attr:`some` above.
Example::
>>> a = torch.tensor([[12., -51, 4], [6, 167, -68], [-4, 24, -41]])
>>> q, r = torch.qr(a)
>>> q
tensor([[-0.8571, 0.3943, 0.3314],
[-0.4286, -0.9029, -0.0343],
[ 0.2857, -0.1714, 0.9429]])
>>> r
tensor([[ -14.0000, -21.0000, 14.0000],
[ 0.0000, -175.0000, 70.0000],
[ 0.0000, 0.0000, -35.0000]])
>>> torch.mm(q, r).round()
tensor([[ 12., -51., 4.],
[ 6., 167., -68.],
[ -4., 24., -41.]])
>>> torch.mm(q.t(), q).round()
tensor([[ 1., 0., 0.],
[ 0., 1., -0.],
[ 0., -0., 1.]])
>>> a = torch.randn(3, 4, 5)
>>> q, r = torch.qr(a, some=False)
>>> torch.allclose(torch.matmul(q, r), a)
True
>>> torch.allclose(torch.matmul(q.mT, q), torch.eye(5))
True
quantile(...)
quantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
Computes the q-th quantiles of each row of the :attr:`input` tensor along the dimension :attr:`dim`.
To compute the quantile, we map q in [0, 1] to the range of indices [0, n] to find the location
of the quantile in the sorted input. If the quantile lies between two data points ``a < b`` with
indices ``i`` and ``j`` in the sorted order, result is computed according to the given
:attr:`interpolation` method as follows:
- ``linear``: ``a + (b - a) * fraction``, where ``fraction`` is the fractional part of the computed quantile index.
- ``lower``: ``a``.
- ``higher``: ``b``.
- ``nearest``: ``a`` or ``b``, whichever's index is closer to the computed quantile index (follows :func:`torch.round`).
- ``midpoint``: ``(a + b) / 2``.
If :attr:`q` is a 1D tensor, the first dimension of the output represents the quantiles and has size
equal to the size of :attr:`q`, the remaining dimensions are what remains from the reduction.
.. note::
By default :attr:`dim` is ``None`` resulting in the :attr:`input` tensor being flattened before computation.
Args:
input (Tensor): the input tensor.
q (float or Tensor): a scalar or 1D tensor of values in the range [0, 1].
dim (int, optional): the dimension to reduce.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword arguments:
interpolation (str, optional): interpolation method to use when the desired quantile lies between two data points.
Can be ``linear``, ``lower``, ``higher``, ``midpoint`` and ``nearest``.
Default is ``linear``.
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(2, 3)
>>> a
tensor([[ 0.0795, -1.2117, 0.9765],
[ 1.1707, 0.6706, 0.4884]])
>>> q = torch.tensor([0.25, 0.5, 0.75])
>>> torch.quantile(a, q, dim=1, keepdim=True)
tensor([[[-0.5661],
[ 0.5795]],
[[ 0.0795],
[ 0.6706]],
[[ 0.5280],
[ 0.9206]]])
>>> torch.quantile(a, q, dim=1, keepdim=True).shape
torch.Size([3, 2, 1])
>>> a = torch.arange(4.)
>>> a
tensor([0., 1., 2., 3.])
>>> torch.quantile(a, 0.6, interpolation='linear')
tensor(1.8000)
>>> torch.quantile(a, 0.6, interpolation='lower')
tensor(1.)
>>> torch.quantile(a, 0.6, interpolation='higher')
tensor(2.)
>>> torch.quantile(a, 0.6, interpolation='midpoint')
tensor(1.5000)
>>> torch.quantile(a, 0.6, interpolation='nearest')
tensor(2.)
>>> torch.quantile(a, 0.4, interpolation='nearest')
tensor(1.)
quantize_per_channel(...)
quantize_per_channel(input, scales, zero_points, axis, dtype) -> Tensor
Converts a float tensor to a per-channel quantized tensor with given scales and zero points.
Arguments:
input (Tensor): float tensor to quantize
scales (Tensor): float 1D tensor of scales to use, size should match ``input.size(axis)``
zero_points (int): integer 1D tensor of offset to use, size should match ``input.size(axis)``
axis (int): dimension on which apply per-channel quantization
dtype (:class:`torch.dtype`): the desired data type of returned tensor.
Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
Returns:
Tensor: A newly quantized tensor
Example::
>>> x = torch.tensor([[-1.0, 0.0], [1.0, 2.0]])
>>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8)
tensor([[-1., 0.],
[ 1., 2.]], size=(2, 2), dtype=torch.quint8,
quantization_scheme=torch.per_channel_affine,
scale=tensor([0.1000, 0.0100], dtype=torch.float64),
zero_point=tensor([10, 0]), axis=0)
>>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8).int_repr()
tensor([[ 0, 10],
[100, 200]], dtype=torch.uint8)
quantize_per_tensor(...)
quantize_per_tensor(input, scale, zero_point, dtype) -> Tensor
Converts a float tensor to a quantized tensor with given scale and zero point.
Arguments:
input (Tensor): float tensor or list of tensors to quantize
scale (float or Tensor): scale to apply in quantization formula
zero_point (int or Tensor): offset in integer value that maps to float zero
dtype (:class:`torch.dtype`): the desired data type of returned tensor.
Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``, ``torch.qint32``
Returns:
Tensor: A newly quantized tensor or list of quantized tensors.
Example::
>>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8)
tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10)
>>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr()
tensor([ 0, 10, 20, 30], dtype=torch.uint8)
>>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])],
>>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8)
(tensor([-1., 0.], size=(2,), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10),
tensor([-2., 2.], size=(2,), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20))
>>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8)
tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)
quantize_per_tensor_dynamic(...)
quantize_per_tensor_dynamic(input, dtype, reduce_range) -> Tensor
Converts a float tensor to a quantized tensor with scale and zero_point calculated
dynamically based on the input.
Arguments:
input (Tensor): float tensor or list of tensors to quantize
dtype (:class:`torch.dtype`): the desired data type of returned tensor.
Has to be one of the quantized dtypes: ``torch.quint8``, ``torch.qint8``
reduce_range (bool): a flag to indicate whether to reduce the range of quantized
data by 1 bit, it's required to avoid instruction overflow for some hardwares
Returns:
Tensor: A newly (dynamically) quantized tensor
Example::
>>> t = torch.quantize_per_tensor_dynamic(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.quint8, False)
>>> print(t)
tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.011764705882352941,
zero_point=85)
>>> t.int_repr()
tensor([ 0, 85, 170, 255], dtype=torch.uint8)
quantized_batch_norm(...)
quantized_batch_norm(input, weight=None, bias=None, mean, var, eps, output_scale, output_zero_point) -> Tensor
Applies batch normalization on a 4D (NCHW) quantized tensor.
.. math::
y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
Arguments:
input (Tensor): quantized tensor
weight (Tensor): float tensor that corresponds to the gamma, size C
bias (Tensor): float tensor that corresponds to the beta, size C
mean (Tensor): float mean value in batch normalization, size C
var (Tensor): float tensor for variance, size C
eps (float): a value added to the denominator for numerical stability.
output_scale (float): output quantized tensor scale
output_zero_point (int): output quantized tensor zero_point
Returns:
Tensor: A quantized tensor with batch normalization applied.
Example::
>>> qx = torch.quantize_per_tensor(torch.rand(2, 2, 2, 2), 1.5, 3, torch.quint8)
>>> torch.quantized_batch_norm(qx, torch.ones(2), torch.zeros(2), torch.rand(2), torch.rand(2), 0.00001, 0.2, 2)
tensor([[[[-0.2000, -0.2000],
[ 1.6000, -0.2000]],
[[-0.4000, -0.4000],
[-0.4000, 0.6000]]],
[[[-0.2000, -0.2000],
[-0.2000, -0.2000]],
[[ 0.6000, -0.4000],
[ 0.6000, -0.4000]]]], size=(2, 2, 2, 2), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=2)
quantized_gru_cell(...)
quantized_lstm_cell(...)
quantized_max_pool1d(...)
quantized_max_pool1d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) -> Tensor
Applies a 1D max pooling over an input quantized tensor composed of several input planes.
Arguments:
input (Tensor): quantized tensor
kernel_size (list of int): the size of the sliding window
stride (``list of int``, optional): the stride of the sliding window
padding (``list of int``, optional): padding to be added on both sides, must be >= 0 and <= kernel_size / 2
dilation (``list of int``, optional): The stride between elements within a sliding window, must be > 0. Default 1
ceil_mode (bool, optional): If True, will use ceil instead of floor to compute the output shape.
Defaults to False.
Returns:
Tensor: A quantized tensor with max_pool1d applied.
Example::
>>> qx = torch.quantize_per_tensor(torch.rand(2, 2), 1.5, 3, torch.quint8)
>>> torch.quantized_max_pool1d(qx, [2])
tensor([[0.0000],
[1.5000]], size=(2, 1), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=1.5, zero_point=3)
quantized_max_pool2d(...)
quantized_max_pool2d(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False) -> Tensor
Applies a 2D max pooling over an input quantized tensor composed of several input planes.
Arguments:
input (Tensor): quantized tensor
kernel_size (``list of int``): the size of the sliding window
stride (``list of int``, optional): the stride of the sliding window
padding (``list of int``, optional): padding to be added on both sides, must be >= 0 and <= kernel_size / 2
dilation (``list of int``, optional): The stride between elements within a sliding window, must be > 0. Default 1
ceil_mode (bool, optional): If True, will use ceil instead of floor to compute the output shape.
Defaults to False.
Returns:
Tensor: A quantized tensor with max_pool2d applied.
Example::
>>> qx = torch.quantize_per_tensor(torch.rand(2, 2, 2, 2), 1.5, 3, torch.quint8)
>>> torch.quantized_max_pool2d(qx, [2,2])
tensor([[[[1.5000]],
[[1.5000]]],
[[[0.0000]],
[[0.0000]]]], size=(2, 2, 1, 1), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=1.5, zero_point=3)
quantized_max_pool3d(...)
quantized_rnn_relu_cell(...)
quantized_rnn_tanh_cell(...)
rad2deg(...)
rad2deg(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with each of the elements of :attr:`input`
converted from angles in radians to degrees.
Args:
input (Tensor): the input tensor.
Keyword arguments:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([[3.142, -3.142], [6.283, -6.283], [1.570, -1.570]])
>>> torch.rad2deg(a)
tensor([[ 180.0233, -180.0233],
[ 359.9894, -359.9894],
[ 89.9544, -89.9544]])
rad2deg_(...)
rand(...)
rand(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
Returns a tensor filled with random numbers from a uniform distribution
on the interval :math:`[0, 1)`
The shape of the tensor is defined by the variable argument :attr:`size`.
Args:
size (int...): a sequence of integers defining the shape of the output tensor.
Can be a variable number of arguments or a collection like a list or tuple.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> torch.rand(4)
tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
>>> torch.rand(2, 3)
tensor([[ 0.8237, 0.5781, 0.6879],
[ 0.3816, 0.7249, 0.0998]])
rand_like(...)
rand_like(input, *, generator=None, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns a tensor with the same size as :attr:`input` that is filled with
random numbers from a uniform distribution on the interval :math:`[0, 1)`.
``torch.rand_like(input)`` is equivalent to
``torch.rand(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
randint(...)
randint(low=0, high, size, \*, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a tensor filled with random integers generated uniformly
between :attr:`low` (inclusive) and :attr:`high` (exclusive).
The shape of the tensor is defined by the variable argument :attr:`size`.
.. note::
With the global dtype default (``torch.float32``), this function returns
a tensor with dtype ``torch.int64``.
Args:
low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
high (int): One above the highest integer to be drawn from the distribution.
size (tuple): a tuple defining the shape of the output tensor.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
dtype (torch.dtype, optional): the desired data type of returned tensor. Default: if ``None``,
this function returns a tensor with dtype ``torch.int64``.
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.randint(3, 5, (3,))
tensor([4, 3, 4])
>>> torch.randint(10, (2, 2))
tensor([[0, 2],
[5, 5]])
>>> torch.randint(3, 10, (2, 2))
tensor([[4, 5],
[6, 7]])
randint_like(...)
randint_like(input, low=0, high, \*, generator=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns a tensor with the same shape as Tensor :attr:`input` filled with
random integers generated uniformly between :attr:`low` (inclusive) and
:attr:`high` (exclusive).
.. note:
With the global dtype default (``torch.float32``), this function returns
a tensor with dtype ``torch.int64``.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
low (int, optional): Lowest integer to be drawn from the distribution. Default: 0.
high (int): One above the highest integer to be drawn from the distribution.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
randn(...)
randn(*size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
Returns a tensor filled with random numbers from a normal distribution
with mean `0` and variance `1` (also called the standard normal
distribution).
.. math::
\text{out}_{i} \sim \mathcal{N}(0, 1)
For complex dtypes, the tensor is i.i.d. sampled from a `complex normal distribution`_ with zero mean and
unit variance as
.. math::
\text{out}_{i} \sim \mathcal{CN}(0, 1)
This is equivalent to separately sampling the real :math:`(\operatorname{Re})` and imaginary
:math:`(\operatorname{Im})` part of :math:`\text{out}_i` as
.. math::
\operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad
\operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})
The shape of the tensor is defined by the variable argument :attr:`size`.
Args:
size (int...): a sequence of integers defining the shape of the output tensor.
Can be a variable number of arguments or a collection like a list or tuple.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> torch.randn(4)
tensor([-2.1436, 0.9966, 2.3426, -0.6366])
>>> torch.randn(2, 3)
tensor([[ 1.5954, 2.8929, -1.0923],
[ 1.1719, -0.4709, -0.1996]])
.. _complex normal distribution: https://en.wikipedia.org/wiki/Complex_normal_distribution
randn_like(...)
randn_like(input, *, generator=None, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns a tensor with the same size as :attr:`input` that is filled with
random numbers from a normal distribution with mean 0 and variance 1. Please refer to :func:`torch.randn` for the
sampling process of complex dtypes. ``torch.randn_like(input)`` is equivalent to
``torch.randn(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling.
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
randperm(...)
randperm(n, *, generator=None, out=None, dtype=torch.int64,layout=torch.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor
Returns a random permutation of integers from ``0`` to ``n - 1``.
Args:
n (int): the upper bound (exclusive)
Keyword args:
generator (:class:`torch.Generator`, optional): a pseudorandom number generator for sampling
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: ``torch.int64``.
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> torch.randperm(4)
tensor([2, 1, 0, 3])
range(...)
range(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a 1-D tensor of size :math:`\left\lfloor \frac{\text{end} - \text{start}}{\text{step}} \right\rfloor + 1`
with values from :attr:`start` to :attr:`end` with step :attr:`step`. Step is
the gap between two values in the tensor.
.. math::
\text{out}_{i+1} = \text{out}_i + \text{step}.
.. warning::
This function is deprecated and will be removed in a future release because its behavior is inconsistent with
Python's range builtin. Instead, use :func:`torch.arange`, which produces values in [start, end).
Args:
start (float, optional): the starting value for the set of points. Default: ``0``.
end (float): the ending value for the set of points
step (float, optional): the gap between each pair of adjacent points. Default: ``1``.
Keyword args:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`). If `dtype` is not given, infer the data type from the other input
arguments. If any of `start`, `end`, or `step` are floating-point, the
`dtype` is inferred to be the default dtype, see
:meth:`~torch.get_default_dtype`. Otherwise, the `dtype` is inferred to
be `torch.int64`.
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.range(1, 4)
tensor([ 1., 2., 3., 4.])
>>> torch.range(1, 4, 0.5)
tensor([ 1.0000, 1.5000, 2.0000, 2.5000, 3.0000, 3.5000, 4.0000])
ravel(...)
ravel(input) -> Tensor
Return a contiguous flattened tensor. A copy is made only if needed.
Args:
input (Tensor): the input tensor.
Example::
>>> t = torch.tensor([[[1, 2],
... [3, 4]],
... [[5, 6],
... [7, 8]]])
>>> torch.ravel(t)
tensor([1, 2, 3, 4, 5, 6, 7, 8])
real(...)
real(input) -> Tensor
Returns a new tensor containing real values of the :attr:`self` tensor.
The returned tensor and :attr:`self` share the same underlying storage.
Args:
input (Tensor): the input tensor.
Example::
>>> x=torch.randn(4, dtype=torch.cfloat)
>>> x
tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
>>> x.real
tensor([ 0.3100, -0.5445, -1.6492, -0.0638])
reciprocal(...)
reciprocal(input, *, out=None) -> Tensor
Returns a new tensor with the reciprocal of the elements of :attr:`input`
.. math::
\text{out}_{i} = \frac{1}{\text{input}_{i}}
.. note::
Unlike NumPy's reciprocal, torch.reciprocal supports integral inputs. Integral
inputs to reciprocal are automatically :ref:`promoted <type-promotion-doc>` to
the default scalar type.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-0.4595, -2.1219, -1.4314, 0.7298])
>>> torch.reciprocal(a)
tensor([-2.1763, -0.4713, -0.6986, 1.3702])
reciprocal_(...)
relu(...)
relu_(...)
relu_(input) -> Tensor
In-place version of :func:`~relu`.
remainder(...)
remainder(input, other, *, out=None) -> Tensor
Computes
`Python's modulus operation <https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations>`_
entrywise. The result has the same sign as the divisor :attr:`other` and its absolute value
is less than that of :attr:`other`.
It may also be defined in terms of :func:`torch.div` as
.. code:: python
torch.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer and float inputs.
.. note::
Complex inputs are not supported. In some cases, it is not mathematically
possible to satisfy the definition of a modulo operation with complex numbers.
See :func:`torch.fmod` for how division by zero is handled.
.. seealso::
:func:`torch.fmod` which implements C++'s `std::fmod <https://en.cppreference.com/w/cpp/numeric/math/fmod>`_.
This one is defined in terms of division rounding towards zero.
Args:
input (Tensor or Scalar): the dividend
other (Tensor or Scalar): the divisor
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
tensor([ 1., 0., 1., 1., 0., 1.])
>>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), -1.5)
tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])
renorm(...)
renorm(input, p, dim, maxnorm, *, out=None) -> Tensor
Returns a tensor where each sub-tensor of :attr:`input` along dimension
:attr:`dim` is normalized such that the `p`-norm of the sub-tensor is lower
than the value :attr:`maxnorm`
.. note:: If the norm of a row is lower than `maxnorm`, the row is unchanged
Args:
input (Tensor): the input tensor.
p (float): the power for the norm computation
dim (int): the dimension to slice over to get the sub-tensors
maxnorm (float): the maximum norm to keep each sub-tensor under
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.ones(3, 3)
>>> x[1].fill_(2)
tensor([ 2., 2., 2.])
>>> x[2].fill_(3)
tensor([ 3., 3., 3.])
>>> x
tensor([[ 1., 1., 1.],
[ 2., 2., 2.],
[ 3., 3., 3.]])
>>> torch.renorm(x, 1, 0, 5)
tensor([[ 1.0000, 1.0000, 1.0000],
[ 1.6667, 1.6667, 1.6667],
[ 1.6667, 1.6667, 1.6667]])
repeat_interleave(...)
repeat_interleave(input, repeats, dim=None, *, output_size=None) -> Tensor
Repeat elements of a tensor.
.. warning::
This is different from :meth:`torch.Tensor.repeat` but similar to ``numpy.repeat``.
Args:
input (Tensor): the input tensor.
repeats (Tensor or int): The number of repetitions for each element.
repeats is broadcasted to fit the shape of the given axis.
dim (int, optional): The dimension along which to repeat values.
By default, use the flattened input array, and return a flat output
array.
Keyword args:
output_size (int, optional): Total output size for the given axis
( e.g. sum of repeats). If given, it will avoid stream synchronization
needed to calculate output shape of the tensor.
Returns:
Tensor: Repeated tensor which has the same shape as input, except along the given axis.
Example::
>>> x = torch.tensor([1, 2, 3])
>>> x.repeat_interleave(2)
tensor([1, 1, 2, 2, 3, 3])
>>> y = torch.tensor([[1, 2], [3, 4]])
>>> torch.repeat_interleave(y, 2)
tensor([1, 1, 2, 2, 3, 3, 4, 4])
>>> torch.repeat_interleave(y, 3, dim=1)
tensor([[1, 1, 1, 2, 2, 2],
[3, 3, 3, 4, 4, 4]])
>>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
tensor([[1, 2],
[3, 4],
[3, 4]])
>>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0, output_size=3)
tensor([[1, 2],
[3, 4],
[3, 4]])
If the `repeats` is `tensor([n1, n2, n3, ...])`, then the output will be
`tensor([0, 0, ..., 1, 1, ..., 2, 2, ..., ...])` where `0` appears `n1` times,
`1` appears `n2` times, `2` appears `n3` times, etc.
.. function:: repeat_interleave(repeats, *) -> Tensor
:noindex:
Repeats 0 repeats[0] times, 1 repeats[1] times, 2 repeats[2] times, etc.
Args:
repeats (Tensor): The number of repetitions for each element.
Returns:
Tensor: Repeated tensor of size `sum(repeats)`.
Example::
>>> torch.repeat_interleave(torch.tensor([1, 2, 3]))
tensor([0, 1, 1, 2, 2, 2])
reshape(...)
reshape(input, shape) -> Tensor
Returns a tensor with the same data and number of elements as :attr:`input`,
but with the specified shape. When possible, the returned tensor will be a view
of :attr:`input`. Otherwise, it will be a copy. Contiguous inputs and inputs
with compatible strides can be reshaped without copying, but you should not
depend on the copying vs. viewing behavior.
See :meth:`torch.Tensor.view` on when it is possible to return a view.
A single dimension may be -1, in which case it's inferred from the remaining
dimensions and the number of elements in :attr:`input`.
Args:
input (Tensor): the tensor to be reshaped
shape (tuple of int): the new shape
Example::
>>> a = torch.arange(4.)
>>> torch.reshape(a, (2, 2))
tensor([[ 0., 1.],
[ 2., 3.]])
>>> b = torch.tensor([[0, 1], [2, 3]])
>>> torch.reshape(b, (-1,))
tensor([ 0, 1, 2, 3])
resize_as_(...)
resize_as_sparse_(...)
resolve_conj(...)
resolve_conj(input) -> Tensor
Returns a new tensor with materialized conjugation if :attr:`input`'s conjugate bit is set to `True`,
else returns :attr:`input`. The output tensor will always have its conjugate bit set to `False`.
Args:
input (Tensor): the input tensor.
Example::
>>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
>>> y = x.conj()
>>> y.is_conj()
True
>>> z = y.resolve_conj()
>>> z
tensor([-1 - 1j, -2 - 2j, 3 + 3j])
>>> z.is_conj()
False
resolve_neg(...)
resolve_neg(input) -> Tensor
Returns a new tensor with materialized negation if :attr:`input`'s negative bit is set to `True`,
else returns :attr:`input`. The output tensor will always have its negative bit set to `False`.
Args:
input (Tensor): the input tensor.
Example::
>>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
>>> y = x.conj()
>>> z = y.imag
>>> z.is_neg()
True
>>> out = z.resolve_neg()
>>> out
tensor([-1., -2., 3.])
>>> out.is_neg()
False
result_type(...)
result_type(tensor1, tensor2) -> dtype
Returns the :class:`torch.dtype` that would result from performing an arithmetic
operation on the provided input tensors. See type promotion :ref:`documentation <type-promotion-doc>`
for more information on the type promotion logic.
Args:
tensor1 (Tensor or Number): an input tensor or number
tensor2 (Tensor or Number): an input tensor or number
Example::
>>> torch.result_type(torch.tensor([1, 2], dtype=torch.int), 1.0)
torch.float32
>>> torch.result_type(torch.tensor([1, 2], dtype=torch.uint8), torch.tensor(1))
torch.uint8
rms_norm(...)
rnn_relu(...)
rnn_relu_cell(...)
rnn_tanh(...)
rnn_tanh_cell(...)
roll(...)
roll(input, shifts, dims=None) -> Tensor
Roll the tensor :attr:`input` along the given dimension(s). Elements that are
shifted beyond the last position are re-introduced at the first position. If
:attr:`dims` is `None`, the tensor will be flattened before rolling and then
restored to the original shape.
Args:
input (Tensor): the input tensor.
shifts (int or tuple of ints): The number of places by which the elements
of the tensor are shifted. If shifts is a tuple, dims must be a tuple of
the same size, and each dimension will be rolled by the corresponding
value
dims (int or tuple of ints): Axis along which to roll
Example::
>>> x = torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]).view(4, 2)
>>> x
tensor([[1, 2],
[3, 4],
[5, 6],
[7, 8]])
>>> torch.roll(x, 1)
tensor([[8, 1],
[2, 3],
[4, 5],
[6, 7]])
>>> torch.roll(x, 1, 0)
tensor([[7, 8],
[1, 2],
[3, 4],
[5, 6]])
>>> torch.roll(x, -1, 0)
tensor([[3, 4],
[5, 6],
[7, 8],
[1, 2]])
>>> torch.roll(x, shifts=(2, 1), dims=(0, 1))
tensor([[6, 5],
[8, 7],
[2, 1],
[4, 3]])
rot90(...)
rot90(input, k=1, dims=(0, 1)) -> Tensor
Rotate an n-D tensor by 90 degrees in the plane specified by dims axis.
Rotation direction is from the first towards the second axis if k > 0, and from the second towards the first for k < 0.
Args:
input (Tensor): the input tensor.
k (int): number of times to rotate. Default value is 1
dims (a list or tuple): axis to rotate. Default value is [0, 1]
Example::
>>> x = torch.arange(4).view(2, 2)
>>> x
tensor([[0, 1],
[2, 3]])
>>> torch.rot90(x, 1, [0, 1])
tensor([[1, 3],
[0, 2]])
>>> x = torch.arange(8).view(2, 2, 2)
>>> x
tensor([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
>>> torch.rot90(x, 1, [1, 2])
tensor([[[1, 3],
[0, 2]],
[[5, 7],
[4, 6]]])
round(...)
round(input, *, decimals=0, out=None) -> Tensor
Rounds elements of :attr:`input` to the nearest integer.
For integer inputs, follows the array-api convention of returning a
copy of the input tensor.
The return type of output is same as that of input's dtype.
.. note::
This function implements the "round half to even" to
break ties when a number is equidistant from two
integers (e.g. `round(2.5)` is 2).
When the :attr:\`decimals\` argument is specified the
algorithm used is similar to NumPy's `around`. This
algorithm is fast but inexact and it can easily
overflow for low precision dtypes.
Eg. `round(tensor([10000], dtype=torch.float16), decimals=3)` is `inf`.
.. seealso::
:func:`torch.ceil`, which rounds up.
:func:`torch.floor`, which rounds down.
:func:`torch.trunc`, which rounds towards zero.
Args:
input (Tensor): the input tensor.
decimals (int): Number of decimal places to round to (default: 0).
If decimals is negative, it specifies the number of positions
to the left of the decimal point.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> torch.round(torch.tensor((4.7, -2.3, 9.1, -7.7)))
tensor([ 5., -2., 9., -8.])
>>> # Values equidistant from two integers are rounded towards the
>>> # the nearest even value (zero is treated as even)
>>> torch.round(torch.tensor([-0.5, 0.5, 1.5, 2.5]))
tensor([-0., 0., 2., 2.])
>>> # A positive decimals argument rounds to the to that decimal place
>>> torch.round(torch.tensor([0.1234567]), decimals=3)
tensor([0.1230])
>>> # A negative decimals argument rounds to the left of the decimal
>>> torch.round(torch.tensor([1200.1234567]), decimals=-3)
tensor([1000.])
round_(...)
row_indices_copy(...)
row_stack(...)
row_stack(tensors, *, out=None) -> Tensor
Alias of :func:`torch.vstack`.
rrelu(...)
rrelu_(...)
rrelu_(input, lower=1./8, upper=1./3, training=False) -> Tensor
In-place version of :func:`~rrelu`.
rsqrt(...)
rsqrt(input, *, out=None) -> Tensor
Returns a new tensor with the reciprocal of the square-root of each of
the elements of :attr:`input`.
.. math::
\text{out}_{i} = \frac{1}{\sqrt{\text{input}_{i}}}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-0.0370, 0.2970, 1.5420, -0.9105])
>>> torch.rsqrt(a)
tensor([ nan, 1.8351, 0.8053, nan])
rsqrt_(...)
rsub(...)
saddmm(...)
save(obj: object, f: Union[str, os.PathLike[str], IO[bytes]], pickle_module: Any = <module 'pickle' from 'C:\\Users\\Youse\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\pickle.py'>, pickle_protocol: int = 2, _use_new_zipfile_serialization: bool = True, _disable_byteorder_record: bool = False) -> None
save(obj, f, pickle_module=pickle, pickle_protocol=2, _use_new_zipfile_serialization=True)
Saves an object to a disk file.
See also: :ref:`saving-loading-tensors`
See :ref:`layout-control` for more advanced tools to manipulate a checkpoint.
Args:
obj: saved object
f: a file-like object (has to implement write and flush) or a string or
os.PathLike object containing a file name
pickle_module: module used for pickling metadata and objects
pickle_protocol: can be specified to override the default protocol
.. note::
A common PyTorch convention is to save tensors using .pt file extension.
.. note::
PyTorch preserves storage sharing across serialization. See
:ref:`preserve-storage-sharing` for more details.
.. note::
The 1.6 release of PyTorch switched ``torch.save`` to use a new
zipfile-based file format. ``torch.load`` still retains the ability to
load files in the old format. If for any reason you want ``torch.save``
to use the old format, pass the kwarg ``_use_new_zipfile_serialization=False``.
Example:
>>> # xdoctest: +SKIP("makes cwd dirty")
>>> # Save to file
>>> x = torch.tensor([0, 1, 2, 3, 4])
>>> torch.save(x, "tensor.pt")
>>> # Save to io.BytesIO buffer
>>> buffer = io.BytesIO()
>>> torch.save(x, buffer)
scalar_tensor(...)
scatter(...)
scatter(input, dim, index, src) -> Tensor
Out-of-place version of :meth:`torch.Tensor.scatter_`
scatter_add(...)
scatter_add(input, dim, index, src) -> Tensor
Out-of-place version of :meth:`torch.Tensor.scatter_add_`
scatter_reduce(...)
scatter_reduce(input, dim, index, src, reduce, *, include_self=True) -> Tensor
Out-of-place version of :meth:`torch.Tensor.scatter_reduce_`
searchsorted(...)
searchsorted(sorted_sequence, values, *, out_int32=False, right=False, side=None, out=None, sorter=None) -> Tensor
Find the indices from the *innermost* dimension of :attr:`sorted_sequence` such that, if the
corresponding values in :attr:`values` were inserted before the indices, when sorted, the order
of the corresponding *innermost* dimension within :attr:`sorted_sequence` would be preserved.
Return a new tensor with the same size as :attr:`values`. More formally,
the returned index satisfies the following rules:
.. list-table::
:widths: 12 10 78
:header-rows: 1
* - :attr:`sorted_sequence`
- :attr:`right`
- *returned index satisfies*
* - 1-D
- False
- ``sorted_sequence[i-1] < values[m][n]...[l][x] <= sorted_sequence[i]``
* - 1-D
- True
- ``sorted_sequence[i-1] <= values[m][n]...[l][x] < sorted_sequence[i]``
* - N-D
- False
- ``sorted_sequence[m][n]...[l][i-1] < values[m][n]...[l][x] <= sorted_sequence[m][n]...[l][i]``
* - N-D
- True
- ``sorted_sequence[m][n]...[l][i-1] <= values[m][n]...[l][x] < sorted_sequence[m][n]...[l][i]``
Args:
sorted_sequence (Tensor): N-D or 1-D tensor, containing monotonically increasing sequence on the *innermost*
dimension unless :attr:`sorter` is provided, in which case the sequence does not
need to be sorted
values (Tensor or Scalar): N-D tensor or a Scalar containing the search value(s).
Keyword args:
out_int32 (bool, optional): indicate the output data type. torch.int32 if True, torch.int64 otherwise.
Default value is False, i.e. default output data type is torch.int64.
right (bool, optional): if False, return the first suitable location that is found. If True, return the
last such index. If no suitable index found, return 0 for non-numerical value
(eg. nan, inf) or the size of *innermost* dimension within :attr:`sorted_sequence`
(one pass the last index of the *innermost* dimension). In other words, if False,
gets the lower bound index for each value in :attr:`values` on the corresponding
*innermost* dimension of the :attr:`sorted_sequence`. If True, gets the upper
bound index instead. Default value is False. :attr:`side` does the same and is
preferred. It will error if :attr:`side` is set to "left" while this is True.
side (str, optional): the same as :attr:`right` but preferred. "left" corresponds to False for :attr:`right`
and "right" corresponds to True for :attr:`right`. It will error if this is set to
"left" while :attr:`right` is True. Default value is None.
out (Tensor, optional): the output tensor, must be the same size as :attr:`values` if provided.
sorter (LongTensor, optional): if provided, a tensor matching the shape of the unsorted
:attr:`sorted_sequence` containing a sequence of indices that sort it in the
ascending order on the innermost dimension
Example::
>>> sorted_sequence = torch.tensor([[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]])
>>> sorted_sequence
tensor([[ 1, 3, 5, 7, 9],
[ 2, 4, 6, 8, 10]])
>>> values = torch.tensor([[3, 6, 9], [3, 6, 9]])
>>> values
tensor([[3, 6, 9],
[3, 6, 9]])
>>> torch.searchsorted(sorted_sequence, values)
tensor([[1, 3, 4],
[1, 2, 4]])
>>> torch.searchsorted(sorted_sequence, values, side='right')
tensor([[2, 3, 5],
[1, 3, 4]])
>>> sorted_sequence_1d = torch.tensor([1, 3, 5, 7, 9])
>>> sorted_sequence_1d
tensor([1, 3, 5, 7, 9])
>>> torch.searchsorted(sorted_sequence_1d, values)
tensor([[1, 3, 4],
[1, 3, 4]])
seed() -> int
Sets the seed for generating random numbers to a non-deterministic
random number on all devices. Returns a 64 bit number used to seed the RNG.
select(...)
select(input, dim, index) -> Tensor
Slices the :attr:`input` tensor along the selected dimension at the given index.
This function returns a view of the original tensor with the given dimension removed.
.. note:: If :attr:`input` is a sparse tensor and returning a view of
the tensor is not possible, a RuntimeError exception is
raised. In this is the case, consider using
:func:`torch.select_copy` function.
Args:
input (Tensor): the input tensor.
dim (int): the dimension to slice
index (int): the index to select with
.. note::
:meth:`select` is equivalent to slicing. For example,
``tensor.select(0, index)`` is equivalent to ``tensor[index]`` and
``tensor.select(2, index)`` is equivalent to ``tensor[:,:,index]``.
select_copy(...)
Performs the same operation as :func:`torch.select`, but all output tensors
are freshly created instead of aliasing the input.
select_scatter(...)
select_scatter(input, src, dim, index) -> Tensor
Embeds the values of the :attr:`src` tensor into :attr:`input` at the given index.
This function returns a tensor with fresh storage; it does not create a view.
Args:
input (Tensor): the input tensor.
src (Tensor): The tensor to embed into :attr:`input`
dim (int): the dimension to insert the slice into.
index (int): the index to select with
.. note::
:attr:`src` must be of the proper size in order to be embedded
into :attr:`input`. Specifically, it should have the same shape as
``torch.select(input, dim, index)``
Example::
>>> a = torch.zeros(2, 2)
>>> b = torch.ones(2)
>>> a.select_scatter(b, 0, 0)
tensor([[1., 1.],
[0., 0.]])
selu(...)
selu_(...)
selu_(input) -> Tensor
In-place version of :func:`~selu`.
set_anomaly_enabled(...)
set_autocast_cache_enabled(...)
set_autocast_cpu_dtype(...)
set_autocast_cpu_enabled(...)
set_autocast_dtype(...)
set_autocast_enabled(...)
set_autocast_gpu_dtype(...)
set_autocast_ipu_dtype(...)
set_autocast_ipu_enabled(...)
set_autocast_xla_dtype(...)
set_autocast_xla_enabled(...)
set_default_device(device: 'Device') -> None
Sets the default ``torch.Tensor`` to be allocated on ``device``. This
does not affect factory function calls which are called with an explicit
``device`` argument. Factory calls will be performed as if they
were passed ``device`` as an argument.
To only temporarily change the default device instead of setting it
globally, use ``with torch.device(device):`` instead.
The default device is initially ``cpu``. If you set the default tensor
device to another device (e.g., ``cuda``) without a device index, tensors
will be allocated on whatever the current device for the device type,
even after :func:`torch.cuda.set_device` is called.
.. warning::
This function imposes a slight performance cost on every Python
call to the torch API (not just factory functions). If this
is causing problems for you, please comment on
https://github.com/pytorch/pytorch/issues/92701
.. note::
This doesn't affect functions that create tensors that share the same memory as the input, like:
:func:`torch.from_numpy` and :func:`torch.frombuffer`
Args:
device (device or string): the device to set as default
Example::
>>> # xdoctest: +SKIP("requires cuda, changes global state")
>>> torch.get_default_device()
device(type='cpu')
>>> torch.set_default_device('cuda') # current device is 0
>>> torch.get_default_device()
device(type='cuda', index=0)
>>> torch.set_default_device('cuda')
>>> torch.cuda.set_device('cuda:1') # current device is 1
>>> torch.get_default_device()
device(type='cuda', index=1)
>>> torch.set_default_device('cuda:1')
>>> torch.get_default_device()
device(type='cuda', index=1)
set_default_tensor_type(t: type['torch.Tensor'] | str, /) -> None
.. warning::
This function is deprecated as of PyTorch 2.1, please use :func:`torch.set_default_dtype()` and
:func:`torch.set_default_device()` as alternatives.
Sets the default ``torch.Tensor`` type to floating point tensor type
``t``. This type will also be used as default floating point type for
type inference in :func:`torch.tensor`.
The default floating point tensor type is initially ``torch.FloatTensor``.
Args:
t (type or string): the floating point tensor type or its name
Example::
>>> # xdoctest: +SKIP("Other tests may have changed the default type. Can we reset it?")
>>> torch.tensor([1.2, 3]).dtype # initial default for floating point is torch.float32
torch.float32
>>> torch.set_default_tensor_type(torch.DoubleTensor)
>>> torch.tensor([1.2, 3]).dtype # a new floating point tensor
torch.float64
set_deterministic_debug_mode(debug_mode: int | str) -> None
Sets the debug mode for deterministic operations.
.. note:: This is an alternative interface for
:func:`torch.use_deterministic_algorithms`. Refer to that function's
documentation for details about affected operations.
Args:
debug_mode(str or int): If "default" or 0, don't error or warn on
nondeterministic operations. If "warn" or 1, warn on
nondeterministic operations. If "error" or 2, error on
nondeterministic operations.
set_float32_matmul_precision(precision: str) -> None
Sets the internal precision of float32 matrix multiplications.
Running float32 matrix multiplications in lower precision may significantly increase
performance, and in some programs the loss of precision has a negligible impact.
Supports three settings:
* "highest", float32 matrix multiplications use the float32 datatype (24 mantissa
bits with 23 bits explicitly stored) for internal computations.
* "high", float32 matrix multiplications either use the TensorFloat32 datatype (10
mantissa bits explicitly stored) or treat each float32 number as the sum of two bfloat16 numbers
(approximately 16 mantissa bits with 14 bits explicitly stored), if the appropriate fast matrix multiplication
algorithms are available. Otherwise float32 matrix multiplications are computed
as if the precision is "highest". See below for more information on the bfloat16
approach.
* "medium", float32 matrix multiplications use the bfloat16 datatype (8 mantissa
bits with 7 bits explicitly stored) for internal computations, if a fast matrix multiplication algorithm
using that datatype internally is available. Otherwise float32
matrix multiplications are computed as if the precision is "high".
When using "high" precision, float32 multiplications may use a bfloat16-based algorithm
that is more complicated than simply truncating to some smaller number mantissa bits
(e.g. 10 for TensorFloat32, 7 for bfloat16 explicitly stored). Refer to [Henry2019]_ for a complete
description of this algorithm. To briefly explain here, the first step is to realize
that we can perfectly encode a single float32 number as the sum of three bfloat16
numbers (because float32 has 23 mantissa bits while bfloat16 has 7 explicitly stored, and both have the
same number of exponent bits). This means that the product of two float32 numbers can
be exactly given by the sum of nine products of bfloat16 numbers. We can then trade
accuracy for speed by dropping some of these products. The "high" precision algorithm
specifically keeps only the three most significant products, which conveniently excludes
all of the products involving the last 8 mantissa bits of either input. This means that
we can represent our inputs as the sum of two bfloat16 numbers rather than three.
Because bfloat16 fused-multiply-add (FMA) instructions are typically >10x faster than
float32 ones, it's faster to do three multiplications and 2 additions with bfloat16
precision than it is to do a single multiplication with float32 precision.
.. [Henry2019] http://arxiv.org/abs/1904.06376
.. note::
This does not change the output dtype of float32 matrix multiplications,
it controls how the internal computation of the matrix multiplication is performed.
.. note::
This does not change the precision of convolution operations. Other flags,
like `torch.backends.cudnn.allow_tf32`, may control the precision of convolution
operations.
.. note::
This flag currently only affects one native device type: CUDA.
If "high" or "medium" are set then the TensorFloat32 datatype will be used
when computing float32 matrix multiplications, equivalent to setting
`torch.backends.cuda.matmul.allow_tf32 = True`. When "highest" (the default)
is set then the float32 datatype is used for internal computations, equivalent
to setting `torch.backends.cuda.matmul.allow_tf32 = False`.
Args:
precision(str): can be set to "highest" (default), "high", or "medium" (see above).
set_flush_denormal(...)
set_flush_denormal(mode) -> bool
Disables denormal floating numbers on CPU.
Returns ``True`` if your system supports flushing denormal numbers and it
successfully configures flush denormal mode. :meth:`~torch.set_flush_denormal`
is supported on x86 architectures supporting SSE3 and AArch64 architecture.
Args:
mode (bool): Controls whether to enable flush denormal mode or not
Example::
>>> torch.set_flush_denormal(True)
True
>>> torch.tensor([1e-323], dtype=torch.float64)
tensor([ 0.], dtype=torch.float64)
>>> torch.set_flush_denormal(False)
True
>>> torch.tensor([1e-323], dtype=torch.float64)
tensor(9.88131e-324 *
[ 1.0000], dtype=torch.float64)
set_num_interop_threads(...)
set_num_interop_threads(int)
Sets the number of threads used for interop parallelism
(e.g. in JIT interpreter) on CPU.
.. warning::
Can only be called once and before any inter-op parallel work
is started (e.g. JIT execution).
set_num_threads(...)
set_num_threads(int)
Sets the number of threads used for intraop parallelism on CPU.
.. warning::
To ensure that the correct number of threads is used, set_num_threads
must be called before running eager, JIT or autograd code.
set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, profile=None, sci_mode=None)
Set options for printing. Items shamelessly taken from NumPy
Args:
precision: Number of digits of precision for floating point output
(default = 4).
threshold: Total number of array elements which trigger summarization
rather than full `repr` (default = 1000).
edgeitems: Number of array items in summary at beginning and end of
each dimension (default = 3).
linewidth: The number of characters per line for the purpose of
inserting line breaks (default = 80). Thresholded matrices will
ignore this parameter.
profile: Sane defaults for pretty printing. Can override with any of
the above options. (any one of `default`, `short`, `full`)
sci_mode: Enable (True) or disable (False) scientific notation. If
None (default) is specified, the value is defined by
`torch._tensor_str._Formatter`. This value is automatically chosen
by the framework.
Example::
>>> # Limit the precision of elements
>>> torch.set_printoptions(precision=2)
>>> torch.tensor([1.12345])
tensor([1.12])
>>> # Limit the number of elements shown
>>> torch.set_printoptions(threshold=5)
>>> torch.arange(10)
tensor([0, 1, 2, ..., 7, 8, 9])
>>> # Restore defaults
>>> torch.set_printoptions(profile='default')
>>> torch.tensor([1.12345])
tensor([1.1235])
>>> torch.arange(10)
tensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
set_rng_state(new_state: torch.Tensor) -> None
Sets the random number generator state.
.. note:: This function only works for CPU. For CUDA, please use
:func:`torch.manual_seed`, which works for both CPU and CUDA.
Args:
new_state (torch.ByteTensor): The desired state
set_warn_always(b: bool, /) -> None
When this flag is False (default) then some PyTorch warnings may only
appear once per process. This helps avoid excessive warning information.
Setting it to True causes these warnings to always appear, which may be
helpful when debugging.
Args:
b (:class:`bool`): If True, force warnings to always be emitted
If False, set to the default behaviour
sgn(...)
sgn(input, *, out=None) -> Tensor
This function is an extension of torch.sign() to complex tensors.
It computes a new tensor whose elements have
the same angles as the corresponding elements of :attr:`input` and
absolute values (i.e. magnitudes) of one for complex tensors and
is equivalent to torch.sign() for non-complex tensors.
.. math::
\text{out}_{i} = \begin{cases}
0 & |\text{{input}}_i| == 0 \\
\frac{{\text{{input}}_i}}{|{\text{{input}}_i}|} & \text{otherwise}
\end{cases}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.tensor([3+4j, 7-24j, 0, 1+2j])
>>> t.sgn()
tensor([0.6000+0.8000j, 0.2800-0.9600j, 0.0000+0.0000j, 0.4472+0.8944j])
sigmoid(...)
sigmoid(input, *, out=None) -> Tensor
Alias for :func:`torch.special.expit`.
sigmoid_(...)
sign(...)
sign(input, *, out=None) -> Tensor
Returns a new tensor with the signs of the elements of :attr:`input`.
.. math::
\text{out}_{i} = \operatorname{sgn}(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([0.7, -1.2, 0., 2.3])
>>> a
tensor([ 0.7000, -1.2000, 0.0000, 2.3000])
>>> torch.sign(a)
tensor([ 1., -1., 0., 1.])
signbit(...)
signbit(input, *, out=None) -> Tensor
Tests if each element of :attr:`input` has its sign bit set or not.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([0.7, -1.2, 0., 2.3])
>>> torch.signbit(a)
tensor([ False, True, False, False])
>>> a = torch.tensor([-0.0, 0.0])
>>> torch.signbit(a)
tensor([ True, False])
.. note::
signbit handles signed zeros, so negative zero (-0) returns True.
sin(...)
sin(input, *, out=None) -> Tensor
Returns a new tensor with the sine of the elements in the :attr:`input` tensor,
where each value in this input tensor is in radians.
.. math::
\text{out}_{i} = \sin(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-0.5461, 0.1347, -2.7266, -0.2746])
>>> torch.sin(a)
tensor([-0.5194, 0.1343, -0.4032, -0.2711])
sin_(...)
sinc(...)
sinc(input, *, out=None) -> Tensor
Alias for :func:`torch.special.sinc`.
sinc_(...)
sinh(...)
sinh(input, *, out=None) -> Tensor
Returns a new tensor with the hyperbolic sine of the elements of
:attr:`input`.
.. math::
\text{out}_{i} = \sinh(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.5380, -0.8632, -0.1265, 0.9399])
>>> torch.sinh(a)
tensor([ 0.5644, -0.9744, -0.1268, 1.0845])
.. note::
When :attr:`input` is on the CPU, the implementation of torch.sinh may use
the Sleef library, which rounds very large results to infinity or negative
infinity. See `here <https://sleef.org/purec.xhtml>`_ for details.
sinh_(...)
slice_copy(...)
Performs the same operation as :func:`torch.slice`, but all output tensors
are freshly created instead of aliasing the input.
slice_inverse(...)
slice_scatter(...)
slice_scatter(input, src, dim=0, start=None, end=None, step=1) -> Tensor
Embeds the values of the :attr:`src` tensor into :attr:`input` at the given
dimension.
This function returns a tensor with fresh storage; it does not create a view.
Args:
input (Tensor): the input tensor.
src (Tensor): The tensor to embed into :attr:`input`
dim (int): the dimension to insert the slice into
start (Optional[int]): the start index of where to insert the slice
end (Optional[int]): the end index of where to insert the slice
step (int): the how many elements to skip in
Example::
>>> a = torch.zeros(8, 8)
>>> b = torch.ones(2, 8)
>>> a.slice_scatter(b, start=6)
tensor([[0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0.],
[1., 1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1., 1.]])
>>> b = torch.ones(8, 2)
>>> a.slice_scatter(b, dim=1, start=2, end=6, step=2)
tensor([[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 1., 0., 0., 0.]])
slogdet(...)
slogdet(input) -> (Tensor, Tensor)
Alias for :func:`torch.linalg.slogdet`
smm(...)
smm(input, mat) -> Tensor
Performs a matrix multiplication of the sparse matrix :attr:`input`
with the dense matrix :attr:`mat`.
Args:
input (Tensor): a sparse matrix to be matrix multiplied
mat (Tensor): a dense matrix to be matrix multiplied
softmax(...)
softmax(input, dim, *, dtype=None) -> Tensor
Alias for :func:`torch.nn.functional.softmax`.
sort(...)
sort(input, dim=-1, descending=False, *, stable=False, out=None) -> (Tensor, LongTensor)
Sorts the elements of the :attr:`input` tensor along a given dimension
in ascending order by value.
If :attr:`dim` is not given, the last dimension of the `input` is chosen.
If :attr:`descending` is ``True`` then the elements are sorted in descending
order by value.
If :attr:`stable` is ``True`` then the sorting routine becomes stable, preserving
the order of equivalent elements.
A namedtuple of (values, indices) is returned, where the `values` are the
sorted values and `indices` are the indices of the elements in the original
`input` tensor.
Args:
input (Tensor): the input tensor.
dim (int, optional): the dimension to sort along
descending (bool, optional): controls the sorting order (ascending or descending)
Keyword args:
stable (bool, optional): makes the sorting routine stable, which guarantees that the order
of equivalent elements is preserved.
out (tuple, optional): the output tuple of (`Tensor`, `LongTensor`) that can
be optionally given to be used as output buffers
Example::
>>> x = torch.randn(3, 4)
>>> sorted, indices = torch.sort(x)
>>> sorted
tensor([[-0.2162, 0.0608, 0.6719, 2.3332],
[-0.5793, 0.0061, 0.6058, 0.9497],
[-0.5071, 0.3343, 0.9553, 1.0960]])
>>> indices
tensor([[ 1, 0, 2, 3],
[ 3, 1, 0, 2],
[ 0, 3, 1, 2]])
>>> sorted, indices = torch.sort(x, 0)
>>> sorted
tensor([[-0.5071, -0.2162, 0.6719, -0.5793],
[ 0.0608, 0.0061, 0.9497, 0.3343],
[ 0.6058, 0.9553, 1.0960, 2.3332]])
>>> indices
tensor([[ 2, 0, 0, 1],
[ 0, 1, 1, 2],
[ 1, 2, 2, 0]])
>>> x = torch.tensor([0, 1] * 9)
>>> x.sort()
torch.return_types.sort(
values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
indices=tensor([ 2, 16, 4, 6, 14, 8, 0, 10, 12, 9, 17, 15, 13, 11, 7, 5, 3, 1]))
>>> x.sort(stable=True)
torch.return_types.sort(
values=tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
indices=tensor([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17]))
sparse_bsc_tensor(...)
sparse_bsc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
Constructs a :ref:`sparse tensor in BSC (Block Compressed Sparse
Column)) <sparse-bsc-docs>` with specified 2-dimensional blocks at the
given :attr:`ccol_indices` and :attr:`row_indices`. Sparse matrix
multiplication operations in BSC format are typically faster than that
for sparse tensors in COO format. Make you have a look at :ref:`the
note on the data type of the indices <sparse-bsc-docs>`.
.. note::
If the ``device`` argument is not specified the device of the given
:attr:`values` and indices tensor(s) must match. If, however, the
argument is specified the input Tensors will be converted to the
given device and in turn determine the device of the constructed
sparse tensor.
Args:
ccol_indices (array_like): (B+1)-dimensional array of size
``(*batchsize, ncolblocks + 1)``. The last element of each
batch is the number of non-zeros. This tensor encodes the
index in values and row_indices depending on where the given
column starts. Each successive number in the tensor subtracted
by the number before it denotes the number of elements in a
given column.
row_indices (array_like): Row block coordinates of each block in
values. (B+1)-dimensional tensor with the same length
as values.
values (array_list): Initial blocks for the tensor. Can be a list,
tuple, NumPy ``ndarray``, and other types that
represents a (1 + 2 + K)-dimensional tensor where ``K`` is the
number of dense dimensions.
size (list, tuple, :class:`torch.Size`, optional): Size of the
sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
blocksize[1], *densesize)`` If not provided, the size will be
inferred as the minimum size big enough to hold all non-zero
blocks.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. Default: if None, infers data type from
:attr:`values`.
device (:class:`torch.device`, optional): the desired device of
returned tensor. Default: if None, uses the current device
for the default tensor type (see
:func:`torch.set_default_device`). :attr:`device` will be
the CPU for CPU tensor types and the current CUDA device for
CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
check_invariants (bool, optional): If sparse tensor invariants are checked.
Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
initially False.
Example::
>>> ccol_indices = [0, 1, 2]
>>> row_indices = [0, 1]
>>> values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
>>> torch.sparse_bsc_tensor(torch.tensor(ccol_indices, dtype=torch.int64),
... torch.tensor(row_indices, dtype=torch.int64),
... torch.tensor(values), dtype=torch.double)
tensor(ccol_indices=tensor([0, 1, 2]),
row_indices=tensor([0, 1]),
values=tensor([[[1., 2.],
[3., 4.]],
[[5., 6.],
[7., 8.]]]), size=(2, 2), nnz=2, dtype=torch.float64,
layout=torch.sparse_bsc)
sparse_bsr_tensor(...)
sparse_bsr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
Constructs a :ref:`sparse tensor in BSR (Block Compressed Sparse Row))
<sparse-bsr-docs>` with specified 2-dimensional blocks at the given
:attr:`crow_indices` and :attr:`col_indices`. Sparse matrix
multiplication operations in BSR format are typically faster than that
for sparse tensors in COO format. Make you have a look at :ref:`the
note on the data type of the indices <sparse-bsr-docs>`.
.. note::
If the ``device`` argument is not specified the device of the given
:attr:`values` and indices tensor(s) must match. If, however, the
argument is specified the input Tensors will be converted to the
given device and in turn determine the device of the constructed
sparse tensor.
Args:
crow_indices (array_like): (B+1)-dimensional array of size
``(*batchsize, nrowblocks + 1)``. The last element of each
batch is the number of non-zeros. This tensor encodes the
block index in values and col_indices depending on where the
given row block starts. Each successive number in the tensor
subtracted by the number before it denotes the number of
blocks in a given row.
col_indices (array_like): Column block coordinates of each block
in values. (B+1)-dimensional tensor with the same length as
values.
values (array_list): Initial values for the tensor. Can be a list,
tuple, NumPy ``ndarray``, scalar, and other types that
represents a (1 + 2 + K)-dimensional tensor where ``K`` is the
number of dense dimensions.
size (list, tuple, :class:`torch.Size`, optional): Size of the
sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
blocksize[1], *densesize)`` where ``blocksize ==
values.shape[1:3]``. If not provided, the size will be
inferred as the minimum size big enough to hold all non-zero
blocks.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. Default: if None, infers data type from
:attr:`values`.
device (:class:`torch.device`, optional): the desired device of
returned tensor. Default: if None, uses the current device
for the default tensor type (see
:func:`torch.set_default_device`). :attr:`device` will be
the CPU for CPU tensor types and the current CUDA device for
CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
check_invariants (bool, optional): If sparse tensor invariants are checked.
Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
initially False.
Example::
>>> crow_indices = [0, 1, 2]
>>> col_indices = [0, 1]
>>> values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
>>> torch.sparse_bsr_tensor(torch.tensor(crow_indices, dtype=torch.int64),
... torch.tensor(col_indices, dtype=torch.int64),
... torch.tensor(values), dtype=torch.double)
tensor(crow_indices=tensor([0, 1, 2]),
col_indices=tensor([0, 1]),
values=tensor([[[1., 2.],
[3., 4.]],
[[5., 6.],
[7., 8.]]]), size=(2, 2), nnz=2, dtype=torch.float64,
layout=torch.sparse_bsr)
sparse_compressed_tensor(...)
sparse_compressed_tensor(compressed_indices, plain_indices, values, size=None, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
Constructs a :ref:`sparse tensor in Compressed Sparse format - CSR,
CSC, BSR, or BSC - <sparse-compressed-docs>` with specified values at
the given :attr:`compressed_indices` and :attr:`plain_indices`. Sparse
matrix multiplication operations in Compressed Sparse format are
typically faster than that for sparse tensors in COO format. Make you
have a look at :ref:`the note on the data type of the indices
<sparse-compressed-docs>`.
.. note::
If the ``device`` argument is not specified the device of the given
:attr:`values` and indices tensor(s) must match. If, however, the
argument is specified the input Tensors will be converted to the
given device and in turn determine the device of the constructed
sparse tensor.
Args:
compressed_indices (array_like): (B+1)-dimensional array of size
``(*batchsize, compressed_dim_size + 1)``. The last element of
each batch is the number of non-zero elements or blocks. This
tensor encodes the index in ``values`` and ``plain_indices``
depending on where the given compressed dimension (row or
column) starts. Each successive number in the tensor
subtracted by the number before it denotes the number of
elements or blocks in a given compressed dimension.
plain_indices (array_like): Plain dimension (column or row)
coordinates of each element or block in values. (B+1)-dimensional
tensor with the same length as values.
values (array_list): Initial values for the tensor. Can be a list,
tuple, NumPy ``ndarray``, scalar, and other types. that
represents a (1+K)-dimensional (for CSR and CSC layouts) or
(1+2+K)-dimensional tensor (for BSR and BSC layouts) where
``K`` is the number of dense dimensions.
size (list, tuple, :class:`torch.Size`, optional): Size of the
sparse tensor: ``(*batchsize, nrows * blocksize[0], ncols *
blocksize[1], *densesize)`` where ``blocksize[0] ==
blocksize[1] == 1`` for CSR and CSC formats. If not provided,
the size will be inferred as the minimum size big enough to
hold all non-zero elements or blocks.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. Default: if None, infers data type from
:attr:`values`.
layout (:class:`torch.layout`, required): the desired layout of
returned tensor: :attr:`torch.sparse_csr`,
:attr:`torch.sparse_csc`, :attr:`torch.sparse_bsr`, or
:attr:`torch.sparse_bsc`.
device (:class:`torch.device`, optional): the desired device of
returned tensor. Default: if None, uses the current device
for the default tensor type (see
:func:`torch.set_default_device`). :attr:`device` will be
the CPU for CPU tensor types and the current CUDA device for
CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
check_invariants (bool, optional): If sparse tensor invariants are checked.
Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
initially False.
Example::
>>> compressed_indices = [0, 2, 4]
>>> plain_indices = [0, 1, 0, 1]
>>> values = [1, 2, 3, 4]
>>> torch.sparse_compressed_tensor(torch.tensor(compressed_indices, dtype=torch.int64),
... torch.tensor(plain_indices, dtype=torch.int64),
... torch.tensor(values), dtype=torch.double, layout=torch.sparse_csr)
tensor(crow_indices=tensor([0, 2, 4]),
col_indices=tensor([0, 1, 0, 1]),
values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
dtype=torch.float64, layout=torch.sparse_csr)
sparse_coo_tensor(...)
sparse_coo_tensor(indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None, is_coalesced=None) -> Tensor
Constructs a :ref:`sparse tensor in COO(rdinate) format
<sparse-coo-docs>` with specified values at the given
:attr:`indices`.
.. note::
This function returns an :ref:`uncoalesced tensor
<sparse-uncoalesced-coo-docs>` when :attr:`is_coalesced` is
unspecified or ``None``.
.. note::
If the ``device`` argument is not specified the device of the given
:attr:`values` and indices tensor(s) must match. If, however, the
argument is specified the input Tensors will be converted to the
given device and in turn determine the device of the constructed
sparse tensor.
Args:
indices (array_like): Initial data for the tensor. Can be a list, tuple,
NumPy ``ndarray``, scalar, and other types. Will be cast to a :class:`torch.LongTensor`
internally. The indices are the coordinates of the non-zero values in the matrix, and thus
should be two-dimensional where the first dimension is the number of tensor dimensions and
the second dimension is the number of non-zero values.
values (array_like): Initial values for the tensor. Can be a list, tuple,
NumPy ``ndarray``, scalar, and other types.
size (list, tuple, or :class:`torch.Size`, optional): Size of the sparse tensor. If not
provided the size will be inferred as the minimum size big enough to hold all non-zero
elements.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if None, infers data type from :attr:`values`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if None, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
check_invariants (bool, optional): If sparse tensor invariants are checked.
Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
initially False.
is_coalesced (bool, optional): When``True``, the caller is
responsible for providing tensor indices that correspond to a
coalesced tensor. If the :attr:`check_invariants` flag is
False, no error will be raised if the prerequisites are not
met and this will lead to silently incorrect results. To force
coalescing please use :meth:`coalesce` on the resulting
Tensor.
Default: None: except for trivial cases (e.g. nnz < 2) the
resulting Tensor has is_coalesced set to ``False```.
Example::
>>> i = torch.tensor([[0, 1, 1],
... [2, 0, 2]])
>>> v = torch.tensor([3, 4, 5], dtype=torch.float32)
>>> torch.sparse_coo_tensor(i, v, [2, 4])
tensor(indices=tensor([[0, 1, 1],
[2, 0, 2]]),
values=tensor([3., 4., 5.]),
size=(2, 4), nnz=3, layout=torch.sparse_coo)
>>> torch.sparse_coo_tensor(i, v) # Shape inference
tensor(indices=tensor([[0, 1, 1],
[2, 0, 2]]),
values=tensor([3., 4., 5.]),
size=(2, 3), nnz=3, layout=torch.sparse_coo)
>>> torch.sparse_coo_tensor(i, v, [2, 4],
... dtype=torch.float64,
... device=torch.device('cuda:0'))
tensor(indices=tensor([[0, 1, 1],
[2, 0, 2]]),
values=tensor([3., 4., 5.]),
device='cuda:0', size=(2, 4), nnz=3, dtype=torch.float64,
layout=torch.sparse_coo)
# Create an empty sparse tensor with the following invariants:
# 1. sparse_dim + dense_dim = len(SparseTensor.shape)
# 2. SparseTensor._indices().shape = (sparse_dim, nnz)
# 3. SparseTensor._values().shape = (nnz, SparseTensor.shape[sparse_dim:])
#
# For instance, to create an empty sparse tensor with nnz = 0, dense_dim = 0 and
# sparse_dim = 1 (hence indices is a 2D tensor of shape = (1, 0))
>>> S = torch.sparse_coo_tensor(torch.empty([1, 0]), [], [1])
tensor(indices=tensor([], size=(1, 0)),
values=tensor([], size=(0,)),
size=(1,), nnz=0, layout=torch.sparse_coo)
# and to create an empty sparse tensor with nnz = 0, dense_dim = 1 and
# sparse_dim = 1
>>> S = torch.sparse_coo_tensor(torch.empty([1, 0]), torch.empty([0, 2]), [1, 2])
tensor(indices=tensor([], size=(1, 0)),
values=tensor([], size=(0, 2)),
size=(1, 2), nnz=0, layout=torch.sparse_coo)
.. _torch.sparse: https://pytorch.org/docs/stable/sparse.html
sparse_csc_tensor(...)
sparse_csc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
Constructs a :ref:`sparse tensor in CSC (Compressed Sparse Column)
<sparse-csc-docs>` with specified values at the given
:attr:`ccol_indices` and :attr:`row_indices`. Sparse matrix
multiplication operations in CSC format are typically faster than that
for sparse tensors in COO format. Make you have a look at :ref:`the
note on the data type of the indices <sparse-csc-docs>`.
.. note::
If the ``device`` argument is not specified the device of the given
:attr:`values` and indices tensor(s) must match. If, however, the
argument is specified the input Tensors will be converted to the
given device and in turn determine the device of the constructed
sparse tensor.
Args:
ccol_indices (array_like): (B+1)-dimensional array of size
``(*batchsize, ncols + 1)``. The last element of each batch
is the number of non-zeros. This tensor encodes the index in
values and row_indices depending on where the given column
starts. Each successive number in the tensor subtracted by the
number before it denotes the number of elements in a given
column.
row_indices (array_like): Row coordinates of each element in
values. (B+1)-dimensional tensor with the same length as
values.
values (array_list): Initial values for the tensor. Can be a list,
tuple, NumPy ``ndarray``, scalar, and other types that
represents a (1+K)-dimensional tensor where ``K`` is the number
of dense dimensions.
size (list, tuple, :class:`torch.Size`, optional): Size of the
sparse tensor: ``(*batchsize, nrows, ncols, *densesize)``. If
not provided, the size will be inferred as the minimum size
big enough to hold all non-zero elements.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. Default: if None, infers data type from
:attr:`values`.
device (:class:`torch.device`, optional): the desired device of
returned tensor. Default: if None, uses the current device
for the default tensor type (see
:func:`torch.set_default_device`). :attr:`device` will be
the CPU for CPU tensor types and the current CUDA device for
CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
check_invariants (bool, optional): If sparse tensor invariants are checked.
Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
initially False.
Example::
>>> ccol_indices = [0, 2, 4]
>>> row_indices = [0, 1, 0, 1]
>>> values = [1, 2, 3, 4]
>>> torch.sparse_csc_tensor(torch.tensor(ccol_indices, dtype=torch.int64),
... torch.tensor(row_indices, dtype=torch.int64),
... torch.tensor(values), dtype=torch.double)
tensor(ccol_indices=tensor([0, 2, 4]),
row_indices=tensor([0, 1, 0, 1]),
values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
dtype=torch.float64, layout=torch.sparse_csc)
sparse_csr_tensor(...)
sparse_csr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) -> Tensor
Constructs a :ref:`sparse tensor in CSR (Compressed Sparse Row) <sparse-csr-docs>` with specified
values at the given :attr:`crow_indices` and :attr:`col_indices`. Sparse matrix multiplication operations
in CSR format are typically faster than that for sparse tensors in COO format. Make you have a look
at :ref:`the note on the data type of the indices <sparse-csr-docs>`.
.. note::
If the ``device`` argument is not specified the device of the given
:attr:`values` and indices tensor(s) must match. If, however, the
argument is specified the input Tensors will be converted to the
given device and in turn determine the device of the constructed
sparse tensor.
Args:
crow_indices (array_like): (B+1)-dimensional array of size
``(*batchsize, nrows + 1)``. The last element of each batch
is the number of non-zeros. This tensor encodes the index in
values and col_indices depending on where the given row
starts. Each successive number in the tensor subtracted by the
number before it denotes the number of elements in a given
row.
col_indices (array_like): Column coordinates of each element in
values. (B+1)-dimensional tensor with the same length
as values.
values (array_list): Initial values for the tensor. Can be a list,
tuple, NumPy ``ndarray``, scalar, and other types that
represents a (1+K)-dimensional tensor where ``K`` is the number
of dense dimensions.
size (list, tuple, :class:`torch.Size`, optional): Size of the
sparse tensor: ``(*batchsize, nrows, ncols, *densesize)``. If
not provided, the size will be inferred as the minimum size
big enough to hold all non-zero elements.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of
returned tensor. Default: if None, infers data type from
:attr:`values`.
device (:class:`torch.device`, optional): the desired device of
returned tensor. Default: if None, uses the current device
for the default tensor type (see
:func:`torch.set_default_device`). :attr:`device` will be
the CPU for CPU tensor types and the current CUDA device for
CUDA tensor types.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
check_invariants (bool, optional): If sparse tensor invariants are checked.
Default: as returned by :func:`torch.sparse.check_sparse_tensor_invariants.is_enabled`,
initially False.
Example::
>>> crow_indices = [0, 2, 4]
>>> col_indices = [0, 1, 0, 1]
>>> values = [1, 2, 3, 4]
>>> torch.sparse_csr_tensor(torch.tensor(crow_indices, dtype=torch.int64),
... torch.tensor(col_indices, dtype=torch.int64),
... torch.tensor(values), dtype=torch.double)
tensor(crow_indices=tensor([0, 2, 4]),
col_indices=tensor([0, 1, 0, 1]),
values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
dtype=torch.float64, layout=torch.sparse_csr)
split(tensor: torch.Tensor, split_size_or_sections: int | list[int], dim: int = 0) -> tuple[torch.Tensor, ...]
Splits the tensor into chunks. Each chunk is a view of the original tensor.
If :attr:`split_size_or_sections` is an integer type, then :attr:`tensor` will
be split into equally sized chunks (if possible). Last chunk will be smaller if
the tensor size along the given dimension :attr:`dim` is not divisible by
:attr:`split_size`.
If :attr:`split_size_or_sections` is a list, then :attr:`tensor` will be split
into ``len(split_size_or_sections)`` chunks with sizes in :attr:`dim` according
to :attr:`split_size_or_sections`.
Args:
tensor (Tensor): tensor to split.
split_size_or_sections (int) or (list(int)): size of a single chunk or
list of sizes for each chunk
dim (int): dimension along which to split the tensor.
Example::
>>> a = torch.arange(10).reshape(5, 2)
>>> a
tensor([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
>>> torch.split(a, 2)
(tensor([[0, 1],
[2, 3]]),
tensor([[4, 5],
[6, 7]]),
tensor([[8, 9]]))
>>> torch.split(a, [1, 4])
(tensor([[0, 1]]),
tensor([[2, 3],
[4, 5],
[6, 7],
[8, 9]]))
split_copy(...)
Performs the same operation as :func:`torch.split`, but all output tensors
are freshly created instead of aliasing the input.
split_with_sizes(...)
split_with_sizes_copy(...)
Performs the same operation as :func:`torch.split_with_sizes`, but all output tensors
are freshly created instead of aliasing the input.
spmm(...)
sqrt(...)
sqrt(input, *, out=None) -> Tensor
Returns a new tensor with the square-root of the elements of :attr:`input`.
.. math::
\text{out}_{i} = \sqrt{\text{input}_{i}}
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-2.0755, 1.0226, 0.0831, 0.4806])
>>> torch.sqrt(a)
tensor([ nan, 1.0112, 0.2883, 0.6933])
sqrt_(...)
square(...)
square(input: Tensor, *, out: Optional[Tensor]) -> Tensor
Returns a new tensor with the square of the elements of :attr:`input`.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-2.0755, 1.0226, 0.0831, 0.4806])
>>> torch.square(a)
tensor([ 4.3077, 1.0457, 0.0069, 0.2310])
square_(...)
squeeze(...)
squeeze(input: Tensor, dim: Optional[Union[int, List[int]]]) -> Tensor
Returns a tensor with all specified dimensions of :attr:`input` of size `1` removed.
For example, if `input` is of shape:
:math:`(A \times 1 \times B \times C \times 1 \times D)` then the `input.squeeze()`
will be of shape: :math:`(A \times B \times C \times D)`.
When :attr:`dim` is given, a squeeze operation is done only in the given
dimension(s). If `input` is of shape: :math:`(A \times 1 \times B)`,
``squeeze(input, 0)`` leaves the tensor unchanged, but ``squeeze(input, 1)``
will squeeze the tensor to the shape :math:`(A \times B)`.
.. note:: The returned tensor shares the storage with the input tensor,
so changing the contents of one will change the contents of the other.
.. warning:: If the tensor has a batch dimension of size 1, then `squeeze(input)`
will also remove the batch dimension, which can lead to unexpected
errors. Consider specifying only the dims you wish to be squeezed.
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): if given, the input will be squeezed
only in the specified dimensions.
.. versionchanged:: 2.0
:attr:`dim` now accepts tuples of dimensions.
Example::
>>> x = torch.zeros(2, 1, 2, 1, 2)
>>> x.size()
torch.Size([2, 1, 2, 1, 2])
>>> y = torch.squeeze(x)
>>> y.size()
torch.Size([2, 2, 2])
>>> y = torch.squeeze(x, 0)
>>> y.size()
torch.Size([2, 1, 2, 1, 2])
>>> y = torch.squeeze(x, 1)
>>> y.size()
torch.Size([2, 2, 1, 2])
>>> y = torch.squeeze(x, (1, 2, 3))
torch.Size([2, 2, 2])
squeeze_copy(...)
Performs the same operation as :func:`torch.squeeze`, but all output tensors
are freshly created instead of aliasing the input.
sspaddmm(...)
sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) -> Tensor
Matrix multiplies a sparse tensor :attr:`mat1` with a dense tensor
:attr:`mat2`, then adds the sparse tensor :attr:`input` to the result.
Note: This function is equivalent to :func:`torch.addmm`, except
:attr:`input` and :attr:`mat1` are sparse.
Args:
input (Tensor): a sparse matrix to be added
mat1 (Tensor): a sparse matrix to be matrix multiplied
mat2 (Tensor): a dense matrix to be matrix multiplied
Keyword args:
beta (Number, optional): multiplier for :attr:`mat` (:math:`\beta`)
alpha (Number, optional): multiplier for :math:`mat1 @ mat2` (:math:`\alpha`)
out (Tensor, optional): the output tensor.
stack(...)
stack(tensors, dim=0, *, out=None) -> Tensor
Concatenates a sequence of tensors along a new dimension.
All tensors need to be of the same size.
.. seealso::
:func:`torch.cat` concatenates the given sequence along an existing dimension.
Arguments:
tensors (sequence of Tensors): sequence of tensors to concatenate
dim (int, optional): dimension to insert. Has to be between 0 and the number
of dimensions of concatenated tensors (inclusive). Default: 0
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> x = torch.randn(2, 3)
>>> x
tensor([[ 0.3367, 0.1288, 0.2345],
[ 0.2303, -1.1229, -0.1863]])
>>> torch.stack((x, x)) # same as torch.stack((x, x), dim=0)
tensor([[[ 0.3367, 0.1288, 0.2345],
[ 0.2303, -1.1229, -0.1863]],
[[ 0.3367, 0.1288, 0.2345],
[ 0.2303, -1.1229, -0.1863]]])
>>> torch.stack((x, x)).size()
torch.Size([2, 2, 3])
>>> torch.stack((x, x), dim=1)
tensor([[[ 0.3367, 0.1288, 0.2345],
[ 0.3367, 0.1288, 0.2345]],
[[ 0.2303, -1.1229, -0.1863],
[ 0.2303, -1.1229, -0.1863]]])
>>> torch.stack((x, x), dim=2)
tensor([[[ 0.3367, 0.3367],
[ 0.1288, 0.1288],
[ 0.2345, 0.2345]],
[[ 0.2303, 0.2303],
[-1.1229, -1.1229],
[-0.1863, -0.1863]]])
>>> torch.stack((x, x), dim=-1)
tensor([[[ 0.3367, 0.3367],
[ 0.1288, 0.1288],
[ 0.2345, 0.2345]],
[[ 0.2303, 0.2303],
[-1.1229, -1.1229],
[-0.1863, -0.1863]]])
std(...)
std(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
Calculates the standard deviation over the dimensions specified by :attr:`dim`.
:attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
reduce over all dimensions.
The standard deviation (:math:`\sigma`) is calculated as
.. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
sample mean, :math:`N` is the number of samples and :math:`\delta N` is
the :attr:`correction`.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
Keyword args:
correction (int): difference between the sample size and sample degrees of freedom.
Defaults to `Bessel's correction`_, ``correction=1``.
.. versionchanged:: 2.0
Previously this argument was called ``unbiased`` and was a boolean
with ``True`` corresponding to ``correction=1`` and ``False`` being
``correction=0``.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
out (Tensor, optional): the output tensor.
Example:
>>> a = torch.tensor(
... [[ 0.2035, 1.2959, 1.8101, -0.4644],
... [ 1.5027, -0.3270, 0.5905, 0.6538],
... [-1.5745, 1.3330, -0.5596, -0.6548],
... [ 0.1264, -0.5080, 1.6420, 0.1992]]
... ) # fmt: skip
>>> torch.std(a, dim=1, keepdim=True)
tensor([[1.0311],
[0.7477],
[1.2204],
[0.9087]])
.. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
std_mean(...)
std_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
Calculates the standard deviation and mean over the dimensions specified by
:attr:`dim`. :attr:`dim` can be a single dimension, list of dimensions, or
``None`` to reduce over all dimensions.
The standard deviation (:math:`\sigma`) is calculated as
.. math:: \sigma = \sqrt{\frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2}
where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
sample mean, :math:`N` is the number of samples and :math:`\delta N` is
the :attr:`correction`.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
Keyword args:
correction (int): difference between the sample size and sample degrees of freedom.
Defaults to `Bessel's correction`_, ``correction=1``.
.. versionchanged:: 2.0
Previously this argument was called ``unbiased`` and was a boolean
with ``True`` corresponding to ``correction=1`` and ``False`` being
``correction=0``.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
out (Tensor, optional): the output tensor.
Returns:
A tuple (std, mean) containing the standard deviation and mean.
Example:
>>> a = torch.tensor(
... [[ 0.2035, 1.2959, 1.8101, -0.4644],
... [ 1.5027, -0.3270, 0.5905, 0.6538],
... [-1.5745, 1.3330, -0.5596, -0.6548],
... [ 0.1264, -0.5080, 1.6420, 0.1992]]
... ) # fmt: skip
>>> torch.std_mean(a, dim=0, keepdim=True)
(tensor([[1.2620, 1.0028, 1.0957, 0.6038]]),
tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
.. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
stft(input: torch.Tensor, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: torch.Tensor | None = None, center: bool = True, pad_mode: str = 'reflect', normalized: bool = False, onesided: bool | None = None, return_complex: bool | None = None, align_to_window: bool | None = None) -> torch.Tensor
Short-time Fourier transform (STFT).
.. warning::
From version 1.8.0, :attr:`return_complex` must always be given
explicitly for real inputs and `return_complex=False` has been
deprecated. Strongly prefer `return_complex=True` as in a future
pytorch release, this function will only return complex tensors.
Note that :func:`torch.view_as_real` can be used to recover a real
tensor with an extra last dimension for real and imaginary components.
.. warning::
From version 2.1, a warning will be provided if a :attr:`window` is
not specified. In a future release, this attribute will be required.
Not providing a window currently defaults to using a rectangular window,
which may result in undesirable artifacts. Consider using tapered windows,
such as :func:`torch.hann_window`.
The STFT computes the Fourier transform of short overlapping windows of the
input. This giving frequency components of the signal as they change over
time. The interface of this function is modeled after (but *not* a drop-in
replacement for) librosa_ stft function.
.. _librosa: https://librosa.org/doc/latest/generated/librosa.stft.html
Ignoring the optional batch dimension, this method computes the following
expression:
.. math::
X[\omega, m] = \sum_{k = 0}^{\text{win\_length-1}}%
\text{window}[k]\ \text{input}[m \times \text{hop\_length} + k]\ %
\exp\left(- j \frac{2 \pi \cdot \omega k}{\text{n\_fft}}\right),
where :math:`m` is the index of the sliding window, and :math:`\omega` is
the frequency :math:`0 \leq \omega < \text{n\_fft}` for ``onesided=False``,
or :math:`0 \leq \omega < \lfloor \text{n\_fft} / 2 \rfloor + 1` for ``onesided=True``.
* :attr:`input` must be either a 1-D time sequence or a 2-D batch of time
sequences.
* If :attr:`hop_length` is ``None`` (default), it is treated as equal to
``floor(n_fft / 4)``.
* If :attr:`win_length` is ``None`` (default), it is treated as equal to
:attr:`n_fft`.
* :attr:`window` can be a 1-D tensor of size :attr:`win_length`, e.g., from
:meth:`torch.hann_window`. If :attr:`window` is ``None`` (default), it is
treated as if having :math:`1` everywhere in the window. If
:math:`\text{win\_length} < \text{n\_fft}`, :attr:`window` will be padded on
both sides to length :attr:`n_fft` before being applied.
* If :attr:`center` is ``True`` (default), :attr:`input` will be padded on
both sides so that the :math:`t`-th frame is centered at time
:math:`t \times \text{hop\_length}`. Otherwise, the :math:`t`-th frame
begins at time :math:`t \times \text{hop\_length}`.
* :attr:`pad_mode` determines the padding method used on :attr:`input` when
:attr:`center` is ``True``. See :meth:`torch.nn.functional.pad` for
all available options. Default is ``"reflect"``.
* If :attr:`onesided` is ``True`` (default for real input), only values for
:math:`\omega` in :math:`\left[0, 1, 2, \dots, \left\lfloor
\frac{\text{n\_fft}}{2} \right\rfloor + 1\right]` are returned because
the real-to-complex Fourier transform satisfies the conjugate symmetry,
i.e., :math:`X[m, \omega] = X[m, \text{n\_fft} - \omega]^*`.
Note if the input or window tensors are complex, then :attr:`onesided`
output is not possible.
* If :attr:`normalized` is ``True`` (default is ``False``), the function
returns the normalized STFT results, i.e., multiplied by :math:`(\text{frame\_length})^{-0.5}`.
* If :attr:`return_complex` is ``True`` (default if input is complex), the
return is a ``input.dim() + 1`` dimensional complex tensor. If ``False``,
the output is a ``input.dim() + 2`` dimensional real tensor where the last
dimension represents the real and imaginary components.
Returns either a complex tensor of size :math:`(* \times N \times T)` if
:attr:`return_complex` is true, or a real tensor of size :math:`(* \times N
\times T \times 2)`. Where :math:`*` is the optional batch size of
:attr:`input`, :math:`N` is the number of frequencies where STFT is applied
and :math:`T` is the total number of frames used.
.. warning::
This function changed signature at version 0.4.1. Calling with the
previous signature may cause error or return incorrect result.
Args:
input (Tensor): the input tensor of shape `(B?, L)` where `B?` is an optional
batch dimension
n_fft (int): size of Fourier transform
hop_length (int, optional): the distance between neighboring sliding window
frames. Default: ``None`` (treated as equal to ``floor(n_fft / 4)``)
win_length (int, optional): the size of window frame and STFT filter.
Default: ``None`` (treated as equal to :attr:`n_fft`)
window (Tensor, optional): the optional window function.
Shape must be 1d and `<= n_fft`
Default: ``None`` (treated as window of all :math:`1` s)
center (bool, optional): whether to pad :attr:`input` on both sides so
that the :math:`t`-th frame is centered at time :math:`t \times \text{hop\_length}`.
Default: ``True``
pad_mode (str, optional): controls the padding method used when
:attr:`center` is ``True``. Default: ``"reflect"``
normalized (bool, optional): controls whether to return the normalized STFT results
Default: ``False``
onesided (bool, optional): controls whether to return half of results to
avoid redundancy for real inputs.
Default: ``True`` for real :attr:`input` and :attr:`window`, ``False`` otherwise.
return_complex (bool, optional): whether to return a complex tensor, or
a real tensor with an extra last dimension for the real and
imaginary components.
.. versionchanged:: 2.0
``return_complex`` is now a required argument for real inputs,
as the default is being transitioned to ``True``.
.. deprecated:: 2.0
``return_complex=False`` is deprecated, instead use ``return_complex=True``
Note that calling :func:`torch.view_as_real` on the output will
recover the deprecated output format.
Returns:
Tensor: A tensor containing the STFT result with shape `(B?, N, T, C?)` where
- `B?` is an optional batch dimension from the input.
- `N` is the number of frequency samples, `(n_fft // 2) + 1` for
`onesided=True`, or otherwise `n_fft`.
- `T` is the number of frames, `1 + L // hop_length`
for `center=True`, or `1 + (L - n_fft) // hop_length` otherwise.
- `C?` is an optional length-2 dimension of real and imaginary
components, present when `return_complex=False`.
sub(...)
sub(input, other, *, alpha=1, out=None) -> Tensor
Subtracts :attr:`other`, scaled by :attr:`alpha`, from :attr:`input`.
.. math::
\text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i
Supports :ref:`broadcasting to a common shape <broadcasting-semantics>`,
:ref:`type promotion <type-promotion-doc>`, and integer, float, and complex inputs.
Args:
input (Tensor): the input tensor.
other (Tensor or Number): the tensor or number to subtract from :attr:`input`.
Keyword args:
alpha (Number): the multiplier for :attr:`other`.
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor((1, 2))
>>> b = torch.tensor((0, 1))
>>> torch.sub(a, b, alpha=2)
tensor([1, 0])
subtract(...)
subtract(input, other, *, alpha=1, out=None) -> Tensor
Alias for :func:`torch.sub`.
sum(...)
sum(input, *, dtype=None) -> Tensor
Returns the sum of all elements in the :attr:`input` tensor.
Args:
input (Tensor): the input tensor.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
.. note:: Use the `dtype` argument if you need the result in a specific tensor type.
Otherwise, the result type may be automatically promoted (e.g., from `torch.int32` to `torch.int64`).
Example::
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.1133, -0.9567, 0.2958]])
>>> torch.sum(a)
tensor(-0.5475)
.. function:: sum(input, dim, keepdim=False, *, dtype=None) -> Tensor
:noindex:
Returns the sum of each row of the :attr:`input` tensor in the given
dimension :attr:`dim`. If :attr:`dim` is a list of dimensions,
reduce over all of them.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
If specified, the input tensor is casted to :attr:`dtype` before the operation
is performed. This is useful for preventing data type overflows. Default: None.
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.0569, -0.2475, 0.0737, -0.3429],
[-0.2993, 0.9138, 0.9337, -1.6864],
[ 0.1132, 0.7892, -0.1003, 0.5688],
[ 0.3637, -0.9906, -0.4752, -1.5197]])
>>> torch.sum(a, 1)
tensor([-0.4598, -0.1381, 1.3708, -2.6217])
>>> b = torch.arange(4 * 5 * 6).view(4, 5, 6)
>>> torch.sum(b, (2, 1))
tensor([ 435., 1335., 2235., 3135.])
svd(...)
svd(input, some=True, compute_uv=True, *, out=None) -> (Tensor, Tensor, Tensor)
Computes the singular value decomposition of either a matrix or batch of
matrices :attr:`input`. The singular value decomposition is represented as a
namedtuple `(U, S, V)`, such that :attr:`input` :math:`= U \text{diag}(S) V^{\text{H}}`.
where :math:`V^{\text{H}}` is the transpose of `V` for real inputs,
and the conjugate transpose of `V` for complex inputs.
If :attr:`input` is a batch of matrices, then `U`, `S`, and `V` are also
batched with the same batch dimensions as :attr:`input`.
If :attr:`some` is `True` (default), the method returns the reduced singular
value decomposition. In this case, if the last two dimensions of :attr:`input` are
`m` and `n`, then the returned `U` and `V` matrices will contain only
`min(n, m)` orthonormal columns.
If :attr:`compute_uv` is `False`, the returned `U` and `V` will be
zero-filled matrices of shape `(m, m)` and `(n, n)`
respectively, and the same device as :attr:`input`. The argument :attr:`some`
has no effect when :attr:`compute_uv` is `False`.
Supports :attr:`input` of float, double, cfloat and cdouble data types.
The dtypes of `U` and `V` are the same as :attr:`input`'s. `S` will
always be real-valued, even if :attr:`input` is complex.
.. warning::
:func:`torch.svd` is deprecated in favor of :func:`torch.linalg.svd`
and will be removed in a future PyTorch release.
``U, S, V = torch.svd(A, some=some, compute_uv=True)`` (default) should be replaced with
.. code:: python
U, S, Vh = torch.linalg.svd(A, full_matrices=not some)
V = Vh.mH
``_, S, _ = torch.svd(A, some=some, compute_uv=False)`` should be replaced with
.. code:: python
S = torch.linalg.svdvals(A)
.. note:: Differences with :func:`torch.linalg.svd`:
* :attr:`some` is the opposite of
:func:`torch.linalg.svd`'s :attr:`full_matrices`. Note that
default value for both is `True`, so the default behavior is
effectively the opposite.
* :func:`torch.svd` returns `V`, whereas :func:`torch.linalg.svd` returns
`Vh`, that is, :math:`V^{\text{H}}`.
* If :attr:`compute_uv` is `False`, :func:`torch.svd` returns zero-filled
tensors for `U` and `Vh`, whereas :func:`torch.linalg.svd` returns
empty tensors.
.. note:: The singular values are returned in descending order. If :attr:`input` is a batch of matrices,
then the singular values of each matrix in the batch are returned in descending order.
.. note:: The `S` tensor can only be used to compute gradients if :attr:`compute_uv` is `True`.
.. note:: When :attr:`some` is `False`, the gradients on `U[..., :, min(m, n):]`
and `V[..., :, min(m, n):]` will be ignored in the backward pass, as those vectors
can be arbitrary bases of the corresponding subspaces.
.. note:: The implementation of :func:`torch.linalg.svd` on CPU uses LAPACK's routine `?gesdd`
(a divide-and-conquer algorithm) instead of `?gesvd` for speed. Analogously,
on GPU, it uses cuSOLVER's routines `gesvdj` and `gesvdjBatched`.
.. note:: The returned `U` will not be contiguous. The matrix (or batch of matrices) will
be represented as a column-major matrix (i.e. Fortran-contiguous).
.. warning:: The gradients with respect to `U` and `V` will only be finite when the input does not
have zero nor repeated singular values.
.. warning:: If the distance between any two singular values is close to zero, the gradients with respect to
`U` and `V` will be numerically unstable, as they depends on
:math:`\frac{1}{\min_{i \neq j} \sigma_i^2 - \sigma_j^2}`. The same happens when the matrix
has small singular values, as these gradients also depend on `S^{-1}`.
.. warning:: For complex-valued :attr:`input` the singular value decomposition is not unique,
as `U` and `V` may be multiplied by an arbitrary phase factor :math:`e^{i \phi}` on every column.
The same happens when :attr:`input` has repeated singular values, where one may multiply
the columns of the spanning subspace in `U` and `V` by a rotation matrix
and `the resulting vectors will span the same subspace`_.
Different platforms, like NumPy, or inputs on different device types,
may produce different `U` and `V` tensors.
Args:
input (Tensor): the input tensor of size `(*, m, n)` where `*` is zero or more
batch dimensions consisting of `(m, n)` matrices.
some (bool, optional): controls whether to compute the reduced or full decomposition, and
consequently, the shape of returned `U` and `V`. Default: `True`.
compute_uv (bool, optional): controls whether to compute `U` and `V`. Default: `True`.
Keyword args:
out (tuple, optional): the output tuple of tensors
Example::
>>> a = torch.randn(5, 3)
>>> a
tensor([[ 0.2364, -0.7752, 0.6372],
[ 1.7201, 0.7394, -0.0504],
[-0.3371, -1.0584, 0.5296],
[ 0.3550, -0.4022, 1.5569],
[ 0.2445, -0.0158, 1.1414]])
>>> u, s, v = torch.svd(a)
>>> u
tensor([[ 0.4027, 0.0287, 0.5434],
[-0.1946, 0.8833, 0.3679],
[ 0.4296, -0.2890, 0.5261],
[ 0.6604, 0.2717, -0.2618],
[ 0.4234, 0.2481, -0.4733]])
>>> s
tensor([2.3289, 2.0315, 0.7806])
>>> v
tensor([[-0.0199, 0.8766, 0.4809],
[-0.5080, 0.4054, -0.7600],
[ 0.8611, 0.2594, -0.4373]])
>>> torch.dist(a, torch.mm(torch.mm(u, torch.diag(s)), v.t()))
tensor(8.6531e-07)
>>> a_big = torch.randn(7, 5, 3)
>>> u, s, v = torch.svd(a_big)
>>> torch.dist(a_big, torch.matmul(torch.matmul(u, torch.diag_embed(s)), v.mT))
tensor(2.6503e-06)
.. _the resulting vectors will span the same subspace:
(https://en.wikipedia.org/wiki/Singular_value_decomposition#Singular_values,_singular_vectors,_and_their_relation_to_the_SVD)
swapaxes(...)
swapaxes(input, axis0, axis1) -> Tensor
Alias for :func:`torch.transpose`.
This function is equivalent to NumPy's swapaxes function.
Examples::
>>> x = torch.tensor([[[0,1],[2,3]],[[4,5],[6,7]]])
>>> x
tensor([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
>>> torch.swapaxes(x, 0, 1)
tensor([[[0, 1],
[4, 5]],
[[2, 3],
[6, 7]]])
>>> torch.swapaxes(x, 0, 2)
tensor([[[0, 4],
[2, 6]],
[[1, 5],
[3, 7]]])
swapdims(...)
swapdims(input, dim0, dim1) -> Tensor
Alias for :func:`torch.transpose`.
This function is equivalent to NumPy's swapaxes function.
Examples::
>>> x = torch.tensor([[[0,1],[2,3]],[[4,5],[6,7]]])
>>> x
tensor([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
>>> torch.swapdims(x, 0, 1)
tensor([[[0, 1],
[4, 5]],
[[2, 3],
[6, 7]]])
>>> torch.swapdims(x, 0, 2)
tensor([[[0, 4],
[2, 6]],
[[1, 5],
[3, 7]]])
sym_constrain_range(...)
sym_constrain_range_for_size(...)
sym_float(a)
SymInt-aware utility for float casting.
Args:
a (SymInt, SymFloat, or object): Object to cast
sym_fresh_size(expr)
# Create a fresh unbacked int, from an (possibly unbacked int) expression.
sym_int(a)
SymInt-aware utility for int casting.
Args:
a (SymInt, SymFloat, or object): Object to cast
sym_ite(b, t, f)
SymInt-aware utility for ternary operator (``t if b else f``.)
sym_max(a, b)
SymInt-aware utility for max which avoids branching on a < b.
Unlike builtins.max(), this only works for int/float, and it always
promotes to float if any argument is float (unlike builtins.max, which
will faithfully preserve the type of the input argument).
sym_min(a, b)
SymInt-aware utility for min().
sym_not(a)
SymInt-aware utility for logical negation.
Args:
a (SymBool or bool): Object to negate
sym_sqrt = _sym_sqrt(a)
sym_sum(*args)
N-ary add which is faster to compute for long lists than iterated binary
addition. Only does something special for integers.
Accepts both ``sym_sum([a, b, c])`` and ``sym_sum(a, b, c)``.
t(...)
t(input) -> Tensor
Expects :attr:`input` to be <= 2-D tensor and transposes dimensions 0
and 1.
0-D and 1-D tensors are returned as is. When input is a 2-D tensor this
is equivalent to ``transpose(input, 0, 1)``.
Args:
input (Tensor): the input tensor.
Example::
>>> x = torch.randn(())
>>> x
tensor(0.1995)
>>> torch.t(x)
tensor(0.1995)
>>> x = torch.randn(3)
>>> x
tensor([ 2.4320, -0.4608, 0.7702])
>>> torch.t(x)
tensor([ 2.4320, -0.4608, 0.7702])
>>> x = torch.randn(2, 3)
>>> x
tensor([[ 0.4875, 0.9158, -0.5872],
[ 0.3938, -0.6929, 0.6932]])
>>> torch.t(x)
tensor([[ 0.4875, 0.3938],
[ 0.9158, -0.6929],
[-0.5872, 0.6932]])
See also :func:`torch.transpose`.
t_copy(...)
Performs the same operation as :func:`torch.t`, but all output tensors
are freshly created instead of aliasing the input.
take(...)
take(input, index) -> Tensor
Returns a new tensor with the elements of :attr:`input` at the given indices.
The input tensor is treated as if it were viewed as a 1-D tensor. The result
takes the same shape as the indices.
Args:
input (Tensor): the input tensor.
index (LongTensor): the indices into tensor
Example::
>>> src = torch.tensor([[4, 3, 5],
... [6, 7, 8]])
>>> torch.take(src, torch.tensor([0, 2, 5]))
tensor([ 4, 5, 8])
take_along_dim(...)
take_along_dim(input, indices, dim=None, *, out=None) -> Tensor
Selects values from :attr:`input` at the 1-dimensional indices from :attr:`indices` along the given :attr:`dim`.
If :attr:`dim` is None, the input array is treated as if it has been flattened to 1d.
Functions that return indices along a dimension, like :func:`torch.argmax` and :func:`torch.argsort`,
are designed to work with this function. See the examples below.
.. note::
This function is similar to NumPy's `take_along_axis`.
See also :func:`torch.gather`.
Args:
input (Tensor): the input tensor.
indices (LongTensor): the indices into :attr:`input`. Must have long dtype.
dim (int, optional): dimension to select along. Default: `None`.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> t = torch.tensor([[10, 30, 20], [60, 40, 50]])
>>> max_idx = torch.argmax(t)
>>> torch.take_along_dim(t, max_idx)
tensor([60])
>>> sorted_idx = torch.argsort(t, dim=1)
>>> torch.take_along_dim(t, sorted_idx, dim=1)
tensor([[10, 20, 30],
[40, 50, 60]])
tan(...)
tan(input, *, out=None) -> Tensor
Returns a new tensor with the tangent of the elements in the :attr:`input` tensor,
where each value in this input tensor is in radians.
.. math::
\text{out}_{i} = \tan(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([-1.2027, -1.7687, 0.4412, -1.3856])
>>> torch.tan(a)
tensor([-2.5930, 4.9859, 0.4722, -5.3366])
tan_(...)
tanh(...)
tanh(input, *, out=None) -> Tensor
Returns a new tensor with the hyperbolic tangent of the elements
of :attr:`input`.
.. math::
\text{out}_{i} = \tanh(\text{input}_{i})
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 0.8986, -0.7279, 1.1745, 0.2611])
>>> torch.tanh(a)
tensor([ 0.7156, -0.6218, 0.8257, 0.2553])
tanh_(...)
tensor(...)
tensor(data, *, dtype=None, device=None, requires_grad=False, pin_memory=False) -> Tensor
Constructs a tensor with no autograd history (also known as a "leaf tensor", see :doc:`/notes/autograd`) by copying :attr:`data`.
.. warning::
When working with tensors prefer using :func:`torch.Tensor.clone`,
:func:`torch.Tensor.detach`, and :func:`torch.Tensor.requires_grad_` for
readability. Letting `t` be a tensor, ``torch.tensor(t)`` is equivalent to
``t.detach().clone()``, and ``torch.tensor(t, requires_grad=True)``
is equivalent to ``t.detach().clone().requires_grad_(True)``.
.. seealso::
:func:`torch.as_tensor` preserves autograd history and avoids copies where possible.
:func:`torch.from_numpy` creates a tensor that shares storage with a NumPy array.
Args:
data (array_like): Initial data for the tensor. Can be a list, tuple,
NumPy ``ndarray``, scalar, and other types.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, infers data type from :attr:`data`.
device (:class:`torch.device`, optional): the device of the constructed tensor. If None and data is a tensor
then the device of data is used. If None and data is not a tensor then
the result tensor is constructed on the current device.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
pin_memory (bool, optional): If set, returned tensor would be allocated in
the pinned memory. Works only for CPU tensors. Default: ``False``.
Example::
>>> torch.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])
tensor([[ 0.1000, 1.2000],
[ 2.2000, 3.1000],
[ 4.9000, 5.2000]])
>>> torch.tensor([0, 1]) # Type inference on data
tensor([ 0, 1])
>>> torch.tensor([[0.11111, 0.222222, 0.3333333]],
... dtype=torch.float64,
... device=torch.device('cuda:0')) # creates a double tensor on a CUDA device
tensor([[ 0.1111, 0.2222, 0.3333]], dtype=torch.float64, device='cuda:0')
>>> torch.tensor(3.14159) # Create a zero-dimensional (scalar) tensor
tensor(3.1416)
>>> torch.tensor([]) # Create an empty tensor (of size (0,))
tensor([])
tensor_split(...)
tensor_split(input, indices_or_sections, dim=0) -> List of Tensors
Splits a tensor into multiple sub-tensors, all of which are views of :attr:`input`,
along dimension :attr:`dim` according to the indices or number of sections specified
by :attr:`indices_or_sections`. This function is based on NumPy's
:func:`numpy.array_split`.
.. function:: tensor_split(input, sections, dim=0) -> List of Tensors
:noindex:
Splits :attr:`input` into :attr:`sections` sections along dimension :attr:`dim`.
If :attr:`input` is divisible by :attr:`sections` along dimension :attr:`dim`, each
section will be of equal size, :code:`input.size(dim) / sections`. If :attr:`input`
is not divisible by :attr:`sections`, the sizes of the first
:code:`int(input.size(dim) % sections)` sections will have size
:code:`int(input.size(dim) / sections) + 1`, and the rest will have size
:code:`int(input.size(dim) / sections)`.
:attr:`sections` can also be a zero-dimensional long tensor.
.. function:: tensor_split(input, indices, dim=0) -> List of Tensors
:noindex:
Splits :attr:`input` along dimension :attr:`dim` at each of the indices in
:attr:`indices`. For instance, :code:`indices=[2, 3]` and :code:`dim=0`
would result in the tensors :code:`input[:2]`, :code:`input[2:3]`, and
:code:`input[3:]`.
:attr:`indices` can be a list or tuple of ints, or a one-dimensional long
tensor on the CPU.
Args:
input (Tensor): the tensor to split
dim (int, optional): dimension along which to split the tensor. Default: ``0``
Example::
>>> x = torch.arange(8)
>>> torch.tensor_split(x, 3)
(tensor([0, 1, 2]), tensor([3, 4, 5]), tensor([6, 7]))
>>> x = torch.arange(7)
>>> torch.tensor_split(x, 3)
(tensor([0, 1, 2]), tensor([3, 4]), tensor([5, 6]))
>>> torch.tensor_split(x, (1, 6))
(tensor([0]), tensor([1, 2, 3, 4, 5]), tensor([6]))
>>> x = torch.arange(14).reshape(2, 7)
>>> x
tensor([[ 0, 1, 2, 3, 4, 5, 6],
[ 7, 8, 9, 10, 11, 12, 13]])
>>> torch.tensor_split(x, 3, dim=1)
(tensor([[0, 1, 2],
[7, 8, 9]]),
tensor([[ 3, 4],
[10, 11]]),
tensor([[ 5, 6],
[12, 13]]))
>>> torch.tensor_split(x, (1, 6), dim=1)
(tensor([[0],
[7]]),
tensor([[ 1, 2, 3, 4, 5],
[ 8, 9, 10, 11, 12]]),
tensor([[ 6],
[13]]))
tensordot(a, b, dims=2, out: torch.Tensor | None = None)
Returns a contraction of a and b over multiple dimensions.
:attr:`tensordot` implements a generalized matrix product.
Args:
a (Tensor): Left tensor to contract
b (Tensor): Right tensor to contract
dims (int or Tuple[List[int], List[int]] or List[List[int]] containing two lists or Tensor): number of dimensions to
contract or explicit lists of dimensions for :attr:`a` and
:attr:`b` respectively
When called with a non-negative integer argument :attr:`dims` = :math:`d`, and
the number of dimensions of :attr:`a` and :attr:`b` is :math:`m` and :math:`n`,
respectively, :func:`~torch.tensordot` computes the tensor :math:`r` of shape
``a.shape[:-dims] + b.shape[dims:]`` given by:
.. math::
r_{i_1,...,i_{m-d}, j_1,...,j_{n-d}}
= \sum_{k_1,...,k_d} a_{i_1,...,i_{m-d},k_1,...,k_d} \times b_{k_1,...,k_d, j_1,...,j_{n-d}}.
When called with :attr:`dims` of the list form, the given dimensions will be contracted
in place of the last :math:`d` of :attr:`a` and the first :math:`d` of :math:`b`. The sizes
in these dimensions must match, but :func:`~torch.tensordot` will deal with broadcasted
dimensions.
Examples::
>>> a = torch.arange(60.).reshape(3, 4, 5)
>>> b = torch.arange(24.).reshape(4, 3, 2)
>>> torch.tensordot(a, b, dims=([1, 0], [0, 1]))
tensor([[4400., 4730.],
[4532., 4874.],
[4664., 5018.],
[4796., 5162.],
[4928., 5306.]])
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
>>> a = torch.randn(3, 4, 5, device='cuda')
>>> b = torch.randn(4, 5, 6, device='cuda')
>>> c = torch.tensordot(a, b, dims=2).cpu()
tensor([[ 8.3504, -2.5436, 6.2922, 2.7556, -1.0732, 3.2741],
[ 3.3161, 0.0704, 5.0187, -0.4079, -4.3126, 4.8744],
[ 0.8223, 3.9445, 3.2168, -0.2400, 3.4117, 1.7780]])
>>> a = torch.randn(3, 5, 4, 6)
>>> b = torch.randn(6, 4, 5, 3)
>>> torch.tensordot(a, b, dims=([2, 1, 3], [1, 2, 0]))
tensor([[ 7.7193, -2.4867, -10.3204],
[ 1.5513, -14.4737, -6.5113],
[ -0.2850, 4.2573, -3.5997]])
thread_safe_generator() -> torch._C.Generator | None
Returns a thread-safe random number generator for use in DataLoader workers.
This function provides a convenient way for transforms and user code to use
thread-safe random number generation without manually checking worker context.
When called in a DataLoader thread worker, returns the worker's thread-local
:class:`torch.Generator`. When called in the main process or process workers,
returns ``None`` (which causes PyTorch functions to use the default global RNG).
Returns:
Optional[torch.Generator]: Thread-local generator in thread workers, None otherwise.
Example::
>>> from torch.random import thread_safe_generator
>>> generator = thread_safe_generator()
>>> torch.randint(0, 10, (5,), generator=generator)
Example with transforms::
>>> from torch.random import thread_safe_generator
>>> class MyRandomTransform:
... def __call__(self, img):
... generator = thread_safe_generator()
... offset = torch.randint(0, 10, (2,), generator=generator)
... return img[..., offset[0]:, offset[1]:]
threshold(...)
threshold_(...)
threshold_(input, threshold, value) -> Tensor
In-place version of :func:`~threshold`.
tile(...)
tile(input, dims) -> Tensor
Constructs a tensor by repeating the elements of :attr:`input`.
The :attr:`dims` argument specifies the number of repetitions
in each dimension.
If :attr:`dims` specifies fewer dimensions than :attr:`input` has, then
ones are prepended to :attr:`dims` until all dimensions are specified.
For example, if :attr:`input` has shape (8, 6, 4, 2) and :attr:`dims`
is (2, 2), then :attr:`dims` is treated as (1, 1, 2, 2).
Analogously, if :attr:`input` has fewer dimensions than :attr:`dims`
specifies, then :attr:`input` is treated as if it were unsqueezed at
dimension zero until it has as many dimensions as :attr:`dims` specifies.
For example, if :attr:`input` has shape (4, 2) and :attr:`dims`
is (3, 3, 2, 2), then :attr:`input` is treated as if it had the
shape (1, 1, 4, 2).
.. note::
This function is similar to NumPy's tile function.
Args:
input (Tensor): the tensor whose elements to repeat.
dims (tuple): the number of repetitions per dimension.
Example::
>>> x = torch.tensor([1, 2, 3])
>>> x.tile((2,))
tensor([1, 2, 3, 1, 2, 3])
>>> y = torch.tensor([[1, 2], [3, 4]])
>>> torch.tile(y, (2, 2))
tensor([[1, 2, 1, 2],
[3, 4, 3, 4],
[1, 2, 1, 2],
[3, 4, 3, 4]])
topk(...)
topk(input, k, dim=None, largest=True, sorted=True, *, out=None) -> (Tensor, LongTensor)
Returns the :attr:`k` largest elements of the given :attr:`input` tensor along
a given dimension.
If :attr:`dim` is not given, the last dimension of the `input` is chosen.
If :attr:`largest` is ``False`` then the `k` smallest elements are returned.
A namedtuple of `(values, indices)` is returned with the `values` and
`indices` of the largest `k` elements of each row of the `input` tensor in the
given dimension `dim`.
The boolean option :attr:`sorted` if ``True``, will make sure that the returned
`k` elements are themselves sorted
.. note::
When using `torch.topk`, the indices of tied elements are not guaranteed to be stable
and may vary across different invocations.
Args:
input (Tensor): the input tensor.
k (int): the k in "top-k"
dim (int, optional): the dimension to sort along
largest (bool, optional): controls whether to return largest or
smallest elements
sorted (bool, optional): controls whether to return the elements
in sorted order
Keyword args:
out (tuple, optional): the output tuple of (Tensor, LongTensor) that can be
optionally given to be used as output buffers
Example::
>>> x = torch.arange(1., 6.)
>>> x
tensor([ 1., 2., 3., 4., 5.])
>>> torch.topk(x, 3)
torch.return_types.topk(values=tensor([5., 4., 3.]), indices=tensor([4, 3, 2]))
trace(...)
trace(input) -> Tensor
Returns the sum of the elements of the diagonal of the input 2-D matrix.
Example::
>>> x = torch.arange(1., 10.).view(3, 3)
>>> x
tensor([[ 1., 2., 3.],
[ 4., 5., 6.],
[ 7., 8., 9.]])
>>> torch.trace(x)
tensor(15.)
transpose(...)
transpose(input, dim0, dim1) -> Tensor
Returns a tensor that is a transposed version of :attr:`input`.
The given dimensions :attr:`dim0` and :attr:`dim1` are swapped.
If :attr:`input` is a strided tensor then the resulting :attr:`out`
tensor shares its underlying storage with the :attr:`input` tensor, so
changing the content of one would change the content of the other.
If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` then the
resulting :attr:`out` tensor *does not* share the underlying storage
with the :attr:`input` tensor.
If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` with compressed
layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments
:attr:`dim0` and :attr:`dim1` must be both batch dimensions, or must
both be sparse dimensions. The batch dimensions of a sparse tensor are the
dimensions preceding the sparse dimensions.
.. note::
Transpositions which interchange the sparse dimensions of a `SparseCSR`
or `SparseCSC` layout tensor will result in the layout changing between
the two options. Transposition of the sparse dimensions of a ` SparseBSR`
or `SparseBSC` layout tensor will likewise generate a result with the
opposite layout.
Args:
input (Tensor): the input tensor.
dim0 (int): the first dimension to be transposed
dim1 (int): the second dimension to be transposed
Example::
>>> x = torch.randn(2, 3)
>>> x
tensor([[ 1.0028, -0.9893, 0.5809],
[-0.1669, 0.7299, 0.4942]])
>>> torch.transpose(x, 0, 1)
tensor([[ 1.0028, -0.1669],
[-0.9893, 0.7299],
[ 0.5809, 0.4942]])
See also :func:`torch.t`.
transpose_copy(...)
Performs the same operation as :func:`torch.transpose`, but all output tensors
are freshly created instead of aliasing the input.
trapezoid(...)
trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
Computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_ along
:attr:`dim`. By default the spacing between elements is assumed to be 1, but
:attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
used to specify arbitrary spacing along :attr:`dim`. Only one of :attr:`x` or :attr:`dx` should be specified.
Assuming :attr:`y` is a one-dimensional tensor with elements :math:`{y_0, y_1, ..., y_n}`,
the default computation is
.. math::
\begin{aligned}
\sum_{i = 1}^{n} \frac{1}{2} (y_i + y_{i-1})
\end{aligned}
When :attr:`dx` is specified the computation becomes
.. math::
\begin{aligned}
\sum_{i = 1}^{n} \frac{\Delta x}{2} (y_i + y_{i-1})
\end{aligned}
effectively multiplying the result by :attr:`dx`. When :attr:`x` is specified,
assuming :attr:`x` is also a one-dimensional tensor with
elements :math:`{x_0, x_1, ..., x_n}`, the computation becomes
.. math::
\begin{aligned}
\sum_{i = 1}^{n} \frac{(x_i - x_{i-1})}{2} (y_i + y_{i-1})
\end{aligned}
When :attr:`x` and :attr:`y` have the same size, the computation is as described above and no broadcasting is needed.
The broadcasting behavior of this function is as follows when their sizes are different. For both :attr:`x`
and :attr:`y`, the function computes the difference between consecutive elements along
dimension :attr:`dim`. This effectively creates two tensors, `x_diff` and `y_diff`, that have
the same shape as the original tensors except their lengths along the dimension :attr:`dim` is reduced by 1.
After that, those two tensors are broadcast together to compute final output as part of the trapezoidal rule.
See the examples below for details.
.. note::
The trapezoidal rule is a technique for approximating the definite integral of a function
by averaging its left and right Riemann sums. The approximation becomes more accurate as
the resolution of the partition increases.
Arguments:
y (Tensor): Values to use when computing the trapezoidal rule.
x (Tensor): If specified, defines spacing between values as specified above.
Keyword arguments:
dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
are specified then this defaults to 1. Effectively multiplies the result by its value.
dim (int): The dimension along which to compute the trapezoidal rule.
The last (inner-most) dimension by default.
Examples::
>>> # Computes the trapezoidal rule in 1D, spacing is implicitly 1
>>> y = torch.tensor([1, 5, 10])
>>> torch.trapezoid(y)
tensor(10.5)
>>> # Computes the same trapezoidal rule directly to verify
>>> (1 + 10 + 10) / 2
10.5
>>> # Computes the trapezoidal rule in 1D with constant spacing of 2
>>> # NOTE: the result is the same as before, but multiplied by 2
>>> torch.trapezoid(y, dx=2)
21.0
>>> # Computes the trapezoidal rule in 1D with arbitrary spacing
>>> x = torch.tensor([1, 3, 6])
>>> torch.trapezoid(y, x)
28.5
>>> # Computes the same trapezoidal rule directly to verify
>>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
28.5
>>> # Computes the trapezoidal rule for each row of a 3x3 matrix
>>> y = torch.arange(9).reshape(3, 3)
tensor([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> torch.trapezoid(y)
tensor([ 2., 8., 14.])
>>> # Computes the trapezoidal rule for each column of the matrix
>>> torch.trapezoid(y, dim=0)
tensor([ 6., 8., 10.])
>>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
>>> # with the same arbitrary spacing
>>> y = torch.ones(3, 3)
>>> x = torch.tensor([1, 3, 6])
>>> torch.trapezoid(y, x)
array([5., 5., 5.])
>>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
>>> # with different arbitrary spacing per row
>>> y = torch.ones(3, 3)
>>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
>>> torch.trapezoid(y, x)
array([2., 4., 6.])
trapz(...)
trapz(y, x=None, *, dim=-1) -> Tensor
Alias for :func:`torch.trapezoid`.
triangular_solve(...)
triangular_solve(b, A, upper=True, transpose=False, unitriangular=False, *, out=None) -> (Tensor, Tensor)
Solves a system of equations with a square upper or lower triangular invertible matrix :math:`A`
and multiple right-hand sides :math:`b`.
In symbols, it solves :math:`AX = b` and assumes :math:`A` is square upper-triangular
(or lower-triangular if :attr:`upper`\ `= False`) and does not have zeros on the diagonal.
`torch.triangular_solve(b, A)` can take in 2D inputs `b, A` or inputs that are
batches of 2D matrices. If the inputs are batches, then returns
batched outputs `X`
If the diagonal of :attr:`A` contains zeros or elements that are very close to zero and
:attr:`unitriangular`\ `= False` (default) or if the input matrix is badly conditioned,
the result may contain `NaN` s.
Supports input of float, double, cfloat and cdouble data types.
.. warning::
:func:`torch.triangular_solve` is deprecated in favor of :func:`torch.linalg.solve_triangular`
and will be removed in a future PyTorch release.
:func:`torch.linalg.solve_triangular` has its arguments reversed and does not return a
copy of one of the inputs.
``X = torch.triangular_solve(B, A).solution`` should be replaced with
.. code:: python
X = torch.linalg.solve_triangular(A, B)
Args:
b (Tensor): multiple right-hand sides of size :math:`(*, m, k)` where
:math:`*` is zero of more batch dimensions
A (Tensor): the input triangular coefficient matrix of size :math:`(*, m, m)`
where :math:`*` is zero or more batch dimensions
upper (bool, optional): whether :math:`A` is upper or lower triangular. Default: ``True``.
transpose (bool, optional): solves `op(A)X = b` where `op(A) = A^T` if this flag is ``True``,
and `op(A) = A` if it is ``False``. Default: ``False``.
unitriangular (bool, optional): whether :math:`A` is unit triangular.
If True, the diagonal elements of :math:`A` are assumed to be
1 and not referenced from :math:`A`. Default: ``False``.
Keyword args:
out ((Tensor, Tensor), optional): tuple of two tensors to write
the output to. Ignored if `None`. Default: `None`.
Returns:
A namedtuple `(solution, cloned_coefficient)` where `cloned_coefficient`
is a clone of :math:`A` and `solution` is the solution :math:`X` to :math:`AX = b`
(or whatever variant of the system of equations, depending on the keyword arguments.)
Examples::
>>> A = torch.randn(2, 2).triu()
>>> A
tensor([[ 1.1527, -1.0753],
[ 0.0000, 0.7986]])
>>> b = torch.randn(2, 3)
>>> b
tensor([[-0.0210, 2.3513, -1.5492],
[ 1.5429, 0.7403, -1.0243]])
>>> torch.triangular_solve(b, A)
torch.return_types.triangular_solve(
solution=tensor([[ 1.7841, 2.9046, -2.5405],
[ 1.9320, 0.9270, -1.2826]]),
cloned_coefficient=tensor([[ 1.1527, -1.0753],
[ 0.0000, 0.7986]]))
tril(...)
tril(input, diagonal=0, *, out=None) -> Tensor
Returns the lower triangular part of the matrix (2-D tensor) or batch of matrices
:attr:`input`, the other elements of the result tensor :attr:`out` are set to 0.
The lower triangular part of the matrix is defined as the elements on and
below the diagonal.
The argument :attr:`diagonal` controls which diagonal to consider. If
:attr:`diagonal` = 0, all elements on and below the main diagonal are
retained. A positive value includes just as many diagonals above the main
diagonal, and similarly a negative value excludes just as many diagonals below
the main diagonal. The main diagonal are the set of indices
:math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]` where
:math:`d_{1}, d_{2}` are the dimensions of the matrix.
Args:
input (Tensor): the input tensor.
diagonal (int, optional): the diagonal to consider
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(3, 3)
>>> a
tensor([[-1.0813, -0.8619, 0.7105],
[ 0.0935, 0.1380, 2.2112],
[-0.3409, -0.9828, 0.0289]])
>>> torch.tril(a)
tensor([[-1.0813, 0.0000, 0.0000],
[ 0.0935, 0.1380, 0.0000],
[-0.3409, -0.9828, 0.0289]])
>>> b = torch.randn(4, 6)
>>> b
tensor([[ 1.2219, 0.5653, -0.2521, -0.2345, 1.2544, 0.3461],
[ 0.4785, -0.4477, 0.6049, 0.6368, 0.8775, 0.7145],
[ 1.1502, 3.2716, -1.1243, -0.5413, 0.3615, 0.6864],
[-0.0614, -0.7344, -1.3164, -0.7648, -1.4024, 0.0978]])
>>> torch.tril(b, diagonal=1)
tensor([[ 1.2219, 0.5653, 0.0000, 0.0000, 0.0000, 0.0000],
[ 0.4785, -0.4477, 0.6049, 0.0000, 0.0000, 0.0000],
[ 1.1502, 3.2716, -1.1243, -0.5413, 0.0000, 0.0000],
[-0.0614, -0.7344, -1.3164, -0.7648, -1.4024, 0.0000]])
>>> torch.tril(b, diagonal=-1)
tensor([[ 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[ 0.4785, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[ 1.1502, 3.2716, 0.0000, 0.0000, 0.0000, 0.0000],
[-0.0614, -0.7344, -1.3164, 0.0000, 0.0000, 0.0000]])
tril_indices(...)
tril_indices(row, col, offset=0, *, dtype=torch.long, device='cpu', layout=torch.strided) -> Tensor
Returns the indices of the lower triangular part of a :attr:`row`-by-
:attr:`col` matrix in a 2-by-N Tensor, where the first row contains row
coordinates of all indices and the second row contains column coordinates.
Indices are ordered based on rows and then columns.
The lower triangular part of the matrix is defined as the elements on and
below the diagonal.
The argument :attr:`offset` controls which diagonal to consider. If
:attr:`offset` = 0, all elements on and below the main diagonal are
retained. A positive value includes just as many diagonals above the main
diagonal, and similarly a negative value excludes just as many diagonals below
the main diagonal. The main diagonal are the set of indices
:math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]`
where :math:`d_{1}, d_{2}` are the dimensions of the matrix.
.. note::
When running on CUDA, ``row * col`` must be less than :math:`2^{59}` to
prevent overflow during calculation.
Args:
row (``int``): number of rows in the 2-D matrix.
col (``int``): number of columns in the 2-D matrix.
offset (``int``): diagonal offset from the main diagonal.
Default: if not provided, 0.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor,
only support ``torch.int``, ``torch.long``. Default: if ``None``, ``torch.long``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
layout (:class:`torch.layout`, optional): currently only support ``torch.strided``.
Example::
>>> a = torch.tril_indices(3, 3)
>>> a
tensor([[0, 1, 1, 2, 2, 2],
[0, 0, 1, 0, 1, 2]])
>>> a = torch.tril_indices(4, 3, -1)
>>> a
tensor([[1, 2, 2, 3, 3, 3],
[0, 0, 1, 0, 1, 2]])
>>> a = torch.tril_indices(4, 3, 1)
>>> a
tensor([[0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3],
[0, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2]])
triplet_margin_loss(...)
triu(...)
triu(input, diagonal=0, *, out=None) -> Tensor
Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices
:attr:`input`, the other elements of the result tensor :attr:`out` are set to 0.
The upper triangular part of the matrix is defined as the elements on and
above the diagonal.
The argument :attr:`diagonal` controls which diagonal to consider. If
:attr:`diagonal` = 0, all elements on and above the main diagonal are
retained. A positive value excludes just as many diagonals above the main
diagonal, and similarly a negative value includes just as many diagonals below
the main diagonal. The main diagonal are the set of indices
:math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]` where
:math:`d_{1}, d_{2}` are the dimensions of the matrix.
Args:
input (Tensor): the input tensor.
diagonal (int, optional): the diagonal to consider
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(3, 3)
>>> a
tensor([[ 0.2309, 0.5207, 2.0049],
[ 0.2072, -1.0680, 0.6602],
[ 0.3480, -0.5211, -0.4573]])
>>> torch.triu(a)
tensor([[ 0.2309, 0.5207, 2.0049],
[ 0.0000, -1.0680, 0.6602],
[ 0.0000, 0.0000, -0.4573]])
>>> torch.triu(a, diagonal=1)
tensor([[ 0.0000, 0.5207, 2.0049],
[ 0.0000, 0.0000, 0.6602],
[ 0.0000, 0.0000, 0.0000]])
>>> torch.triu(a, diagonal=-1)
tensor([[ 0.2309, 0.5207, 2.0049],
[ 0.2072, -1.0680, 0.6602],
[ 0.0000, -0.5211, -0.4573]])
>>> b = torch.randn(4, 6)
>>> b
tensor([[ 0.5876, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
[-0.2447, 0.9556, -1.2919, 1.3378, -0.1768, -1.0857],
[ 0.4333, 0.3146, 0.6576, -1.0432, 0.9348, -0.4410],
[-0.9888, 1.0679, -1.3337, -1.6556, 0.4798, 0.2830]])
>>> torch.triu(b, diagonal=1)
tensor([[ 0.0000, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
[ 0.0000, 0.0000, -1.2919, 1.3378, -0.1768, -1.0857],
[ 0.0000, 0.0000, 0.0000, -1.0432, 0.9348, -0.4410],
[ 0.0000, 0.0000, 0.0000, 0.0000, 0.4798, 0.2830]])
>>> torch.triu(b, diagonal=-1)
tensor([[ 0.5876, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
[-0.2447, 0.9556, -1.2919, 1.3378, -0.1768, -1.0857],
[ 0.0000, 0.3146, 0.6576, -1.0432, 0.9348, -0.4410],
[ 0.0000, 0.0000, -1.3337, -1.6556, 0.4798, 0.2830]])
triu_indices(...)
triu_indices(row, col, offset=0, *, dtype=torch.long, device='cpu', layout=torch.strided) -> Tensor
Returns the indices of the upper triangular part of a :attr:`row` by
:attr:`col` matrix in a 2-by-N Tensor, where the first row contains row
coordinates of all indices and the second row contains column coordinates.
Indices are ordered based on rows and then columns.
The upper triangular part of the matrix is defined as the elements on and
above the diagonal.
The argument :attr:`offset` controls which diagonal to consider. If
:attr:`offset` = 0, all elements on and above the main diagonal are
retained. A positive value excludes just as many diagonals above the main
diagonal, and similarly a negative value includes just as many diagonals below
the main diagonal. The main diagonal are the set of indices
:math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]`
where :math:`d_{1}, d_{2}` are the dimensions of the matrix.
.. note::
When running on CUDA, ``row * col`` must be less than :math:`2^{59}` to
prevent overflow during calculation.
Args:
row (``int``): number of rows in the 2-D matrix.
col (``int``): number of columns in the 2-D matrix.
offset (``int``): diagonal offset from the main diagonal.
Default: if not provided, 0.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor,
only support ``torch.int``, ``torch.long``. Default: if ``None``, ``torch.long``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
layout (:class:`torch.layout`, optional): currently only support ``torch.strided``.
Example::
>>> a = torch.triu_indices(3, 3)
>>> a
tensor([[0, 0, 0, 1, 1, 2],
[0, 1, 2, 1, 2, 2]])
>>> a = torch.triu_indices(4, 3, -1)
>>> a
tensor([[0, 0, 0, 1, 1, 1, 2, 2, 3],
[0, 1, 2, 0, 1, 2, 1, 2, 2]])
>>> a = torch.triu_indices(4, 3, 1)
>>> a
tensor([[0, 0, 1],
[1, 2, 2]])
true_divide(...)
true_divide(dividend, divisor, *, out) -> Tensor
Alias for :func:`torch.div` with ``rounding_mode=None``.
trunc(...)
trunc(input, *, out=None) -> Tensor
Returns a new tensor with the truncated integer values of
the elements of :attr:`input`.
For integer inputs, follows the array-api convention of returning a
copy of the input tensor.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 3.4742, 0.5466, -0.8008, -0.9079])
>>> torch.trunc(a)
tensor([ 3., 0., -0., -0.])
trunc_(...)
typename(obj: Any, /) -> str
String representation of the type of an object.
This function returns a fully qualified string representation of an object's type.
Args:
obj (object): The object whose type to represent
Returns:
str: the type of the object `o`
Example:
>>> x = torch.tensor([1, 2, 3])
>>> torch.typename(x)
'torch.LongTensor'
>>> torch.typename(torch.nn.Parameter)
'torch.nn.parameter.Parameter'
unbind(...)
unbind(input, dim=0) -> seq
Removes a tensor dimension.
Returns a tuple of all slices along a given dimension, already without it.
Arguments:
input (Tensor): the tensor to unbind
dim (int): dimension to remove
Example::
>>> torch.unbind(torch.tensor([[1, 2, 3],
>>> [4, 5, 6],
>>> [7, 8, 9]]))
(tensor([1, 2, 3]), tensor([4, 5, 6]), tensor([7, 8, 9]))
unbind_copy(...)
Performs the same operation as :func:`torch.unbind`, but all output tensors
are freshly created instead of aliasing the input.
unflatten(...)
unflatten(input, dim, sizes) -> Tensor
Expands a dimension of the input tensor over multiple dimensions.
.. seealso::
:func:`torch.flatten` the inverse of this function. It coalesces several dimensions into one.
Args:
input (Tensor): the input tensor.
dim (int): Dimension to be unflattened, specified as an index into
``input.shape``.
sizes (Tuple[int]): New shape of the unflattened dimension.
One of its elements can be `-1` in which case the corresponding output
dimension is inferred. Otherwise, the product of ``sizes`` *must*
equal ``input.shape[dim]``.
Returns:
A View of input with the specified dimension unflattened.
Examples::
>>> torch.unflatten(torch.randn(3, 4, 1), 1, (2, 2)).shape
torch.Size([3, 2, 2, 1])
>>> torch.unflatten(torch.randn(3, 4, 1), 1, (-1, 2)).shape
torch.Size([3, 2, 2, 1])
>>> torch.unflatten(torch.randn(5, 12, 3), -2, (2, 2, 3, 1, 1)).shape
torch.Size([5, 2, 2, 3, 1, 1, 3])
unfold_copy(...)
Performs the same operation as :func:`torch.unfold`, but all output tensors
are freshly created instead of aliasing the input.
unify_type_list(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
unify_type_list(arg0: collections.abc.Sequence[c10::Type]) -> c10::Type
unique_consecutive(*args, **kwargs)
Eliminates all but the first element from every consecutive group of equivalent elements.
.. note:: This function is different from :func:`torch.unique` in the sense that this function
only eliminates consecutive duplicate values. This semantics is similar to `std::unique`
in C++.
Args:
input (Tensor): the input tensor
return_inverse (bool): Whether to also return the indices for where
elements in the original input ended up in the returned unique list.
return_counts (bool): Whether to also return the counts for each unique
element.
dim (int): the dimension to apply unique. If ``None``, the unique of the
flattened input is returned. default: ``None``
Returns:
(Tensor, Tensor (optional), Tensor (optional)): A tensor or a tuple of tensors containing
- **output** (*Tensor*): the output list of unique scalar elements.
- **inverse_indices** (*Tensor*): (optional) if
:attr:`return_inverse` is True, there will be an additional
returned tensor (same shape as input) representing the indices
for where elements in the original input map to in the output;
otherwise, this function will only return a single tensor.
- **counts** (*Tensor*): (optional) if
:attr:`return_counts` is True, there will be an additional
returned tensor (same shape as output or output.size(dim),
if dim was specified) representing the number of occurrences
for each unique value or tensor.
Example::
>>> x = torch.tensor([1, 1, 2, 2, 3, 1, 1, 2])
>>> output = torch.unique_consecutive(x)
>>> output
tensor([1, 2, 3, 1, 2])
>>> output, inverse_indices = torch.unique_consecutive(x, return_inverse=True)
>>> output
tensor([1, 2, 3, 1, 2])
>>> inverse_indices
tensor([0, 0, 1, 1, 2, 3, 3, 4])
>>> output, counts = torch.unique_consecutive(x, return_counts=True)
>>> output
tensor([1, 2, 3, 1, 2])
>>> counts
tensor([2, 2, 1, 2, 1])
unravel_index(indices: torch.Tensor, shape: int | collections.abc.Sequence[int] | torch.Size) -> tuple[torch.Tensor, ...]
Converts a tensor of flat indices into a tuple of coordinate tensors that
index into an arbitrary tensor of the specified shape.
Args:
indices (Tensor): An integer tensor containing indices into the
flattened version of an arbitrary tensor of shape :attr:`shape`.
All elements must be in the range ``[0, prod(shape) - 1]``.
shape (int, sequence of ints, or torch.Size): The shape of the arbitrary
tensor. All elements must be non-negative.
Returns:
tuple of Tensors: Each ``i``-th tensor in the output corresponds with
dimension ``i`` of :attr:`shape`. Each tensor has the same shape as
``indices`` and contains one index into dimension ``i`` for each of the
flat indices given by ``indices``.
Example::
>>> import torch
>>> torch.unravel_index(torch.tensor(4), (3, 2))
(tensor(2),
tensor(0))
>>> torch.unravel_index(torch.tensor([4, 1]), (3, 2))
(tensor([2, 0]),
tensor([0, 1]))
>>> torch.unravel_index(torch.tensor([0, 1, 2, 3, 4, 5]), (3, 2))
(tensor([0, 0, 1, 1, 2, 2]),
tensor([0, 1, 0, 1, 0, 1]))
>>> torch.unravel_index(torch.tensor([1234, 5678]), (10, 10, 10, 10))
(tensor([1, 5]),
tensor([2, 6]),
tensor([3, 7]),
tensor([4, 8]))
>>> torch.unravel_index(torch.tensor([[1234], [5678]]), (10, 10, 10, 10))
(tensor([[1], [5]]),
tensor([[2], [6]]),
tensor([[3], [7]]),
tensor([[4], [8]]))
>>> torch.unravel_index(torch.tensor([[1234], [5678]]), (100, 100))
(tensor([[12], [56]]),
tensor([[34], [78]]))
unsafe_chunk(...)
unsafe_chunk(input, chunks, dim=0) -> List of Tensors
Works like :func:`torch.chunk` but without enforcing the autograd restrictions
on inplace modification of the outputs.
.. warning::
This function is safe to use as long as only the input, or only the outputs
are modified inplace after calling this function. It is user's
responsibility to ensure that is the case. If both the input and one or more
of the outputs are modified inplace, gradients computed by autograd will be
silently incorrect.
unsafe_split(...)
unsafe_split(tensor, split_size_or_sections, dim=0) -> List of Tensors
Works like :func:`torch.split` but without enforcing the autograd restrictions
on inplace modification of the outputs.
.. warning::
This function is safe to use as long as only the input, or only the outputs
are modified inplace after calling this function. It is user's
responsibility to ensure that is the case. If both the input and one or more
of the outputs are modified inplace, gradients computed by autograd will be
silently incorrect.
unsafe_split_with_sizes(...)
unsqueeze(...)
unsqueeze(input, dim) -> Tensor
Returns a new tensor with a dimension of size one inserted at the
specified position.
The returned tensor shares the same underlying data with this tensor.
A :attr:`dim` value within the range ``[-input.dim() - 1, input.dim() + 1)``
can be used. Negative :attr:`dim` will correspond to :meth:`unsqueeze`
applied at :attr:`dim` = ``dim + input.dim() + 1``.
Args:
input (Tensor): the input tensor.
dim (int): the index at which to insert the singleton dimension
Example::
>>> x = torch.tensor([1, 2, 3, 4])
>>> torch.unsqueeze(x, 0)
tensor([[ 1, 2, 3, 4]])
>>> torch.unsqueeze(x, 1)
tensor([[ 1],
[ 2],
[ 3],
[ 4]])
unsqueeze_copy(...)
Performs the same operation as :func:`torch.unsqueeze`, but all output tensors
are freshly created instead of aliasing the input.
use_deterministic_algorithms(mode: bool, *, warn_only: bool = False) -> None
Sets whether PyTorch operations must use "deterministic"
algorithms. That is, algorithms which, given the same input, and when
run on the same software and hardware, always produce the same output.
When enabled, operations will use deterministic algorithms when available,
and if only nondeterministic algorithms are available they will throw a
:class:`RuntimeError` when called.
.. note:: This setting alone is not always enough to make an application
reproducible. Refer to :ref:`reproducibility` for more information.
.. note:: :func:`torch.set_deterministic_debug_mode` offers an alternative
interface for this feature.
The following normally-nondeterministic operations will act
deterministically when ``mode=True``:
* :class:`torch.nn.Conv1d` when called on CUDA tensor
* :class:`torch.nn.Conv2d` when called on CUDA tensor
* :class:`torch.nn.Conv3d` when called on CUDA tensor
* :class:`torch.nn.ConvTranspose1d` when called on CUDA tensor
* :class:`torch.nn.ConvTranspose2d` when called on CUDA tensor
* :class:`torch.nn.ConvTranspose3d` when called on CUDA tensor
* :class:`torch.nn.ReplicationPad1d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.ReplicationPad2d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.ReplicationPad3d` when attempting to differentiate a CUDA tensor
* :func:`torch.bmm` when called on sparse-dense CUDA tensors
* :func:`torch.Tensor.__getitem__` when attempting to differentiate a CPU tensor
and the index is a list of tensors
* :func:`torch.Tensor.index_put` with ``accumulate=False``
* :func:`torch.Tensor.index_put` with ``accumulate=True`` when called on a CPU
tensor
* :func:`torch.Tensor.put_` with ``accumulate=True`` when called on a CPU
tensor
* :func:`torch.Tensor.scatter_add_` when called on a CUDA tensor
* :func:`torch.gather` when called on a CUDA tensor that requires grad
* :func:`torch.index_add` when called on CUDA tensor
* :func:`torch.index_select` when attempting to differentiate a CUDA tensor
* :func:`torch.repeat_interleave` when attempting to differentiate a CUDA tensor
* :func:`torch.Tensor.index_copy` when called on a CPU or CUDA tensor
* :func:`torch.Tensor.scatter` when `src` type is Tensor and called on CUDA tensor
* :func:`torch.Tensor.scatter_reduce` when ``reduce='sum'`` or ``reduce='mean'`` and called on CUDA tensor
* :class:`torch.nn.MaxPool3d` when attempting to differentiate a CUDA tensor
The following normally-nondeterministic operations will throw a
:class:`RuntimeError` when ``mode=True``:
* :class:`torch.nn.AvgPool3d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.AdaptiveAvgPool2d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.AdaptiveAvgPool3d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.AdaptiveMaxPool2d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.FractionalMaxPool2d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.FractionalMaxPool3d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.MaxUnpool1d`
* :class:`torch.nn.MaxUnpool2d`
* :class:`torch.nn.MaxUnpool3d`
* :func:`torch.nn.functional.interpolate` when attempting to differentiate a CUDA tensor
and one of the following modes is used:
- ``linear``
- ``bilinear``
- ``bicubic``
- ``trilinear``
* :class:`torch.nn.ReflectionPad1d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.ReflectionPad2d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.ReflectionPad3d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.NLLLoss` when called on a CUDA tensor
* :class:`torch.nn.CTCLoss` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.EmbeddingBag` when attempting to differentiate a CUDA tensor when
``mode='max'``
* :func:`torch.Tensor.put_` when ``accumulate=False``
* :func:`torch.Tensor.put_` when ``accumulate=True`` and called on a CUDA tensor
* :func:`torch.histc` when called on a CUDA tensor
* :func:`torch.bincount` when called on a CUDA tensor and ``weights``
tensor is given
* :func:`torch.median` with indices output when called on a CUDA tensor
* :func:`torch.nn.functional.grid_sample` when attempting to differentiate a CUDA tensor
* :func:`torch.cumsum` when called on a CUDA tensor when dtype is floating point or complex
* :func:`torch.Tensor.scatter_reduce` when ``reduce='prod'`` and called on CUDA tensor
* :func:`torch.Tensor.resize_` when called with a quantized tensor
In addition, several operations fill uninitialized memory when this setting
is turned on and when
:attr:`torch.utils.deterministic.fill_uninitialized_memory` is turned on.
See the documentation for that attribute for more information.
Note that deterministic operations tend to have worse performance than
nondeterministic operations.
When this setting is turned on, the Inductor deterministic mode is also tuned on
automatically. In deterministic mode, Inductor would avoid doing on device benchmarking
that affect numerics. This includes:
- don't pad matmul input shapes. Without enabling deterministic mode, Inductor would do
benchmarking to check if padding matmul shape is beneficial.
- don't autotune templates. Inductor has templates for kernels like matmul/conv/attention.
Without enabling deterministic mode, Inductor would do autotuning to
pick the best configs for those templates and adopt it if it's faster
than the kernel in eager mode. In deterministic mode, we pick the eager kernel.
- don't autotune triton configs for reduction. Reduction numerics are
very sensitive to triton configs. In deterministic mode, Inductor
will use some heuristics to pick the most promising configs rather
than do autotuning.
- Skip autotuning for reduction in coordinate descent tuning.
- Don't benchmark for the computation/communication reordering pass
- Disable the feature that dynamically scale down RBLOCK triton config for higher
occupancy.
.. note::
This flag does not detect or prevent nondeterministic behavior caused
by calling an inplace operation on a tensor with an internal memory
overlap or by giving such a tensor as the :attr:`out` argument for an
operation. In these cases, multiple writes of different data may target
a single memory location, and the order of writes is not guaranteed.
Args:
mode (:class:`bool`): If True, makes potentially nondeterministic
operations switch to a deterministic algorithm or throw a runtime
error. If False, allows nondeterministic operations.
Keyword args:
warn_only (:class:`bool`, optional): If True, operations that do not
have a deterministic implementation will throw a warning instead of
an error. Default: ``False``
Example::
>>> # xdoctest: +SKIP
>>> torch.use_deterministic_algorithms(True)
# Backward mode nondeterministic error
>>> torch.nn.AvgPool3d(1)(torch.randn(3, 4, 5, 6, requires_grad=True).cuda()).sum().backward()
...
RuntimeError: avg_pool3d_backward_cuda does not have a deterministic implementation...
values_copy(...)
Performs the same operation as :func:`torch.values`, but all output tensors
are freshly created instead of aliasing the input.
vander(...)
vander(x, N=None, increasing=False) -> Tensor
Generates a Vandermonde matrix.
The columns of the output matrix are elementwise powers of the input vector :math:`x^{(N-1)}, x^{(N-2)}, ..., x^0`.
If increasing is True, the order of the columns is reversed :math:`x^0, x^1, ..., x^{(N-1)}`. Such a
matrix with a geometric progression in each row is named for Alexandre-Theophile Vandermonde.
Arguments:
x (Tensor): 1-D input tensor.
N (int, optional): Number of columns in the output. If N is not specified,
a square array is returned :math:`(N = len(x))`.
increasing (bool, optional): Order of the powers of the columns. If True,
the powers increase from left to right, if False (the default) they are reversed.
Returns:
Tensor: Vandermonde matrix. If increasing is False, the first column is :math:`x^{(N-1)}`,
the second :math:`x^{(N-2)}` and so forth. If increasing is True, the columns
are :math:`x^0, x^1, ..., x^{(N-1)}`.
Example::
>>> x = torch.tensor([1, 2, 3, 5])
>>> torch.vander(x)
tensor([[ 1, 1, 1, 1],
[ 8, 4, 2, 1],
[ 27, 9, 3, 1],
[125, 25, 5, 1]])
>>> torch.vander(x, N=3)
tensor([[ 1, 1, 1],
[ 4, 2, 1],
[ 9, 3, 1],
[25, 5, 1]])
>>> torch.vander(x, N=3, increasing=True)
tensor([[ 1, 1, 1],
[ 1, 2, 4],
[ 1, 3, 9],
[ 1, 5, 25]])
var(...)
var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
can be a single dimension, list of dimensions, or ``None`` to reduce over all
dimensions.
The variance (:math:`\sigma^2`) is calculated as
.. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
sample mean, :math:`N` is the number of samples and :math:`\delta N` is
the :attr:`correction`.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
Keyword args:
correction (int): difference between the sample size and sample degrees of freedom.
Defaults to `Bessel's correction`_, ``correction=1``.
.. versionchanged:: 2.0
Previously this argument was called ``unbiased`` and was a boolean
with ``True`` corresponding to ``correction=1`` and ``False`` being
``correction=0``.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
out (Tensor, optional): the output tensor.
Example:
>>> a = torch.tensor(
... [[ 0.2035, 1.2959, 1.8101, -0.4644],
... [ 1.5027, -0.3270, 0.5905, 0.6538],
... [-1.5745, 1.3330, -0.5596, -0.6548],
... [ 0.1264, -0.5080, 1.6420, 0.1992]]
... ) # fmt: skip
>>> torch.var(a, dim=1, keepdim=True)
tensor([[1.0631],
[0.5590],
[1.4893],
[0.8258]])
.. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
var_mean(...)
var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
Calculates the variance and mean over the dimensions specified by :attr:`dim`.
:attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
reduce over all dimensions.
The variance (:math:`\sigma^2`) is calculated as
.. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
sample mean, :math:`N` is the number of samples and :math:`\delta N` is
the :attr:`correction`.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
Keyword args:
correction (int): difference between the sample size and sample degrees of freedom.
Defaults to `Bessel's correction`_, ``correction=1``.
.. versionchanged:: 2.0
Previously this argument was called ``unbiased`` and was a boolean
with ``True`` corresponding to ``correction=1`` and ``False`` being
``correction=0``.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
out (Tensor, optional): the output tensor.
Returns:
A tuple (var, mean) containing the variance and mean.
Example:
>>> a = torch.tensor(
... [[ 0.2035, 1.2959, 1.8101, -0.4644],
... [ 1.5027, -0.3270, 0.5905, 0.6538],
... [-1.5745, 1.3330, -0.5596, -0.6548],
... [ 0.1264, -0.5080, 1.6420, 0.1992]]
... ) # fmt: skip
>>> torch.var_mean(a, dim=0, keepdim=True)
(tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
.. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
vdot(...)
vdot(input, other, *, out=None) -> Tensor
Computes the dot product of two 1D vectors along a dimension.
In symbols, this function computes
.. math::
\sum_{i=1}^n \overline{x_i}y_i.
where :math:`\overline{x_i}` denotes the conjugate for complex
vectors, and it is the identity for real vectors.
.. note::
Unlike NumPy's vdot, torch.vdot intentionally only supports computing the dot product
of two 1D tensors with the same number of elements.
.. seealso::
:func:`torch.linalg.vecdot` computes the dot product of two batches of vectors along a dimension.
Args:
input (Tensor): first tensor in the dot product, must be 1D. Its conjugate is used if it's complex.
other (Tensor): second tensor in the dot product, must be 1D.
Keyword args:
.. note:: out (Tensor, optional): the output tensor.
Example::
>>> torch.vdot(torch.tensor([2, 3]), torch.tensor([2, 1]))
tensor(7)
>>> a = torch.tensor((1 +2j, 3 - 1j))
>>> b = torch.tensor((2 +1j, 4 - 0j))
>>> torch.vdot(a, b)
tensor([16.+1.j])
>>> torch.vdot(b, a)
tensor([16.-1.j])
view_as_complex(...)
view_as_complex(input) -> Tensor
Returns a view of :attr:`input` as a complex tensor. For an input complex
tensor of :attr:`size` :math:`m1, m2, \dots, mi, 2`, this function returns a
new complex tensor of :attr:`size` :math:`m1, m2, \dots, mi` where the last
dimension of the input tensor is expected to represent the real and imaginary
components of complex numbers.
.. warning::
:func:`view_as_complex` is only supported for tensors with
:class:`torch.dtype` ``torch.float64`` and ``torch.float32``. The input is
expected to have the last dimension of :attr:`size` 2. In addition, the
tensor must have a `stride` of 1 for its last dimension. The strides of all
other dimensions must be even numbers.
Args:
input (Tensor): the input tensor.
Example::
>>> x=torch.randn(4, 2)
>>> x
tensor([[ 1.6116, -0.5772],
[-1.4606, -0.9120],
[ 0.0786, -1.7497],
[-0.6561, -1.6623]])
>>> torch.view_as_complex(x)
tensor([(1.6116-0.5772j), (-1.4606-0.9120j), (0.0786-1.7497j), (-0.6561-1.6623j)])
view_as_complex_copy(...)
Performs the same operation as :func:`torch.view_as_complex`, but all output tensors
are freshly created instead of aliasing the input.
view_as_real(...)
view_as_real(input) -> Tensor
Returns a view of :attr:`input` as a real tensor. For an input complex tensor of
:attr:`size` :math:`m1, m2, \dots, mi`, this function returns a new
real tensor of size :math:`m1, m2, \dots, mi, 2`, where the last dimension of size 2
represents the real and imaginary components of complex numbers.
.. warning::
:func:`view_as_real` is only supported for tensors with ``complex dtypes``.
Args:
input (Tensor): the input tensor.
Example::
>>> x=torch.randn(4, dtype=torch.cfloat)
>>> x
tensor([(0.4737-0.3839j), (-0.2098-0.6699j), (0.3470-0.9451j), (-0.5174-1.3136j)])
>>> torch.view_as_real(x)
tensor([[ 0.4737, -0.3839],
[-0.2098, -0.6699],
[ 0.3470, -0.9451],
[-0.5174, -1.3136]])
view_as_real_copy(...)
Performs the same operation as :func:`torch.view_as_real`, but all output tensors
are freshly created instead of aliasing the input.
view_copy(...)
Performs the same operation as :func:`torch.view`, but all output tensors
are freshly created instead of aliasing the input.
vmap(func: 'Callable[_P, _R]', in_dims: 'in_dims_t' = 0, out_dims: 'out_dims_t' = 0, randomness: 'str' = 'error', *, chunk_size: 'int | None' = None) -> 'Callable[_P, _R]'
vmap is the vectorizing map; ``vmap(func)`` returns a new function that
maps ``func`` over some dimension of the inputs. Semantically, vmap
pushes the map into PyTorch operations called by ``func``, effectively
vectorizing those operations.
vmap is useful for handling batch dimensions: one can write a function
``func`` that runs on examples and then lift it to a function that can
take batches of examples with ``vmap(func)``. vmap can also be used to
compute batched gradients when composed with autograd.
.. note::
:func:`torch.vmap` is aliased to :func:`torch.func.vmap` for
convenience. Use whichever one you'd like.
Args:
func (function): A Python function that takes one or more arguments.
Must return one or more Tensors.
in_dims (int or nested structure): Specifies which dimension of the
inputs should be mapped over. ``in_dims`` should have a
structure like the inputs. If the ``in_dim`` for a particular
input is None, then that indicates there is no map dimension.
Default: 0.
out_dims (int or Tuple[int]): Specifies where the mapped dimension
should appear in the outputs. If ``out_dims`` is a Tuple, then
it should have one element per output. Default: 0.
randomness (str): Specifies whether the randomness in this
vmap should be the same or different across batches. If 'different',
the randomness for each batch will be different. If 'same', the
randomness will be the same across batches. If 'error', any calls to
random functions will error. Default: 'error'. WARNING: this flag
only applies to random PyTorch operations and does not apply to
Python's random module or numpy randomness.
chunk_size (None or int): If None (default), apply a single vmap over inputs.
If not None, then compute the vmap :attr:`chunk_size` samples at a time.
Note that :attr:`chunk_size=1` is equivalent to computing the vmap with a for-loop.
If you run into memory issues computing the vmap, please try a non-None chunk_size.
Returns:
Returns a new "batched" function. It takes the same inputs as
``func``, except each input has an extra dimension at the index
specified by ``in_dims``. It takes returns the same outputs as
``func``, except each output has an extra dimension at the index
specified by ``out_dims``.
.. warning:
:func:`vmap` works best with functional-style code. Please do not
perform any side-effects in ``func``, with the exception of
in-place PyTorch operations. Examples of side-effects include mutating
Python data structures and assigning values to variables not captured
in ``func``.
One example of using :func:`vmap` is to compute batched dot products. PyTorch
doesn't provide a batched ``torch.dot`` API; instead of unsuccessfully
rummaging through docs, use :func:`vmap` to construct a new function.
>>> torch.dot # [D], [D] -> []
>>> batched_dot = torch.func.vmap(torch.dot) # [N, D], [N, D] -> [N]
>>> x, y = torch.randn(2, 5), torch.randn(2, 5)
>>> batched_dot(x, y)
:func:`vmap` can be helpful in hiding batch dimensions, leading to a simpler
model authoring experience.
>>> batch_size, feature_size = 3, 5
>>> weights = torch.randn(feature_size, requires_grad=True)
>>>
>>> def model(feature_vec):
>>> # Very simple linear model with activation
>>> return feature_vec.dot(weights).relu()
>>>
>>> examples = torch.randn(batch_size, feature_size)
>>> result = torch.vmap(model)(examples)
:func:`vmap` can also help vectorize computations that were previously difficult
or impossible to batch. One example is higher-order gradient computation.
The PyTorch autograd engine computes vjps (vector-Jacobian products).
Computing a full Jacobian matrix for some function f: R^N -> R^N usually
requires N calls to ``autograd.grad``, one per Jacobian row. Using :func:`vmap`,
we can vectorize the whole computation, computing the Jacobian in a single
call to ``autograd.grad``.
>>> # Setup
>>> N = 5
>>> f = lambda x: x**2
>>> x = torch.randn(N, requires_grad=True)
>>> y = f(x)
>>> I_N = torch.eye(N)
>>>
>>> # Sequential approach
>>> jacobian_rows = [torch.autograd.grad(y, x, v, retain_graph=True)[0]
>>> for v in I_N.unbind()]
>>> jacobian = torch.stack(jacobian_rows)
>>>
>>> # vectorized gradient computation
>>> def get_vjp(v):
>>> return torch.autograd.grad(y, x, v)
>>> jacobian = torch.vmap(get_vjp)(I_N)
:func:`vmap` can also be nested, producing an output with multiple batched dimensions
>>> torch.dot # [D], [D] -> []
>>> batched_dot = torch.vmap(
... torch.vmap(torch.dot)
... ) # [N1, N0, D], [N1, N0, D] -> [N1, N0]
>>> x, y = torch.randn(2, 3, 5), torch.randn(2, 3, 5)
>>> batched_dot(x, y) # tensor of size [2, 3]
If the inputs are not batched along the first dimension, ``in_dims`` specifies
the dimension that each inputs are batched along as
>>> torch.dot # [N], [N] -> []
>>> batched_dot = torch.vmap(torch.dot, in_dims=1) # [N, D], [N, D] -> [D]
>>> x, y = torch.randn(2, 5), torch.randn(2, 5)
>>> batched_dot(
... x, y
... ) # output is [5] instead of [2] if batched along the 0th dimension
If there are multiple inputs each of which is batched along different dimensions,
``in_dims`` must be a tuple with the batch dimension for each input as
>>> torch.dot # [D], [D] -> []
>>> batched_dot = torch.vmap(torch.dot, in_dims=(0, None)) # [N, D], [D] -> [N]
>>> x, y = torch.randn(2, 5), torch.randn(5)
>>> batched_dot(
... x, y
... ) # second arg doesn't have a batch dim because in_dim[1] was None
If the input is a Python struct, ``in_dims`` must be a tuple containing a struct
matching the shape of the input:
>>> f = lambda dict: torch.dot(dict["x"], dict["y"])
>>> x, y = torch.randn(2, 5), torch.randn(5)
>>> input = {"x": x, "y": y}
>>> batched_dot = torch.vmap(f, in_dims=({"x": 0, "y": None},))
>>> batched_dot(input)
By default, the output is batched along the first dimension. However, it can be batched
along any dimension by using ``out_dims``
>>> f = lambda x: x**2
>>> x = torch.randn(2, 5)
>>> batched_pow = torch.vmap(f, out_dims=1)
>>> batched_pow(x) # [5, 2]
For any function that uses kwargs, the returned function will not batch the kwargs but will
accept kwargs
>>> x = torch.randn([2, 5])
>>> def fn(x, scale=4.):
>>> return x * scale
>>>
>>> batched_pow = torch.vmap(fn)
>>> assert torch.allclose(batched_pow(x), x * 4)
>>> batched_pow(x, scale=x) # scale is not batched, output has shape [2, 2, 5]
.. note::
vmap does not provide general autobatching or handle variable-length
sequences out of the box.
vsplit(...)
vsplit(input, indices_or_sections) -> List of Tensors
Splits :attr:`input`, a tensor with two or more dimensions, into multiple tensors
vertically according to :attr:`indices_or_sections`. Each split is a view of
:attr:`input`.
This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=0)
(the split dimension is 0), except that if :attr:`indices_or_sections` is an integer
it must evenly divide the split dimension or a runtime error will be thrown.
This function is based on NumPy's :func:`numpy.vsplit`.
Args:
input (Tensor): tensor to split.
indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
Example::
>>> t = torch.arange(16.0).reshape(4,4)
>>> t
tensor([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.],
[12., 13., 14., 15.]])
>>> torch.vsplit(t, 2)
(tensor([[0., 1., 2., 3.],
[4., 5., 6., 7.]]),
tensor([[ 8., 9., 10., 11.],
[12., 13., 14., 15.]]))
>>> torch.vsplit(t, [3, 6])
(tensor([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]]),
tensor([[12., 13., 14., 15.]]),
tensor([], size=(0, 4)))
vstack(...)
vstack(tensors, *, out=None) -> Tensor
Stack tensors in sequence vertically (row wise).
This is equivalent to concatenation along the first axis after all 1-D tensors have been reshaped by :func:`torch.atleast_2d`.
Args:
tensors (sequence of Tensors): sequence of tensors to concatenate
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([1, 2, 3])
>>> b = torch.tensor([4, 5, 6])
>>> torch.vstack((a,b))
tensor([[1, 2, 3],
[4, 5, 6]])
>>> a = torch.tensor([[1],[2],[3]])
>>> b = torch.tensor([[4],[5],[6]])
>>> torch.vstack((a,b))
tensor([[1],
[2],
[3],
[4],
[5],
[6]])
wait(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
wait(arg0: torch._C.Future) -> object
where(...)
where(condition, input, other, *, out=None) -> Tensor
Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
The operation is defined as:
.. math::
\text{out}_i = \begin{cases}
\text{input}_i & \text{if } \text{condition}_i \\
\text{other}_i & \text{otherwise} \\
\end{cases}
.. note::
The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
Arguments:
condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
where :attr:`condition` is ``True``
other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
where :attr:`condition` is ``False``
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
Example::
>>> x = torch.randn(3, 2)
>>> y = torch.ones(3, 2)
>>> x
tensor([[-0.4620, 0.3139],
[ 0.3898, -0.7197],
[ 0.0478, -0.1657]])
>>> torch.where(x > 0, 1.0, 0.0)
tensor([[0., 1.],
[1., 0.],
[1., 0.]])
>>> torch.where(x > 0, x, y)
tensor([[ 1.0000, 0.3139],
[ 0.3898, 1.0000],
[ 0.0478, 1.0000]])
>>> x = torch.randn(2, 2, dtype=torch.double)
>>> x
tensor([[ 1.0779, 0.0383],
[-0.8785, -1.1089]], dtype=torch.float64)
>>> torch.where(x > 0, x, 0.)
tensor([[1.0779, 0.0383],
[0.0000, 0.0000]], dtype=torch.float64)
.. function:: where(condition) -> tuple of LongTensor
:noindex:
``torch.where(condition)`` is identical to
``torch.nonzero(condition, as_tuple=True)``.
.. note::
See also :func:`torch.nonzero`.
xlogy(...)
xlogy(input, other, *, out=None) -> Tensor
Alias for :func:`torch.special.xlogy`.
xlogy_(...)
zero_(...)
zeros(...)
zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a tensor filled with the scalar value `0`, with the shape defined
by the variable argument :attr:`size`.
Args:
size (int...): a sequence of integers defining the shape of the output tensor.
Can be a variable number of arguments or a collection like a list or tuple.
Keyword args:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.zeros(2, 3)
tensor([[ 0., 0., 0.],
[ 0., 0., 0.]])
>>> torch.zeros(5)
tensor([ 0., 0., 0., 0., 0.])
zeros_like(...)
zeros_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns a tensor filled with the scalar value `0`, with the same size as
:attr:`input`. ``torch.zeros_like(input)`` is equivalent to
``torch.zeros(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
.. warning::
As of 0.4, this function does not support an :attr:`out` keyword. As an alternative,
the old ``torch.zeros_like(input, out=output)`` is equivalent to
``torch.zeros(input.size(), out=output)``.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
Example::
>>> input = torch.empty(2, 3)
>>> torch.zeros_like(input)
tensor([[ 0., 0., 0.],
[ 0., 0., 0.]])
DATA
AVG = <AggregationType.AVG: 1>
SUM = <AggregationType.SUM: 0>
__all__ = ['BoolStorage', 'BoolTensor', 'ByteStorage', 'ByteTensor', '...
__annotations__ = {'_storage_classes': set[type[torch.storage.TypedSto...
bfloat16 = torch.bfloat16
bit = torch.uint1
bits16 = torch.bits16
bits1x8 = torch.bits1x8
bits2x4 = torch.bits2x4
bits4x2 = torch.bits4x2
bits8 = torch.bits8
bool = torch.bool
cdouble = torch.complex128
cfloat = torch.complex64
chalf = torch.complex32
complex128 = torch.complex128
complex32 = torch.complex32
complex64 = torch.complex64
default_generator = <torch._C.Generator object>
double = torch.float64
e = 2.718281828459045
float = torch.float32
float16 = torch.float16
float32 = torch.float32
float4_e2m1fn_x2 = torch.float4_e2m1fn_x2
float64 = torch.float64
float8_e4m3fn = torch.float8_e4m3fn
float8_e4m3fnuz = torch.float8_e4m3fnuz
float8_e5m2 = torch.float8_e5m2
float8_e5m2fnuz = torch.float8_e5m2fnuz
float8_e8m0fnu = torch.float8_e8m0fnu
half = torch.float16
has_lapack = True
has_mkl = True
has_openmp = True
has_spectral = True
inf = inf
int = torch.int32
int1 = torch.int1
int16 = torch.int16
int2 = torch.int2
int3 = torch.int3
int32 = torch.int32
int4 = torch.int4
int5 = torch.int5
int6 = torch.int6
int64 = torch.int64
int7 = torch.int7
int8 = torch.int8
long = torch.int64
nan = nan
newaxis = None
pi = 3.141592653589793
qint32 = torch.qint32
qint8 = torch.qint8
quint2x4 = torch.quint2x4
quint4x2 = torch.quint4x2
quint8 = torch.quint8
short = torch.int16
uint1 = torch.uint1
uint16 = torch.uint16
uint2 = torch.uint2
uint3 = torch.uint3
uint32 = torch.uint32
uint4 = torch.uint4
uint5 = torch.uint5
uint6 = torch.uint6
uint64 = torch.uint64
uint7 = torch.uint7
uint8 = torch.uint8
VERSION
2.13.0+cpu
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\__init__.py
torch.torch_version
Python Library Documentation: module torch.torch_version in torch
NAME
torch.torch_version
CLASSES
builtins.str(builtins.object)
TorchVersion
class TorchVersion(builtins.str)
| A string with magic powers to compare to both Version and iterables!
| Prior to 1.10.0 torch.__version__ was stored as a str and so many did
| comparisons against torch.__version__ as if it were a str. In order to not
| break them we have TorchVersion which masquerades as a str while also
| having the ability to compare against both packaging.version.Version as
| well as tuples of values, eg. (1, 2, 1)
| Examples:
| Comparing a TorchVersion object to a Version object
| TorchVersion('1.10.0a') > Version('1.10.0a')
| Comparing a TorchVersion object to a Tuple object
| TorchVersion('1.10.0a') > (1, 2) # 1.2
| TorchVersion('1.10.0a') > (1, 2, 1) # 1.2.1
| Comparing a TorchVersion object against a string
| TorchVersion('1.10.0a') > '1.2'
| TorchVersion('1.10.0a') > '1.2.1'
|
| Method resolution order:
| TorchVersion
| builtins.str
| builtins.object
|
| Methods defined here:
|
| __eq__ lambda x, y, method='__eq__'
|
| __ge__ lambda x, y, method='__ge__'
|
| __gt__ lambda x, y, method='__gt__'
|
| __le__ lambda x, y, method='__le__'
|
| __lt__ lambda x, y, method='__lt__'
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.str:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return bool(key in self).
|
| __format__(self, format_spec, /)
| Return a formatted version of the string as described by format_spec.
|
| __getitem__(self, key, /)
| Return self[key].
|
| __getnewargs__(...)
|
| __hash__(self, /)
| Return hash(self).
|
| __iter__(self, /)
| Implement iter(self).
|
| __len__(self, /)
| Return len(self).
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __sizeof__(self, /)
| Return the size of the string in memory, in bytes.
|
| __str__(self, /)
| Return str(self).
|
| capitalize(self, /)
| Return a capitalized version of the string.
|
| More specifically, make the first character have upper case and the rest lower
| case.
|
| casefold(self, /)
| Return a version of the string suitable for caseless comparisons.
|
| center(self, width, fillchar=' ', /)
| Return a centered string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| count(...)
| S.count(sub[, start[, end]]) -> int
|
| Return the number of non-overlapping occurrences of substring sub in
| string S[start:end]. Optional arguments start and end are
| interpreted as in slice notation.
|
| encode(self, /, encoding='utf-8', errors='strict')
| Encode the string using the codec registered for encoding.
|
| encoding
| The encoding in which to encode the string.
| errors
| The error handling scheme to use for encoding errors.
| The default is 'strict' meaning that encoding errors raise a
| UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
|
| endswith(...)
| S.endswith(suffix[, start[, end]]) -> bool
|
| Return True if S ends with the specified suffix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| suffix can also be a tuple of strings to try.
|
| expandtabs(self, /, tabsize=8)
| Return a copy where all tab characters are expanded using spaces.
|
| If tabsize is not given, a tab size of 8 characters is assumed.
|
| find(...)
| S.find(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| format(...)
| S.format(*args, **kwargs) -> str
|
| Return a formatted version of S, using substitutions from args and kwargs.
| The substitutions are identified by braces ('{' and '}').
|
| format_map(...)
| S.format_map(mapping) -> str
|
| Return a formatted version of S, using substitutions from mapping.
| The substitutions are identified by braces ('{' and '}').
|
| index(...)
| S.index(sub[, start[, end]]) -> int
|
| Return the lowest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| isalnum(self, /)
| Return True if the string is an alpha-numeric string, False otherwise.
|
| A string is alpha-numeric if all characters in the string are alpha-numeric and
| there is at least one character in the string.
|
| isalpha(self, /)
| Return True if the string is an alphabetic string, False otherwise.
|
| A string is alphabetic if all characters in the string are alphabetic and there
| is at least one character in the string.
|
| isascii(self, /)
| Return True if all characters in the string are ASCII, False otherwise.
|
| ASCII characters have code points in the range U+0000-U+007F.
| Empty string is ASCII too.
|
| isdecimal(self, /)
| Return True if the string is a decimal string, False otherwise.
|
| A string is a decimal string if all characters in the string are decimal and
| there is at least one character in the string.
|
| isdigit(self, /)
| Return True if the string is a digit string, False otherwise.
|
| A string is a digit string if all characters in the string are digits and there
| is at least one character in the string.
|
| isidentifier(self, /)
| Return True if the string is a valid Python identifier, False otherwise.
|
| Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
| such as "def" or "class".
|
| islower(self, /)
| Return True if the string is a lowercase string, False otherwise.
|
| A string is lowercase if all cased characters in the string are lowercase and
| there is at least one cased character in the string.
|
| isnumeric(self, /)
| Return True if the string is a numeric string, False otherwise.
|
| A string is numeric if all characters in the string are numeric and there is at
| least one character in the string.
|
| isprintable(self, /)
| Return True if the string is printable, False otherwise.
|
| A string is printable if all of its characters are considered printable in
| repr() or if it is empty.
|
| isspace(self, /)
| Return True if the string is a whitespace string, False otherwise.
|
| A string is whitespace if all characters in the string are whitespace and there
| is at least one character in the string.
|
| istitle(self, /)
| Return True if the string is a title-cased string, False otherwise.
|
| In a title-cased string, upper- and title-case characters may only
| follow uncased characters and lowercase characters only cased ones.
|
| isupper(self, /)
| Return True if the string is an uppercase string, False otherwise.
|
| A string is uppercase if all cased characters in the string are uppercase and
| there is at least one cased character in the string.
|
| join(self, iterable, /)
| Concatenate any number of strings.
|
| The string whose method is called is inserted in between each given string.
| The result is returned as a new string.
|
| Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
|
| ljust(self, width, fillchar=' ', /)
| Return a left-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| lower(self, /)
| Return a copy of the string converted to lowercase.
|
| lstrip(self, chars=None, /)
| Return a copy of the string with leading whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| partition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string. If the separator is found,
| returns a 3-tuple containing the part before the separator, the separator
| itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing the original string
| and two empty strings.
|
| removeprefix(self, prefix, /)
| Return a str with the given prefix string removed if present.
|
| If the string starts with the prefix string, return string[len(prefix):].
| Otherwise, return a copy of the original string.
|
| removesuffix(self, suffix, /)
| Return a str with the given suffix string removed if present.
|
| If the string ends with the suffix string and that suffix is not empty,
| return string[:-len(suffix)]. Otherwise, return a copy of the original
| string.
|
| replace(self, old, new, count=-1, /)
| Return a copy with all occurrences of substring old replaced by new.
|
| count
| Maximum number of occurrences to replace.
| -1 (the default value) means replace all occurrences.
|
| If the optional argument count is given, only the first count occurrences are
| replaced.
|
| rfind(...)
| S.rfind(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.
|
| rindex(...)
| S.rindex(sub[, start[, end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within S[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Raises ValueError when the substring is not found.
|
| rjust(self, width, fillchar=' ', /)
| Return a right-justified string of length width.
|
| Padding is done using the specified fill character (default is a space).
|
| rpartition(self, sep, /)
| Partition the string into three parts using the given separator.
|
| This will search for the separator in the string, starting at the end. If
| the separator is found, returns a 3-tuple containing the part before the
| separator, the separator itself, and the part after it.
|
| If the separator is not found, returns a 3-tuple containing two empty strings
| and the original string.
|
| rsplit(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the end of the string and works to the front.
|
| rstrip(self, chars=None, /)
| Return a copy of the string with trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| split(self, /, sep=None, maxsplit=-1)
| Return a list of the substrings in the string, using sep as the separator string.
|
| sep
| The separator used to split the string.
|
| When set to None (the default value), will split on any whitespace
| character (including \n \r \t \f and spaces) and will discard
| empty strings from the result.
| maxsplit
| Maximum number of splits.
| -1 (the default value) means no limit.
|
| Splitting starts at the front of the string and works to the end.
|
| Note, str.split() is mainly useful for data that has been intentionally
| delimited. With natural text that includes punctuation, consider using
| the regular expression module.
|
| splitlines(self, /, keepends=False)
| Return a list of the lines in the string, breaking at line boundaries.
|
| Line breaks are not included in the resulting list unless keepends is given and
| true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(self, chars=None, /)
| Return a copy of the string with leading and trailing whitespace removed.
|
| If chars is given and not None, remove characters in chars instead.
|
| swapcase(self, /)
| Convert uppercase characters to lowercase and lowercase characters to uppercase.
|
| title(self, /)
| Return a version of the string where each word is titlecased.
|
| More specifically, words start with uppercased characters and all remaining
| cased characters have lower case.
|
| translate(self, table, /)
| Replace each character in the string using the given translation table.
|
| table
| Translation table, which must be a mapping of Unicode ordinals to
| Unicode ordinals, strings, or None.
|
| The table must implement lookup/indexing via __getitem__, for instance a
| dictionary or list. If this operation raises LookupError, the character is
| left untouched. Characters mapped to None are deleted.
|
| upper(self, /)
| Return a copy of the string converted to uppercase.
|
| zfill(self, width, /)
| Pad a numeric string with zeros on the left, to fill a field of the given width.
|
| The string is never truncated.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.str:
|
| __new__(*args, **kwargs) class method of builtins.str
| Create and return a new object. See help(type) for accurate signature.
|
| maketrans(...)
| Return a translation table usable for str.translate().
|
| If there is only one argument, it must be a dictionary mapping Unicode
| ordinals (integers) or characters to Unicode ordinals, strings or None.
| Character keys will be then converted to ordinals.
| If there are two arguments, they must be strings of equal length, and
| in the resulting dictionary, each character in x will be mapped to the
| character at the same position in y. If there is a third argument, it
| must be a string, whose characters will be mapped to None in the result.
DATA
__all__ = ['TorchVersion']
VERSION
2.13.0+cpu
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\torch_version.py
torch.trace
Python Library Documentation: built-in function trace in module torch
trace(...)
trace(input) -> Tensor
Returns the sum of the elements of the diagonal of the input 2-D matrix.
Example::
>>> x = torch.arange(1., 10.).view(3, 3)
>>> x
tensor([[ 1., 2., 3.],
[ 4., 5., 6.],
[ 7., 8., 9.]])
>>> torch.trace(x)
tensor(15.)
torch.transpose
Python Library Documentation: built-in function transpose in module torch
transpose(...)
transpose(input, dim0, dim1) -> Tensor
Returns a tensor that is a transposed version of :attr:`input`.
The given dimensions :attr:`dim0` and :attr:`dim1` are swapped.
If :attr:`input` is a strided tensor then the resulting :attr:`out`
tensor shares its underlying storage with the :attr:`input` tensor, so
changing the content of one would change the content of the other.
If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` then the
resulting :attr:`out` tensor *does not* share the underlying storage
with the :attr:`input` tensor.
If :attr:`input` is a :ref:`sparse tensor <sparse-docs>` with compressed
layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments
:attr:`dim0` and :attr:`dim1` must be both batch dimensions, or must
both be sparse dimensions. The batch dimensions of a sparse tensor are the
dimensions preceding the sparse dimensions.
.. note::
Transpositions which interchange the sparse dimensions of a `SparseCSR`
or `SparseCSC` layout tensor will result in the layout changing between
the two options. Transposition of the sparse dimensions of a ` SparseBSR`
or `SparseBSC` layout tensor will likewise generate a result with the
opposite layout.
Args:
input (Tensor): the input tensor.
dim0 (int): the first dimension to be transposed
dim1 (int): the second dimension to be transposed
Example::
>>> x = torch.randn(2, 3)
>>> x
tensor([[ 1.0028, -0.9893, 0.5809],
[-0.1669, 0.7299, 0.4942]])
>>> torch.transpose(x, 0, 1)
tensor([[ 1.0028, -0.1669],
[-0.9893, 0.7299],
[ 0.5809, 0.4942]])
See also :func:`torch.t`.
torch.transpose_copy
Python Library Documentation: built-in function transpose_copy in module torch
transpose_copy(...)
Performs the same operation as :func:`torch.transpose`, but all output tensors
are freshly created instead of aliasing the input.
torch.trapezoid
Python Library Documentation: built-in function trapezoid in module torch
trapezoid(...)
trapezoid(y, x=None, *, dx=None, dim=-1) -> Tensor
Computes the `trapezoidal rule <https://en.wikipedia.org/wiki/Trapezoidal_rule>`_ along
:attr:`dim`. By default the spacing between elements is assumed to be 1, but
:attr:`dx` can be used to specify a different constant spacing, and :attr:`x` can be
used to specify arbitrary spacing along :attr:`dim`. Only one of :attr:`x` or :attr:`dx` should be specified.
Assuming :attr:`y` is a one-dimensional tensor with elements :math:`{y_0, y_1, ..., y_n}`,
the default computation is
.. math::
\begin{aligned}
\sum_{i = 1}^{n} \frac{1}{2} (y_i + y_{i-1})
\end{aligned}
When :attr:`dx` is specified the computation becomes
.. math::
\begin{aligned}
\sum_{i = 1}^{n} \frac{\Delta x}{2} (y_i + y_{i-1})
\end{aligned}
effectively multiplying the result by :attr:`dx`. When :attr:`x` is specified,
assuming :attr:`x` is also a one-dimensional tensor with
elements :math:`{x_0, x_1, ..., x_n}`, the computation becomes
.. math::
\begin{aligned}
\sum_{i = 1}^{n} \frac{(x_i - x_{i-1})}{2} (y_i + y_{i-1})
\end{aligned}
When :attr:`x` and :attr:`y` have the same size, the computation is as described above and no broadcasting is needed.
The broadcasting behavior of this function is as follows when their sizes are different. For both :attr:`x`
and :attr:`y`, the function computes the difference between consecutive elements along
dimension :attr:`dim`. This effectively creates two tensors, `x_diff` and `y_diff`, that have
the same shape as the original tensors except their lengths along the dimension :attr:`dim` is reduced by 1.
After that, those two tensors are broadcast together to compute final output as part of the trapezoidal rule.
See the examples below for details.
.. note::
The trapezoidal rule is a technique for approximating the definite integral of a function
by averaging its left and right Riemann sums. The approximation becomes more accurate as
the resolution of the partition increases.
Arguments:
y (Tensor): Values to use when computing the trapezoidal rule.
x (Tensor): If specified, defines spacing between values as specified above.
Keyword arguments:
dx (float): constant spacing between values. If neither :attr:`x` or :attr:`dx`
are specified then this defaults to 1. Effectively multiplies the result by its value.
dim (int): The dimension along which to compute the trapezoidal rule.
The last (inner-most) dimension by default.
Examples::
>>> # Computes the trapezoidal rule in 1D, spacing is implicitly 1
>>> y = torch.tensor([1, 5, 10])
>>> torch.trapezoid(y)
tensor(10.5)
>>> # Computes the same trapezoidal rule directly to verify
>>> (1 + 10 + 10) / 2
10.5
>>> # Computes the trapezoidal rule in 1D with constant spacing of 2
>>> # NOTE: the result is the same as before, but multiplied by 2
>>> torch.trapezoid(y, dx=2)
21.0
>>> # Computes the trapezoidal rule in 1D with arbitrary spacing
>>> x = torch.tensor([1, 3, 6])
>>> torch.trapezoid(y, x)
28.5
>>> # Computes the same trapezoidal rule directly to verify
>>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2
28.5
>>> # Computes the trapezoidal rule for each row of a 3x3 matrix
>>> y = torch.arange(9).reshape(3, 3)
tensor([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> torch.trapezoid(y)
tensor([ 2., 8., 14.])
>>> # Computes the trapezoidal rule for each column of the matrix
>>> torch.trapezoid(y, dim=0)
tensor([ 6., 8., 10.])
>>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
>>> # with the same arbitrary spacing
>>> y = torch.ones(3, 3)
>>> x = torch.tensor([1, 3, 6])
>>> torch.trapezoid(y, x)
array([5., 5., 5.])
>>> # Computes the trapezoidal rule for each row of a 3x3 ones matrix
>>> # with different arbitrary spacing per row
>>> y = torch.ones(3, 3)
>>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]])
>>> torch.trapezoid(y, x)
array([2., 4., 6.])
torch.trapz
Python Library Documentation: built-in function trapz in module torch
trapz(...)
trapz(y, x=None, *, dim=-1) -> Tensor
Alias for :func:`torch.trapezoid`.
torch.triangular_solve
Python Library Documentation: built-in function triangular_solve in module torch
triangular_solve(...)
triangular_solve(b, A, upper=True, transpose=False, unitriangular=False, *, out=None) -> (Tensor, Tensor)
Solves a system of equations with a square upper or lower triangular invertible matrix :math:`A`
and multiple right-hand sides :math:`b`.
In symbols, it solves :math:`AX = b` and assumes :math:`A` is square upper-triangular
(or lower-triangular if :attr:`upper`\ `= False`) and does not have zeros on the diagonal.
`torch.triangular_solve(b, A)` can take in 2D inputs `b, A` or inputs that are
batches of 2D matrices. If the inputs are batches, then returns
batched outputs `X`
If the diagonal of :attr:`A` contains zeros or elements that are very close to zero and
:attr:`unitriangular`\ `= False` (default) or if the input matrix is badly conditioned,
the result may contain `NaN` s.
Supports input of float, double, cfloat and cdouble data types.
.. warning::
:func:`torch.triangular_solve` is deprecated in favor of :func:`torch.linalg.solve_triangular`
and will be removed in a future PyTorch release.
:func:`torch.linalg.solve_triangular` has its arguments reversed and does not return a
copy of one of the inputs.
``X = torch.triangular_solve(B, A).solution`` should be replaced with
.. code:: python
X = torch.linalg.solve_triangular(A, B)
Args:
b (Tensor): multiple right-hand sides of size :math:`(*, m, k)` where
:math:`*` is zero of more batch dimensions
A (Tensor): the input triangular coefficient matrix of size :math:`(*, m, m)`
where :math:`*` is zero or more batch dimensions
upper (bool, optional): whether :math:`A` is upper or lower triangular. Default: ``True``.
transpose (bool, optional): solves `op(A)X = b` where `op(A) = A^T` if this flag is ``True``,
and `op(A) = A` if it is ``False``. Default: ``False``.
unitriangular (bool, optional): whether :math:`A` is unit triangular.
If True, the diagonal elements of :math:`A` are assumed to be
1 and not referenced from :math:`A`. Default: ``False``.
Keyword args:
out ((Tensor, Tensor), optional): tuple of two tensors to write
the output to. Ignored if `None`. Default: `None`.
Returns:
A namedtuple `(solution, cloned_coefficient)` where `cloned_coefficient`
is a clone of :math:`A` and `solution` is the solution :math:`X` to :math:`AX = b`
(or whatever variant of the system of equations, depending on the keyword arguments.)
Examples::
>>> A = torch.randn(2, 2).triu()
>>> A
tensor([[ 1.1527, -1.0753],
[ 0.0000, 0.7986]])
>>> b = torch.randn(2, 3)
>>> b
tensor([[-0.0210, 2.3513, -1.5492],
[ 1.5429, 0.7403, -1.0243]])
>>> torch.triangular_solve(b, A)
torch.return_types.triangular_solve(
solution=tensor([[ 1.7841, 2.9046, -2.5405],
[ 1.9320, 0.9270, -1.2826]]),
cloned_coefficient=tensor([[ 1.1527, -1.0753],
[ 0.0000, 0.7986]]))
torch.tril
Python Library Documentation: built-in function tril in module torch
tril(...)
tril(input, diagonal=0, *, out=None) -> Tensor
Returns the lower triangular part of the matrix (2-D tensor) or batch of matrices
:attr:`input`, the other elements of the result tensor :attr:`out` are set to 0.
The lower triangular part of the matrix is defined as the elements on and
below the diagonal.
The argument :attr:`diagonal` controls which diagonal to consider. If
:attr:`diagonal` = 0, all elements on and below the main diagonal are
retained. A positive value includes just as many diagonals above the main
diagonal, and similarly a negative value excludes just as many diagonals below
the main diagonal. The main diagonal are the set of indices
:math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]` where
:math:`d_{1}, d_{2}` are the dimensions of the matrix.
Args:
input (Tensor): the input tensor.
diagonal (int, optional): the diagonal to consider
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(3, 3)
>>> a
tensor([[-1.0813, -0.8619, 0.7105],
[ 0.0935, 0.1380, 2.2112],
[-0.3409, -0.9828, 0.0289]])
>>> torch.tril(a)
tensor([[-1.0813, 0.0000, 0.0000],
[ 0.0935, 0.1380, 0.0000],
[-0.3409, -0.9828, 0.0289]])
>>> b = torch.randn(4, 6)
>>> b
tensor([[ 1.2219, 0.5653, -0.2521, -0.2345, 1.2544, 0.3461],
[ 0.4785, -0.4477, 0.6049, 0.6368, 0.8775, 0.7145],
[ 1.1502, 3.2716, -1.1243, -0.5413, 0.3615, 0.6864],
[-0.0614, -0.7344, -1.3164, -0.7648, -1.4024, 0.0978]])
>>> torch.tril(b, diagonal=1)
tensor([[ 1.2219, 0.5653, 0.0000, 0.0000, 0.0000, 0.0000],
[ 0.4785, -0.4477, 0.6049, 0.0000, 0.0000, 0.0000],
[ 1.1502, 3.2716, -1.1243, -0.5413, 0.0000, 0.0000],
[-0.0614, -0.7344, -1.3164, -0.7648, -1.4024, 0.0000]])
>>> torch.tril(b, diagonal=-1)
tensor([[ 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[ 0.4785, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[ 1.1502, 3.2716, 0.0000, 0.0000, 0.0000, 0.0000],
[-0.0614, -0.7344, -1.3164, 0.0000, 0.0000, 0.0000]])
torch.tril_indices
Python Library Documentation: built-in function tril_indices in module torch
tril_indices(...)
tril_indices(row, col, offset=0, *, dtype=torch.long, device='cpu', layout=torch.strided) -> Tensor
Returns the indices of the lower triangular part of a :attr:`row`-by-
:attr:`col` matrix in a 2-by-N Tensor, where the first row contains row
coordinates of all indices and the second row contains column coordinates.
Indices are ordered based on rows and then columns.
The lower triangular part of the matrix is defined as the elements on and
below the diagonal.
The argument :attr:`offset` controls which diagonal to consider. If
:attr:`offset` = 0, all elements on and below the main diagonal are
retained. A positive value includes just as many diagonals above the main
diagonal, and similarly a negative value excludes just as many diagonals below
the main diagonal. The main diagonal are the set of indices
:math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]`
where :math:`d_{1}, d_{2}` are the dimensions of the matrix.
.. note::
When running on CUDA, ``row * col`` must be less than :math:`2^{59}` to
prevent overflow during calculation.
Args:
row (``int``): number of rows in the 2-D matrix.
col (``int``): number of columns in the 2-D matrix.
offset (``int``): diagonal offset from the main diagonal.
Default: if not provided, 0.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor,
only support ``torch.int``, ``torch.long``. Default: if ``None``, ``torch.long``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
layout (:class:`torch.layout`, optional): currently only support ``torch.strided``.
Example::
>>> a = torch.tril_indices(3, 3)
>>> a
tensor([[0, 1, 1, 2, 2, 2],
[0, 0, 1, 0, 1, 2]])
>>> a = torch.tril_indices(4, 3, -1)
>>> a
tensor([[1, 2, 2, 3, 3, 3],
[0, 0, 1, 0, 1, 2]])
>>> a = torch.tril_indices(4, 3, 1)
>>> a
tensor([[0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3],
[0, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2]])
torch.triplet_margin_loss
Python Library Documentation: built-in function triplet_margin_loss in module torch triplet_margin_loss(...)
torch.triu
Python Library Documentation: built-in function triu in module torch
triu(...)
triu(input, diagonal=0, *, out=None) -> Tensor
Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices
:attr:`input`, the other elements of the result tensor :attr:`out` are set to 0.
The upper triangular part of the matrix is defined as the elements on and
above the diagonal.
The argument :attr:`diagonal` controls which diagonal to consider. If
:attr:`diagonal` = 0, all elements on and above the main diagonal are
retained. A positive value excludes just as many diagonals above the main
diagonal, and similarly a negative value includes just as many diagonals below
the main diagonal. The main diagonal are the set of indices
:math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]` where
:math:`d_{1}, d_{2}` are the dimensions of the matrix.
Args:
input (Tensor): the input tensor.
diagonal (int, optional): the diagonal to consider
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(3, 3)
>>> a
tensor([[ 0.2309, 0.5207, 2.0049],
[ 0.2072, -1.0680, 0.6602],
[ 0.3480, -0.5211, -0.4573]])
>>> torch.triu(a)
tensor([[ 0.2309, 0.5207, 2.0049],
[ 0.0000, -1.0680, 0.6602],
[ 0.0000, 0.0000, -0.4573]])
>>> torch.triu(a, diagonal=1)
tensor([[ 0.0000, 0.5207, 2.0049],
[ 0.0000, 0.0000, 0.6602],
[ 0.0000, 0.0000, 0.0000]])
>>> torch.triu(a, diagonal=-1)
tensor([[ 0.2309, 0.5207, 2.0049],
[ 0.2072, -1.0680, 0.6602],
[ 0.0000, -0.5211, -0.4573]])
>>> b = torch.randn(4, 6)
>>> b
tensor([[ 0.5876, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
[-0.2447, 0.9556, -1.2919, 1.3378, -0.1768, -1.0857],
[ 0.4333, 0.3146, 0.6576, -1.0432, 0.9348, -0.4410],
[-0.9888, 1.0679, -1.3337, -1.6556, 0.4798, 0.2830]])
>>> torch.triu(b, diagonal=1)
tensor([[ 0.0000, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
[ 0.0000, 0.0000, -1.2919, 1.3378, -0.1768, -1.0857],
[ 0.0000, 0.0000, 0.0000, -1.0432, 0.9348, -0.4410],
[ 0.0000, 0.0000, 0.0000, 0.0000, 0.4798, 0.2830]])
>>> torch.triu(b, diagonal=-1)
tensor([[ 0.5876, -0.0794, -1.8373, 0.6654, 0.2604, 1.5235],
[-0.2447, 0.9556, -1.2919, 1.3378, -0.1768, -1.0857],
[ 0.0000, 0.3146, 0.6576, -1.0432, 0.9348, -0.4410],
[ 0.0000, 0.0000, -1.3337, -1.6556, 0.4798, 0.2830]])
torch.triu_indices
Python Library Documentation: built-in function triu_indices in module torch
triu_indices(...)
triu_indices(row, col, offset=0, *, dtype=torch.long, device='cpu', layout=torch.strided) -> Tensor
Returns the indices of the upper triangular part of a :attr:`row` by
:attr:`col` matrix in a 2-by-N Tensor, where the first row contains row
coordinates of all indices and the second row contains column coordinates.
Indices are ordered based on rows and then columns.
The upper triangular part of the matrix is defined as the elements on and
above the diagonal.
The argument :attr:`offset` controls which diagonal to consider. If
:attr:`offset` = 0, all elements on and above the main diagonal are
retained. A positive value excludes just as many diagonals above the main
diagonal, and similarly a negative value includes just as many diagonals below
the main diagonal. The main diagonal are the set of indices
:math:`\lbrace (i, i) \rbrace` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]`
where :math:`d_{1}, d_{2}` are the dimensions of the matrix.
.. note::
When running on CUDA, ``row * col`` must be less than :math:`2^{59}` to
prevent overflow during calculation.
Args:
row (``int``): number of rows in the 2-D matrix.
col (``int``): number of columns in the 2-D matrix.
offset (``int``): diagonal offset from the main diagonal.
Default: if not provided, 0.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor,
only support ``torch.int``, ``torch.long``. Default: if ``None``, ``torch.long``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
layout (:class:`torch.layout`, optional): currently only support ``torch.strided``.
Example::
>>> a = torch.triu_indices(3, 3)
>>> a
tensor([[0, 0, 0, 1, 1, 2],
[0, 1, 2, 1, 2, 2]])
>>> a = torch.triu_indices(4, 3, -1)
>>> a
tensor([[0, 0, 0, 1, 1, 1, 2, 2, 3],
[0, 1, 2, 0, 1, 2, 1, 2, 2]])
>>> a = torch.triu_indices(4, 3, 1)
>>> a
tensor([[0, 0, 1],
[1, 2, 2]])
torch.true_divide
Python Library Documentation: built-in function true_divide in module torch
true_divide(...)
true_divide(dividend, divisor, *, out) -> Tensor
Alias for :func:`torch.div` with ``rounding_mode=None``.
torch.trunc
Python Library Documentation: built-in function trunc in module torch
trunc(...)
trunc(input, *, out=None) -> Tensor
Returns a new tensor with the truncated integer values of
the elements of :attr:`input`.
For integer inputs, follows the array-api convention of returning a
copy of the input tensor.
Args:
input (Tensor): the input tensor.
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.randn(4)
>>> a
tensor([ 3.4742, 0.5466, -0.8008, -0.9079])
>>> torch.trunc(a)
tensor([ 3., 0., -0., -0.])
torch.trunc_
Python Library Documentation: built-in function trunc_ in module torch trunc_(...)
torch.typename
Python Library Documentation: function typename in module torch
typename(obj: Any, /) -> str
String representation of the type of an object.
This function returns a fully qualified string representation of an object's type.
Args:
obj (object): The object whose type to represent
Returns:
str: the type of the object `o`
Example:
>>> x = torch.tensor([1, 2, 3])
>>> torch.typename(x)
'torch.LongTensor'
>>> torch.typename(torch.nn.Parameter)
'torch.nn.parameter.Parameter'
torch.types
Python Library Documentation: module torch.types in torch
NAME
torch.types
DESCRIPTION
# In some cases, these basic types are shadowed by corresponding
# top-level values. The underscore variants let us refer to these
# types. See https://github.com/python/mypy/issues/4146 for why these
# workarounds is necessary
CLASSES
builtins.object
Storage
class Storage(builtins.object)
| # Storage protocol implemented by ${Type}StorageBase classes
|
| Methods defined here:
|
| __deepcopy__(self, memo: dict[int, typing.Any]) -> Self
|
| cpu(self) -> Self
|
| data_ptr(self) -> int
|
| element_size(self) -> int
|
| from_file(self, filename: str, shared: bool = False, nbytes: int = 0) -> Self
|
| is_shared(self) -> bool
|
| nbytes(self) -> int
|
| share_memory_(self) -> Self
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'_cdata': <class 'int'>, '_torch_load_uninitialized...
DATA
Device = torch.device | str | int | None
FileLike = typing.Union[str, os.PathLike[str], typing.IO[bytes]]
Number = int | float | bool
__all__ = ['Number', 'Device', 'FileLike', 'Storage']
__annotations__ = {'BoolLikeType': typing.TypeAlias, 'Device': typing....
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\types.py
torch.uint1
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.uint16
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.uint2
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.uint3
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.uint32
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.uint4
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.uint5
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.uint6
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.uint64
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.uint7
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.uint8
Python Library Documentation: dtype in module torch object class dtype(builtins.object) | Methods defined here: | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | to_complex(...) | | to_real(...) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | abbr | | is_complex | | is_floating_point | | is_signed | | itemsize
torch.unbind
Python Library Documentation: built-in function unbind in module torch
unbind(...)
unbind(input, dim=0) -> seq
Removes a tensor dimension.
Returns a tuple of all slices along a given dimension, already without it.
Arguments:
input (Tensor): the tensor to unbind
dim (int): dimension to remove
Example::
>>> torch.unbind(torch.tensor([[1, 2, 3],
>>> [4, 5, 6],
>>> [7, 8, 9]]))
(tensor([1, 2, 3]), tensor([4, 5, 6]), tensor([7, 8, 9]))
torch.unbind_copy
Python Library Documentation: built-in function unbind_copy in module torch
unbind_copy(...)
Performs the same operation as :func:`torch.unbind`, but all output tensors
are freshly created instead of aliasing the input.
torch.unflatten
Python Library Documentation: built-in function unflatten in module torch
unflatten(...)
unflatten(input, dim, sizes) -> Tensor
Expands a dimension of the input tensor over multiple dimensions.
.. seealso::
:func:`torch.flatten` the inverse of this function. It coalesces several dimensions into one.
Args:
input (Tensor): the input tensor.
dim (int): Dimension to be unflattened, specified as an index into
``input.shape``.
sizes (Tuple[int]): New shape of the unflattened dimension.
One of its elements can be `-1` in which case the corresponding output
dimension is inferred. Otherwise, the product of ``sizes`` *must*
equal ``input.shape[dim]``.
Returns:
A View of input with the specified dimension unflattened.
Examples::
>>> torch.unflatten(torch.randn(3, 4, 1), 1, (2, 2)).shape
torch.Size([3, 2, 2, 1])
>>> torch.unflatten(torch.randn(3, 4, 1), 1, (-1, 2)).shape
torch.Size([3, 2, 2, 1])
>>> torch.unflatten(torch.randn(5, 12, 3), -2, (2, 2, 3, 1, 1)).shape
torch.Size([5, 2, 2, 3, 1, 1, 3])
torch.unfold_copy
Python Library Documentation: built-in function unfold_copy in module torch
unfold_copy(...)
Performs the same operation as :func:`torch.unfold`, but all output tensors
are freshly created instead of aliasing the input.
torch.unify_type_list
Python Library Documentation: built-in function unify_type_list in module torch
unify_type_list(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
unify_type_list(arg0: collections.abc.Sequence[c10::Type]) -> c10::Type
torch.unique
Python Library Documentation: function unique in module torch.functional
unique(*args, **kwargs)
unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None) -> tuple[Tensor, Tensor, Tensor]
Returns the unique elements of the input tensor.
.. note:: This function is different from :func:`torch.unique_consecutive` in the sense that
this function also eliminates non-consecutive duplicate values.
.. note:: Currently in the CUDA implementation and the CPU implementation,
`torch.unique` always sort the tensor at the beginning regardless of the `sort` argument.
Sorting could be slow, so if your input tensor is already sorted, it is recommended to use
:func:`torch.unique_consecutive` which avoids the sorting.
Args:
input (Tensor): the input tensor
sorted (bool): Whether to sort the unique elements in ascending order
before returning as output.
return_inverse (bool): Whether to also return the indices for where
elements in the original input ended up in the returned unique list.
return_counts (bool): Whether to also return the counts for each unique
element.
dim (int, optional): the dimension to operate upon. If ``None``, the
unique of the flattened input is returned. Otherwise, each of the
tensors indexed by the given dimension is treated as one of the
elements to apply the unique operation upon. **Important:** when ``dim``
is specified, the operation finds unique sub-tensors (e.g., unique rows
or columns), not unique scalar values. This means individual values may
appear multiple times in the output if they exist in different sub-tensors.
See examples for more details. Default: ``None``
Returns:
(Tensor, Tensor (optional), Tensor (optional)): A tensor or a tuple of tensors containing
- **output** (*Tensor*): the output list of unique scalar elements if :attr:`dim`
is ``None``; otherwise, the unique sub-tensors along the specified dimension.
Note that when :attr:`dim` is specified, scalar values may repeat in the output.
- **inverse_indices** (*Tensor*): (optional) if
:attr:`return_inverse` is True, there will be an additional
returned tensor (same shape as input) representing the indices
for where elements in the original input map to in the output;
otherwise, this function will only return a single tensor.
- **counts** (*Tensor*): (optional) if
:attr:`return_counts` is True, there will be an additional
returned tensor (same shape as output or output.size(dim),
if dim was specified) representing the number of occurrences
for each unique value or tensor.
Example::
>>> output = torch.unique(torch.tensor([1, 3, 2, 3], dtype=torch.long))
>>> output
tensor([1, 2, 3])
>>> output, inverse_indices = torch.unique(
... torch.tensor([1, 3, 2, 3], dtype=torch.long), sorted=True, return_inverse=True)
>>> output
tensor([1, 2, 3])
>>> inverse_indices
tensor([0, 2, 1, 2])
>>> output, inverse_indices = torch.unique(
... torch.tensor([[1, 3], [2, 3]], dtype=torch.long), sorted=True, return_inverse=True)
>>> output
tensor([1, 2, 3])
>>> inverse_indices
tensor([[0, 2],
[1, 2]])
>>> # When using dim, the operation finds unique sub-tensors, not unique values.
>>> # Notice how values can repeat in the output:
>>> x = torch.tensor([[1, 3, 2, 3], [1, 2, 1, 2]], dtype=torch.long)
>>> torch.unique(x, dim=0) # unique rows
tensor([[1, 2, 1, 2],
[1, 3, 2, 3]])
>>> # Both rows are kept because they're different from each other,
>>> # even though values 1, 2, 3 appear multiple times in the output.
>>> torch.unique(x, dim=1) # unique columns
tensor([[1, 2, 3],
[1, 1, 2]])
>>> # The value 1 appears twice because we're comparing columns, not values.
>>> # Compare with flattened (no dim):
>>> torch.unique(x)
tensor([1, 2, 3])
>>> a = torch.tensor([
... [
... [1, 1, 0, 0],
... [1, 1, 0, 0],
... [0, 0, 1, 1],
... ],
... [
... [0, 0, 1, 1],
... [0, 0, 1, 1],
... [1, 1, 1, 1],
... ],
... [
... [1, 1, 0, 0],
... [1, 1, 0, 0],
... [0, 0, 1, 1],
... ],
... ])
>>> # If we call `torch.unique(a, dim=0)`, each of the tensors `a[idx, :, :]`
>>> # will be compared. We can see that `a[0, :, :]` and `a[2, :, :]` match
>>> # each other, so one of them will be removed.
>>> (a[0, :, :] == a[2, :, :]).all()
tensor(True)
>>> a_unique_dim0 = torch.unique(a, dim=0)
>>> a_unique_dim0
tensor([[[0, 0, 1, 1],
[0, 0, 1, 1],
[1, 1, 1, 1]],
[[1, 1, 0, 0],
[1, 1, 0, 0],
[0, 0, 1, 1]]])
>>> # Notice which sub-tensors from `a` match with the sub-tensors from
>>> # `a_unique_dim0`:
>>> (a_unique_dim0[0, :, :] == a[1, :, :]).all()
tensor(True)
>>> (a_unique_dim0[1, :, :] == a[0, :, :]).all()
tensor(True)
>>> # For `torch.unique(a, dim=1)`, each of the tensors `a[:, idx, :]` are
>>> # compared. `a[:, 0, :]` and `a[:, 1, :]` match each other, so one of
>>> # them will be removed.
>>> (a[:, 0, :] == a[:, 1, :]).all()
tensor(True)
>>> torch.unique(a, dim=1)
tensor([[[0, 0, 1, 1],
[1, 1, 0, 0]],
[[1, 1, 1, 1],
[0, 0, 1, 1]],
[[0, 0, 1, 1],
[1, 1, 0, 0]]])
>>> # For `torch.unique(a, dim=2)`, the tensors `a[:, :, idx]` are compared.
>>> # `a[:, :, 0]` and `a[:, :, 1]` match each other. Also, `a[:, :, 2]` and
>>> # `a[:, :, 3]` match each other as well. So in this case, two of the
>>> # sub-tensors will be removed.
>>> (a[:, :, 0] == a[:, :, 1]).all()
tensor(True)
>>> (a[:, :, 2] == a[:, :, 3]).all()
tensor(True)
>>> torch.unique(a, dim=2)
tensor([[[0, 1],
[0, 1],
[1, 0]],
[[1, 0],
[1, 0],
[1, 1]],
[[0, 1],
[0, 1],
[1, 0]]])
torch.unique_consecutive
Python Library Documentation: function unique_consecutive in module torch.functional
unique_consecutive(*args, **kwargs)
Eliminates all but the first element from every consecutive group of equivalent elements.
.. note:: This function is different from :func:`torch.unique` in the sense that this function
only eliminates consecutive duplicate values. This semantics is similar to `std::unique`
in C++.
Args:
input (Tensor): the input tensor
return_inverse (bool): Whether to also return the indices for where
elements in the original input ended up in the returned unique list.
return_counts (bool): Whether to also return the counts for each unique
element.
dim (int): the dimension to apply unique. If ``None``, the unique of the
flattened input is returned. default: ``None``
Returns:
(Tensor, Tensor (optional), Tensor (optional)): A tensor or a tuple of tensors containing
- **output** (*Tensor*): the output list of unique scalar elements.
- **inverse_indices** (*Tensor*): (optional) if
:attr:`return_inverse` is True, there will be an additional
returned tensor (same shape as input) representing the indices
for where elements in the original input map to in the output;
otherwise, this function will only return a single tensor.
- **counts** (*Tensor*): (optional) if
:attr:`return_counts` is True, there will be an additional
returned tensor (same shape as output or output.size(dim),
if dim was specified) representing the number of occurrences
for each unique value or tensor.
Example::
>>> x = torch.tensor([1, 1, 2, 2, 3, 1, 1, 2])
>>> output = torch.unique_consecutive(x)
>>> output
tensor([1, 2, 3, 1, 2])
>>> output, inverse_indices = torch.unique_consecutive(x, return_inverse=True)
>>> output
tensor([1, 2, 3, 1, 2])
>>> inverse_indices
tensor([0, 0, 1, 1, 2, 3, 3, 4])
>>> output, counts = torch.unique_consecutive(x, return_counts=True)
>>> output
tensor([1, 2, 3, 1, 2])
>>> counts
tensor([2, 2, 1, 2, 1])
torch.unravel_index
Python Library Documentation: function unravel_index in module torch.functional
unravel_index(indices: torch.Tensor, shape: int | collections.abc.Sequence[int] | torch.Size) -> tuple[torch.Tensor, ...]
Converts a tensor of flat indices into a tuple of coordinate tensors that
index into an arbitrary tensor of the specified shape.
Args:
indices (Tensor): An integer tensor containing indices into the
flattened version of an arbitrary tensor of shape :attr:`shape`.
All elements must be in the range ``[0, prod(shape) - 1]``.
shape (int, sequence of ints, or torch.Size): The shape of the arbitrary
tensor. All elements must be non-negative.
Returns:
tuple of Tensors: Each ``i``-th tensor in the output corresponds with
dimension ``i`` of :attr:`shape`. Each tensor has the same shape as
``indices`` and contains one index into dimension ``i`` for each of the
flat indices given by ``indices``.
Example::
>>> import torch
>>> torch.unravel_index(torch.tensor(4), (3, 2))
(tensor(2),
tensor(0))
>>> torch.unravel_index(torch.tensor([4, 1]), (3, 2))
(tensor([2, 0]),
tensor([0, 1]))
>>> torch.unravel_index(torch.tensor([0, 1, 2, 3, 4, 5]), (3, 2))
(tensor([0, 0, 1, 1, 2, 2]),
tensor([0, 1, 0, 1, 0, 1]))
>>> torch.unravel_index(torch.tensor([1234, 5678]), (10, 10, 10, 10))
(tensor([1, 5]),
tensor([2, 6]),
tensor([3, 7]),
tensor([4, 8]))
>>> torch.unravel_index(torch.tensor([[1234], [5678]]), (10, 10, 10, 10))
(tensor([[1], [5]]),
tensor([[2], [6]]),
tensor([[3], [7]]),
tensor([[4], [8]]))
>>> torch.unravel_index(torch.tensor([[1234], [5678]]), (100, 100))
(tensor([[12], [56]]),
tensor([[34], [78]]))
torch.unsafe_chunk
Python Library Documentation: built-in function unsafe_chunk in module torch
unsafe_chunk(...)
unsafe_chunk(input, chunks, dim=0) -> List of Tensors
Works like :func:`torch.chunk` but without enforcing the autograd restrictions
on inplace modification of the outputs.
.. warning::
This function is safe to use as long as only the input, or only the outputs
are modified inplace after calling this function. It is user's
responsibility to ensure that is the case. If both the input and one or more
of the outputs are modified inplace, gradients computed by autograd will be
silently incorrect.
torch.unsafe_split
Python Library Documentation: built-in function unsafe_split in module torch
unsafe_split(...)
unsafe_split(tensor, split_size_or_sections, dim=0) -> List of Tensors
Works like :func:`torch.split` but without enforcing the autograd restrictions
on inplace modification of the outputs.
.. warning::
This function is safe to use as long as only the input, or only the outputs
are modified inplace after calling this function. It is user's
responsibility to ensure that is the case. If both the input and one or more
of the outputs are modified inplace, gradients computed by autograd will be
silently incorrect.
torch.unsafe_split_with_sizes
Python Library Documentation: built-in function unsafe_split_with_sizes in module torch unsafe_split_with_sizes(...)
torch.unsqueeze
Python Library Documentation: built-in function unsqueeze in module torch
unsqueeze(...)
unsqueeze(input, dim) -> Tensor
Returns a new tensor with a dimension of size one inserted at the
specified position.
The returned tensor shares the same underlying data with this tensor.
A :attr:`dim` value within the range ``[-input.dim() - 1, input.dim() + 1)``
can be used. Negative :attr:`dim` will correspond to :meth:`unsqueeze`
applied at :attr:`dim` = ``dim + input.dim() + 1``.
Args:
input (Tensor): the input tensor.
dim (int): the index at which to insert the singleton dimension
Example::
>>> x = torch.tensor([1, 2, 3, 4])
>>> torch.unsqueeze(x, 0)
tensor([[ 1, 2, 3, 4]])
>>> torch.unsqueeze(x, 1)
tensor([[ 1],
[ 2],
[ 3],
[ 4]])
torch.unsqueeze_copy
Python Library Documentation: built-in function unsqueeze_copy in module torch
unsqueeze_copy(...)
Performs the same operation as :func:`torch.unsqueeze`, but all output tensors
are freshly created instead of aliasing the input.
torch.use_deterministic_algorithms
Python Library Documentation: function use_deterministic_algorithms in module torch
use_deterministic_algorithms(mode: bool, *, warn_only: bool = False) -> None
Sets whether PyTorch operations must use "deterministic"
algorithms. That is, algorithms which, given the same input, and when
run on the same software and hardware, always produce the same output.
When enabled, operations will use deterministic algorithms when available,
and if only nondeterministic algorithms are available they will throw a
:class:`RuntimeError` when called.
.. note:: This setting alone is not always enough to make an application
reproducible. Refer to :ref:`reproducibility` for more information.
.. note:: :func:`torch.set_deterministic_debug_mode` offers an alternative
interface for this feature.
The following normally-nondeterministic operations will act
deterministically when ``mode=True``:
* :class:`torch.nn.Conv1d` when called on CUDA tensor
* :class:`torch.nn.Conv2d` when called on CUDA tensor
* :class:`torch.nn.Conv3d` when called on CUDA tensor
* :class:`torch.nn.ConvTranspose1d` when called on CUDA tensor
* :class:`torch.nn.ConvTranspose2d` when called on CUDA tensor
* :class:`torch.nn.ConvTranspose3d` when called on CUDA tensor
* :class:`torch.nn.ReplicationPad1d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.ReplicationPad2d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.ReplicationPad3d` when attempting to differentiate a CUDA tensor
* :func:`torch.bmm` when called on sparse-dense CUDA tensors
* :func:`torch.Tensor.__getitem__` when attempting to differentiate a CPU tensor
and the index is a list of tensors
* :func:`torch.Tensor.index_put` with ``accumulate=False``
* :func:`torch.Tensor.index_put` with ``accumulate=True`` when called on a CPU
tensor
* :func:`torch.Tensor.put_` with ``accumulate=True`` when called on a CPU
tensor
* :func:`torch.Tensor.scatter_add_` when called on a CUDA tensor
* :func:`torch.gather` when called on a CUDA tensor that requires grad
* :func:`torch.index_add` when called on CUDA tensor
* :func:`torch.index_select` when attempting to differentiate a CUDA tensor
* :func:`torch.repeat_interleave` when attempting to differentiate a CUDA tensor
* :func:`torch.Tensor.index_copy` when called on a CPU or CUDA tensor
* :func:`torch.Tensor.scatter` when `src` type is Tensor and called on CUDA tensor
* :func:`torch.Tensor.scatter_reduce` when ``reduce='sum'`` or ``reduce='mean'`` and called on CUDA tensor
* :class:`torch.nn.MaxPool3d` when attempting to differentiate a CUDA tensor
The following normally-nondeterministic operations will throw a
:class:`RuntimeError` when ``mode=True``:
* :class:`torch.nn.AvgPool3d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.AdaptiveAvgPool2d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.AdaptiveAvgPool3d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.AdaptiveMaxPool2d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.FractionalMaxPool2d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.FractionalMaxPool3d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.MaxUnpool1d`
* :class:`torch.nn.MaxUnpool2d`
* :class:`torch.nn.MaxUnpool3d`
* :func:`torch.nn.functional.interpolate` when attempting to differentiate a CUDA tensor
and one of the following modes is used:
- ``linear``
- ``bilinear``
- ``bicubic``
- ``trilinear``
* :class:`torch.nn.ReflectionPad1d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.ReflectionPad2d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.ReflectionPad3d` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.NLLLoss` when called on a CUDA tensor
* :class:`torch.nn.CTCLoss` when attempting to differentiate a CUDA tensor
* :class:`torch.nn.EmbeddingBag` when attempting to differentiate a CUDA tensor when
``mode='max'``
* :func:`torch.Tensor.put_` when ``accumulate=False``
* :func:`torch.Tensor.put_` when ``accumulate=True`` and called on a CUDA tensor
* :func:`torch.histc` when called on a CUDA tensor
* :func:`torch.bincount` when called on a CUDA tensor and ``weights``
tensor is given
* :func:`torch.median` with indices output when called on a CUDA tensor
* :func:`torch.nn.functional.grid_sample` when attempting to differentiate a CUDA tensor
* :func:`torch.cumsum` when called on a CUDA tensor when dtype is floating point or complex
* :func:`torch.Tensor.scatter_reduce` when ``reduce='prod'`` and called on CUDA tensor
* :func:`torch.Tensor.resize_` when called with a quantized tensor
In addition, several operations fill uninitialized memory when this setting
is turned on and when
:attr:`torch.utils.deterministic.fill_uninitialized_memory` is turned on.
See the documentation for that attribute for more information.
Note that deterministic operations tend to have worse performance than
nondeterministic operations.
When this setting is turned on, the Inductor deterministic mode is also tuned on
automatically. In deterministic mode, Inductor would avoid doing on device benchmarking
that affect numerics. This includes:
- don't pad matmul input shapes. Without enabling deterministic mode, Inductor would do
benchmarking to check if padding matmul shape is beneficial.
- don't autotune templates. Inductor has templates for kernels like matmul/conv/attention.
Without enabling deterministic mode, Inductor would do autotuning to
pick the best configs for those templates and adopt it if it's faster
than the kernel in eager mode. In deterministic mode, we pick the eager kernel.
- don't autotune triton configs for reduction. Reduction numerics are
very sensitive to triton configs. In deterministic mode, Inductor
will use some heuristics to pick the most promising configs rather
than do autotuning.
- Skip autotuning for reduction in coordinate descent tuning.
- Don't benchmark for the computation/communication reordering pass
- Disable the feature that dynamically scale down RBLOCK triton config for higher
occupancy.
.. note::
This flag does not detect or prevent nondeterministic behavior caused
by calling an inplace operation on a tensor with an internal memory
overlap or by giving such a tensor as the :attr:`out` argument for an
operation. In these cases, multiple writes of different data may target
a single memory location, and the order of writes is not guaranteed.
Args:
mode (:class:`bool`): If True, makes potentially nondeterministic
operations switch to a deterministic algorithm or throw a runtime
error. If False, allows nondeterministic operations.
Keyword args:
warn_only (:class:`bool`, optional): If True, operations that do not
have a deterministic implementation will throw a warning instead of
an error. Default: ``False``
Example::
>>> # xdoctest: +SKIP
>>> torch.use_deterministic_algorithms(True)
# Backward mode nondeterministic error
>>> torch.nn.AvgPool3d(1)(torch.randn(3, 4, 5, 6, requires_grad=True).cuda()).sum().backward()
...
RuntimeError: avg_pool3d_backward_cuda does not have a deterministic implementation...
torch.utils
Python Library Documentation: package torch.utils in torch
NAME
torch.utils - # mypy: allow-untyped-defs
PACKAGE CONTENTS
_appending_byte_serializer
_config_module
_content_store
_contextlib
_cpp_embed_headers
_cpp_extension_versioner
_cuda_debug
_cxx_pytree
_debug_mode (package)
_device
_dtype_abbrs
_exposed_in
_filelock
_foreach_utils
_functools
_get_clean_triton
_helion
_import_utils
_inspect
_mode_utils
_ordered_set
_pallas
_python_dispatch
_pytree
_runtime_estimation
_stats
_strobelight (package)
_sympy (package)
_thunk
_traceback
_triton
_typing_utils
_zip
backcompat (package)
backend_registration
benchmark (package)
bundled_inputs
checkpoint
collect_env
cpp_backtrace
cpp_extension
data (package)
debug_log
deterministic
dlpack
file_baton
flop_counter
hipify (package)
hooks
jit (package)
mkldnn
mobile_optimizer
model_dump (package)
model_zoo
module_tracker
serialization (package)
show_pickle
tensorboard (package)
throughput_benchmark
viz (package)
weak
FUNCTIONS
set_module(obj, mod)
Set the module attribute on a python object for a given object for nicer printing
swap_tensors(t1, t2)
This function swaps the content of the two Tensor objects.
At a high level, this will make t1 have the content of t2 while preserving
its identity.
This will not work if t1 and t2 have different slots.
DATA
cmake_prefix_path = r'C:\Users\Youse\AppData\Local\Programs\Python\Pyt...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\utils\__init__.py
torch.values_copy
Python Library Documentation: built-in function values_copy in module torch
values_copy(...)
Performs the same operation as :func:`torch.values`, but all output tensors
are freshly created instead of aliasing the input.
torch.vander
Python Library Documentation: built-in function vander in module torch
vander(...)
vander(x, N=None, increasing=False) -> Tensor
Generates a Vandermonde matrix.
The columns of the output matrix are elementwise powers of the input vector :math:`x^{(N-1)}, x^{(N-2)}, ..., x^0`.
If increasing is True, the order of the columns is reversed :math:`x^0, x^1, ..., x^{(N-1)}`. Such a
matrix with a geometric progression in each row is named for Alexandre-Theophile Vandermonde.
Arguments:
x (Tensor): 1-D input tensor.
N (int, optional): Number of columns in the output. If N is not specified,
a square array is returned :math:`(N = len(x))`.
increasing (bool, optional): Order of the powers of the columns. If True,
the powers increase from left to right, if False (the default) they are reversed.
Returns:
Tensor: Vandermonde matrix. If increasing is False, the first column is :math:`x^{(N-1)}`,
the second :math:`x^{(N-2)}` and so forth. If increasing is True, the columns
are :math:`x^0, x^1, ..., x^{(N-1)}`.
Example::
>>> x = torch.tensor([1, 2, 3, 5])
>>> torch.vander(x)
tensor([[ 1, 1, 1, 1],
[ 8, 4, 2, 1],
[ 27, 9, 3, 1],
[125, 25, 5, 1]])
>>> torch.vander(x, N=3)
tensor([[ 1, 1, 1],
[ 4, 2, 1],
[ 9, 3, 1],
[25, 5, 1]])
>>> torch.vander(x, N=3, increasing=True)
tensor([[ 1, 1, 1],
[ 1, 2, 4],
[ 1, 3, 9],
[ 1, 5, 25]])
torch.var
Python Library Documentation: built-in function var in module torch
var(...)
var(input, dim=None, *, correction=1, keepdim=False, out=None) -> Tensor
Calculates the variance over the dimensions specified by :attr:`dim`. :attr:`dim`
can be a single dimension, list of dimensions, or ``None`` to reduce over all
dimensions.
The variance (:math:`\sigma^2`) is calculated as
.. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
sample mean, :math:`N` is the number of samples and :math:`\delta N` is
the :attr:`correction`.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
Keyword args:
correction (int): difference between the sample size and sample degrees of freedom.
Defaults to `Bessel's correction`_, ``correction=1``.
.. versionchanged:: 2.0
Previously this argument was called ``unbiased`` and was a boolean
with ``True`` corresponding to ``correction=1`` and ``False`` being
``correction=0``.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
out (Tensor, optional): the output tensor.
Example:
>>> a = torch.tensor(
... [[ 0.2035, 1.2959, 1.8101, -0.4644],
... [ 1.5027, -0.3270, 0.5905, 0.6538],
... [-1.5745, 1.3330, -0.5596, -0.6548],
... [ 0.1264, -0.5080, 1.6420, 0.1992]]
... ) # fmt: skip
>>> torch.var(a, dim=1, keepdim=True)
tensor([[1.0631],
[0.5590],
[1.4893],
[0.8258]])
.. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
torch.var_mean
Python Library Documentation: built-in function var_mean in module torch
var_mean(...)
var_mean(input, dim=None, *, correction=1, keepdim=False, out=None) -> (Tensor, Tensor)
Calculates the variance and mean over the dimensions specified by :attr:`dim`.
:attr:`dim` can be a single dimension, list of dimensions, or ``None`` to
reduce over all dimensions.
The variance (:math:`\sigma^2`) is calculated as
.. math:: \sigma^2 = \frac{1}{\max(0,~N - \delta N)}\sum_{i=0}^{N-1}(x_i-\bar{x})^2
where :math:`x` is the sample set of elements, :math:`\bar{x}` is the
sample mean, :math:`N` is the number of samples and :math:`\delta N` is
the :attr:`correction`.
If :attr:`keepdim` is ``True``, the output tensor is of the same size
as :attr:`input` except in the dimension(s) :attr:`dim` where it is of size 1.
Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting in the
output tensor having 1 (or ``len(dim)``) fewer dimension(s).
Args:
input (Tensor): the input tensor.
dim (int or tuple of ints, optional): the dimension or dimensions to reduce.
If ``None``, all dimensions are reduced.
Keyword args:
correction (int): difference between the sample size and sample degrees of freedom.
Defaults to `Bessel's correction`_, ``correction=1``.
.. versionchanged:: 2.0
Previously this argument was called ``unbiased`` and was a boolean
with ``True`` corresponding to ``correction=1`` and ``False`` being
``correction=0``.
keepdim (bool, optional): whether the output tensor has :attr:`dim` retained or not. Default: ``False``.
out (Tensor, optional): the output tensor.
Returns:
A tuple (var, mean) containing the variance and mean.
Example:
>>> a = torch.tensor(
... [[ 0.2035, 1.2959, 1.8101, -0.4644],
... [ 1.5027, -0.3270, 0.5905, 0.6538],
... [-1.5745, 1.3330, -0.5596, -0.6548],
... [ 0.1264, -0.5080, 1.6420, 0.1992]]
... ) # fmt: skip
>>> torch.var_mean(a, dim=0, keepdim=True)
(tensor([[1.5926, 1.0056, 1.2005, 0.3646]]),
tensor([[ 0.0645, 0.4485, 0.8707, -0.0665]]))
.. _Bessel's correction: https://en.wikipedia.org/wiki/Bessel%27s_correction
torch.vdot
Python Library Documentation: built-in function vdot in module torch
vdot(...)
vdot(input, other, *, out=None) -> Tensor
Computes the dot product of two 1D vectors along a dimension.
In symbols, this function computes
.. math::
\sum_{i=1}^n \overline{x_i}y_i.
where :math:`\overline{x_i}` denotes the conjugate for complex
vectors, and it is the identity for real vectors.
.. note::
Unlike NumPy's vdot, torch.vdot intentionally only supports computing the dot product
of two 1D tensors with the same number of elements.
.. seealso::
:func:`torch.linalg.vecdot` computes the dot product of two batches of vectors along a dimension.
Args:
input (Tensor): first tensor in the dot product, must be 1D. Its conjugate is used if it's complex.
other (Tensor): second tensor in the dot product, must be 1D.
Keyword args:
.. note:: out (Tensor, optional): the output tensor.
Example::
>>> torch.vdot(torch.tensor([2, 3]), torch.tensor([2, 1]))
tensor(7)
>>> a = torch.tensor((1 +2j, 3 - 1j))
>>> b = torch.tensor((2 +1j, 4 - 0j))
>>> torch.vdot(a, b)
tensor([16.+1.j])
>>> torch.vdot(b, a)
tensor([16.-1.j])
torch.version
Python Library Documentation: module torch.version in torch
NAME
torch.version
DATA
__all__ = ['__version__', 'debug', 'cuda', 'git_version', 'hip', 'rocm...
__annotations__ = {'cuda': typing.Optional[str], 'hip': typing.Optiona...
cuda = None
debug = False
git_version = 'cf30153c4c131c8164ee7798e5022d810682e2cb'
hip = None
rocm = None
xpu = None
VERSION
2.13.0+cpu
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\version.py
torch.view_as_complex
Python Library Documentation: built-in function view_as_complex in module torch
view_as_complex(...)
view_as_complex(input) -> Tensor
Returns a view of :attr:`input` as a complex tensor. For an input complex
tensor of :attr:`size` :math:`m1, m2, \dots, mi, 2`, this function returns a
new complex tensor of :attr:`size` :math:`m1, m2, \dots, mi` where the last
dimension of the input tensor is expected to represent the real and imaginary
components of complex numbers.
.. warning::
:func:`view_as_complex` is only supported for tensors with
:class:`torch.dtype` ``torch.float64`` and ``torch.float32``. The input is
expected to have the last dimension of :attr:`size` 2. In addition, the
tensor must have a `stride` of 1 for its last dimension. The strides of all
other dimensions must be even numbers.
Args:
input (Tensor): the input tensor.
Example::
>>> x=torch.randn(4, 2)
>>> x
tensor([[ 1.6116, -0.5772],
[-1.4606, -0.9120],
[ 0.0786, -1.7497],
[-0.6561, -1.6623]])
>>> torch.view_as_complex(x)
tensor([(1.6116-0.5772j), (-1.4606-0.9120j), (0.0786-1.7497j), (-0.6561-1.6623j)])
torch.view_as_complex_copy
Python Library Documentation: built-in function view_as_complex_copy in module torch
view_as_complex_copy(...)
Performs the same operation as :func:`torch.view_as_complex`, but all output tensors
are freshly created instead of aliasing the input.
torch.view_as_real
Python Library Documentation: built-in function view_as_real in module torch
view_as_real(...)
view_as_real(input) -> Tensor
Returns a view of :attr:`input` as a real tensor. For an input complex tensor of
:attr:`size` :math:`m1, m2, \dots, mi`, this function returns a new
real tensor of size :math:`m1, m2, \dots, mi, 2`, where the last dimension of size 2
represents the real and imaginary components of complex numbers.
.. warning::
:func:`view_as_real` is only supported for tensors with ``complex dtypes``.
Args:
input (Tensor): the input tensor.
Example::
>>> x=torch.randn(4, dtype=torch.cfloat)
>>> x
tensor([(0.4737-0.3839j), (-0.2098-0.6699j), (0.3470-0.9451j), (-0.5174-1.3136j)])
>>> torch.view_as_real(x)
tensor([[ 0.4737, -0.3839],
[-0.2098, -0.6699],
[ 0.3470, -0.9451],
[-0.5174, -1.3136]])
torch.view_as_real_copy
Python Library Documentation: built-in function view_as_real_copy in module torch
view_as_real_copy(...)
Performs the same operation as :func:`torch.view_as_real`, but all output tensors
are freshly created instead of aliasing the input.
torch.view_copy
Python Library Documentation: built-in function view_copy in module torch
view_copy(...)
Performs the same operation as :func:`torch.view`, but all output tensors
are freshly created instead of aliasing the input.
torch.vmap
Python Library Documentation: function vmap in module torch.func
vmap(func: 'Callable[_P, _R]', in_dims: 'in_dims_t' = 0, out_dims: 'out_dims_t' = 0, randomness: 'str' = 'error', *, chunk_size: 'int | None' = None) -> 'Callable[_P, _R]'
vmap is the vectorizing map; ``vmap(func)`` returns a new function that
maps ``func`` over some dimension of the inputs. Semantically, vmap
pushes the map into PyTorch operations called by ``func``, effectively
vectorizing those operations.
vmap is useful for handling batch dimensions: one can write a function
``func`` that runs on examples and then lift it to a function that can
take batches of examples with ``vmap(func)``. vmap can also be used to
compute batched gradients when composed with autograd.
.. note::
:func:`torch.vmap` is aliased to :func:`torch.func.vmap` for
convenience. Use whichever one you'd like.
Args:
func (function): A Python function that takes one or more arguments.
Must return one or more Tensors.
in_dims (int or nested structure): Specifies which dimension of the
inputs should be mapped over. ``in_dims`` should have a
structure like the inputs. If the ``in_dim`` for a particular
input is None, then that indicates there is no map dimension.
Default: 0.
out_dims (int or Tuple[int]): Specifies where the mapped dimension
should appear in the outputs. If ``out_dims`` is a Tuple, then
it should have one element per output. Default: 0.
randomness (str): Specifies whether the randomness in this
vmap should be the same or different across batches. If 'different',
the randomness for each batch will be different. If 'same', the
randomness will be the same across batches. If 'error', any calls to
random functions will error. Default: 'error'. WARNING: this flag
only applies to random PyTorch operations and does not apply to
Python's random module or numpy randomness.
chunk_size (None or int): If None (default), apply a single vmap over inputs.
If not None, then compute the vmap :attr:`chunk_size` samples at a time.
Note that :attr:`chunk_size=1` is equivalent to computing the vmap with a for-loop.
If you run into memory issues computing the vmap, please try a non-None chunk_size.
Returns:
Returns a new "batched" function. It takes the same inputs as
``func``, except each input has an extra dimension at the index
specified by ``in_dims``. It takes returns the same outputs as
``func``, except each output has an extra dimension at the index
specified by ``out_dims``.
.. warning:
:func:`vmap` works best with functional-style code. Please do not
perform any side-effects in ``func``, with the exception of
in-place PyTorch operations. Examples of side-effects include mutating
Python data structures and assigning values to variables not captured
in ``func``.
One example of using :func:`vmap` is to compute batched dot products. PyTorch
doesn't provide a batched ``torch.dot`` API; instead of unsuccessfully
rummaging through docs, use :func:`vmap` to construct a new function.
>>> torch.dot # [D], [D] -> []
>>> batched_dot = torch.func.vmap(torch.dot) # [N, D], [N, D] -> [N]
>>> x, y = torch.randn(2, 5), torch.randn(2, 5)
>>> batched_dot(x, y)
:func:`vmap` can be helpful in hiding batch dimensions, leading to a simpler
model authoring experience.
>>> batch_size, feature_size = 3, 5
>>> weights = torch.randn(feature_size, requires_grad=True)
>>>
>>> def model(feature_vec):
>>> # Very simple linear model with activation
>>> return feature_vec.dot(weights).relu()
>>>
>>> examples = torch.randn(batch_size, feature_size)
>>> result = torch.vmap(model)(examples)
:func:`vmap` can also help vectorize computations that were previously difficult
or impossible to batch. One example is higher-order gradient computation.
The PyTorch autograd engine computes vjps (vector-Jacobian products).
Computing a full Jacobian matrix for some function f: R^N -> R^N usually
requires N calls to ``autograd.grad``, one per Jacobian row. Using :func:`vmap`,
we can vectorize the whole computation, computing the Jacobian in a single
call to ``autograd.grad``.
>>> # Setup
>>> N = 5
>>> f = lambda x: x**2
>>> x = torch.randn(N, requires_grad=True)
>>> y = f(x)
>>> I_N = torch.eye(N)
>>>
>>> # Sequential approach
>>> jacobian_rows = [torch.autograd.grad(y, x, v, retain_graph=True)[0]
>>> for v in I_N.unbind()]
>>> jacobian = torch.stack(jacobian_rows)
>>>
>>> # vectorized gradient computation
>>> def get_vjp(v):
>>> return torch.autograd.grad(y, x, v)
>>> jacobian = torch.vmap(get_vjp)(I_N)
:func:`vmap` can also be nested, producing an output with multiple batched dimensions
>>> torch.dot # [D], [D] -> []
>>> batched_dot = torch.vmap(
... torch.vmap(torch.dot)
... ) # [N1, N0, D], [N1, N0, D] -> [N1, N0]
>>> x, y = torch.randn(2, 3, 5), torch.randn(2, 3, 5)
>>> batched_dot(x, y) # tensor of size [2, 3]
If the inputs are not batched along the first dimension, ``in_dims`` specifies
the dimension that each inputs are batched along as
>>> torch.dot # [N], [N] -> []
>>> batched_dot = torch.vmap(torch.dot, in_dims=1) # [N, D], [N, D] -> [D]
>>> x, y = torch.randn(2, 5), torch.randn(2, 5)
>>> batched_dot(
... x, y
... ) # output is [5] instead of [2] if batched along the 0th dimension
If there are multiple inputs each of which is batched along different dimensions,
``in_dims`` must be a tuple with the batch dimension for each input as
>>> torch.dot # [D], [D] -> []
>>> batched_dot = torch.vmap(torch.dot, in_dims=(0, None)) # [N, D], [D] -> [N]
>>> x, y = torch.randn(2, 5), torch.randn(5)
>>> batched_dot(
... x, y
... ) # second arg doesn't have a batch dim because in_dim[1] was None
If the input is a Python struct, ``in_dims`` must be a tuple containing a struct
matching the shape of the input:
>>> f = lambda dict: torch.dot(dict["x"], dict["y"])
>>> x, y = torch.randn(2, 5), torch.randn(5)
>>> input = {"x": x, "y": y}
>>> batched_dot = torch.vmap(f, in_dims=({"x": 0, "y": None},))
>>> batched_dot(input)
By default, the output is batched along the first dimension. However, it can be batched
along any dimension by using ``out_dims``
>>> f = lambda x: x**2
>>> x = torch.randn(2, 5)
>>> batched_pow = torch.vmap(f, out_dims=1)
>>> batched_pow(x) # [5, 2]
For any function that uses kwargs, the returned function will not batch the kwargs but will
accept kwargs
>>> x = torch.randn([2, 5])
>>> def fn(x, scale=4.):
>>> return x * scale
>>>
>>> batched_pow = torch.vmap(fn)
>>> assert torch.allclose(batched_pow(x), x * 4)
>>> batched_pow(x, scale=x) # scale is not batched, output has shape [2, 2, 5]
.. note::
vmap does not provide general autobatching or handle variable-length
sequences out of the box.
torch.vsplit
Python Library Documentation: built-in function vsplit in module torch
vsplit(...)
vsplit(input, indices_or_sections) -> List of Tensors
Splits :attr:`input`, a tensor with two or more dimensions, into multiple tensors
vertically according to :attr:`indices_or_sections`. Each split is a view of
:attr:`input`.
This is equivalent to calling torch.tensor_split(input, indices_or_sections, dim=0)
(the split dimension is 0), except that if :attr:`indices_or_sections` is an integer
it must evenly divide the split dimension or a runtime error will be thrown.
This function is based on NumPy's :func:`numpy.vsplit`.
Args:
input (Tensor): tensor to split.
indices_or_sections (int or list or tuple of ints): See argument in :func:`torch.tensor_split`.
Example::
>>> t = torch.arange(16.0).reshape(4,4)
>>> t
tensor([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.],
[12., 13., 14., 15.]])
>>> torch.vsplit(t, 2)
(tensor([[0., 1., 2., 3.],
[4., 5., 6., 7.]]),
tensor([[ 8., 9., 10., 11.],
[12., 13., 14., 15.]]))
>>> torch.vsplit(t, [3, 6])
(tensor([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]]),
tensor([[12., 13., 14., 15.]]),
tensor([], size=(0, 4)))
torch.vstack
Python Library Documentation: built-in function vstack in module torch
vstack(...)
vstack(tensors, *, out=None) -> Tensor
Stack tensors in sequence vertically (row wise).
This is equivalent to concatenation along the first axis after all 1-D tensors have been reshaped by :func:`torch.atleast_2d`.
Args:
tensors (sequence of Tensors): sequence of tensors to concatenate
Keyword args:
out (Tensor, optional): the output tensor.
Example::
>>> a = torch.tensor([1, 2, 3])
>>> b = torch.tensor([4, 5, 6])
>>> torch.vstack((a,b))
tensor([[1, 2, 3],
[4, 5, 6]])
>>> a = torch.tensor([[1],[2],[3]])
>>> b = torch.tensor([[4],[5],[6]])
>>> torch.vstack((a,b))
tensor([[1],
[2],
[3],
[4],
[5],
[6]])
torch.wait
Python Library Documentation: built-in function wait in module torch
wait(...) method of pybind11_builtins.pybind11_detail_function_record_v1_msvc_md_mscver19 instance
wait(arg0: torch._C.Future) -> object
torch.warnings
Python Library Documentation: module warnings
NAME
warnings - Python part of the warnings subsystem.
MODULE REFERENCE
https://docs.python.org/3.12/library/warnings.html
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
CLASSES
builtins.object
catch_warnings
class catch_warnings(builtins.object)
| catch_warnings(*, record=False, module=None, action=None, category=<class 'Warning'>, lineno=0, append=False)
|
| A context manager that copies and restores the warnings filter upon
| exiting the context.
|
| The 'record' argument specifies whether warnings should be captured by a
| custom implementation of warnings.showwarning() and be appended to a list
| returned by the context manager. Otherwise None is returned by the context
| manager. The objects appended to the list are arguments whose attributes
| mirror the arguments to showwarning().
|
| The 'module' argument is to specify an alternative module to the module
| named 'warnings' and imported under that name. This argument is only useful
| when testing the warnings module itself.
|
| If the 'action' argument is not None, the remaining arguments are passed
| to warnings.simplefilter() as if it were called immediately on entering the
| context.
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, *exc_info)
|
| __init__(self, *, record=False, module=None, action=None, category=<class 'Warning'>, lineno=0, append=False)
| Specify whether to record warnings and if an alternative module
| should be used other than sys.modules['warnings'].
|
| For compatibility with Python 3.0, please consider all arguments to be
| keyword-only.
|
| __repr__(self)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
filterwarnings(action, message='', category=<class 'Warning'>, module='', lineno=0, append=False)
Insert an entry into the list of warnings filters (at the front).
'action' -- one of "error", "ignore", "always", "default", "module",
or "once"
'message' -- a regex that the warning message must match
'category' -- a class that the warning must be a subclass of
'module' -- a regex that the module name must match
'lineno' -- an integer line number, 0 matches all warnings
'append' -- if true, append to the list of filters
formatwarning(message, category, filename, lineno, line=None)
Function to format a warning the standard way.
resetwarnings()
Clear the list of warning filters, so that no filters are active.
showwarning(message, category, filename, lineno, file=None, line=None)
Hook to write a warning to a file; replace if you like.
simplefilter(action, category=<class 'Warning'>, lineno=0, append=False)
Insert a simple entry into the list of warnings filters (at the front).
A simple filter matches all modules and messages.
'action' -- one of "error", "ignore", "always", "default", "module",
or "once"
'category' -- a class that the warning must be a subclass of
'lineno' -- an integer line number, 0 matches all warnings
'append' -- if true, append to the list of filters
warn(...)
Issue a warning, or maybe ignore it or raise an exception.
message
Text of the warning message.
category
The Warning category subclass. Defaults to UserWarning.
stacklevel
How far up the call stack to make this warning appear. A value of 2 for
example attributes the warning to the caller of the code calling warn().
source
If supplied, the destroyed object which emitted a ResourceWarning
skip_file_prefixes
An optional tuple of module filename prefixes indicating frames to skip
during stacklevel computations for stack frame attribution.
warn_explicit(...)
Issue a warning, or maybe ignore it or raise an exception.
DATA
__all__ = ['warn', 'warn_explicit', 'showwarning', 'formatwarning', 'f...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\warnings.py
torch.where
Python Library Documentation: built-in function where in module torch
where(...)
where(condition, input, other, *, out=None) -> Tensor
Return a tensor of elements selected from either :attr:`input` or :attr:`other`, depending on :attr:`condition`.
The operation is defined as:
.. math::
\text{out}_i = \begin{cases}
\text{input}_i & \text{if } \text{condition}_i \\
\text{other}_i & \text{otherwise} \\
\end{cases}
.. note::
The tensors :attr:`condition`, :attr:`input`, :attr:`other` must be :ref:`broadcastable <broadcasting-semantics>`.
Arguments:
condition (BoolTensor): When True (nonzero), yield input, otherwise yield other
input (Tensor or Scalar): value (if :attr:`input` is a scalar) or values selected at indices
where :attr:`condition` is ``True``
other (Tensor or Scalar): value (if :attr:`other` is a scalar) or values selected at indices
where :attr:`condition` is ``False``
Keyword args:
out (Tensor, optional): the output tensor.
Returns:
Tensor: A tensor of shape equal to the broadcasted shape of :attr:`condition`, :attr:`input`, :attr:`other`
Example::
>>> x = torch.randn(3, 2)
>>> y = torch.ones(3, 2)
>>> x
tensor([[-0.4620, 0.3139],
[ 0.3898, -0.7197],
[ 0.0478, -0.1657]])
>>> torch.where(x > 0, 1.0, 0.0)
tensor([[0., 1.],
[1., 0.],
[1., 0.]])
>>> torch.where(x > 0, x, y)
tensor([[ 1.0000, 0.3139],
[ 0.3898, 1.0000],
[ 0.0478, 1.0000]])
>>> x = torch.randn(2, 2, dtype=torch.double)
>>> x
tensor([[ 1.0779, 0.0383],
[-0.8785, -1.1089]], dtype=torch.float64)
>>> torch.where(x > 0, x, 0.)
tensor([[1.0779, 0.0383],
[0.0000, 0.0000]], dtype=torch.float64)
.. function:: where(condition) -> tuple of LongTensor
:noindex:
``torch.where(condition)`` is identical to
``torch.nonzero(condition, as_tuple=True)``.
.. note::
See also :func:`torch.nonzero`.
torch.while_loop
Python Library Documentation: function while_loop in module torch._higher_order_ops.while_loop
while_loop(cond_fn, body_fn, carried_inputs)
Run ``body_fn(*carried_inputs)`` while ``cond_fn(*carried_inputs)`` returns
a True scalar tensor. Returns the output of body_fn or initial
carried_inputs.
.. warning::
`torch.while_loop` is a prototype feature in PyTorch. It has limited support for input and output types and
doesn't support training currently. Please look forward to a more stable implementation in a future version of PyTorch.
Read more about feature classification at: https://pytorch.org/blog/pytorch-feature-classification-changes/#prototype
`while_loop` is a structured control flow operator. It preserves the loop semantic across the torch.compile and torch.export.
`while_loop` is equivalent to the following::
def while_loop(cond_fn, body_fn, carried_inputs):
val = carried_inputs
while cond_fn(*val):
val = body_fn(*val)
return val
Args:
cond_fn (Callable): A callable function that returns a boolean Scalar tensor or a python boolean.
body_fn (Callable): A callable function that takes the same inputs as `cond_fn` and returns a tuple of tensors or ints
carried_inputs (Tuple of possibly nested dict/list/tuple of tensors or ints): A tuple of inputs to cond_fn and body_fn.
It's also the initial value of states that are carried across iterations. Note that when pass an integer as carry,
the corresponding return of while_loop will be another int with unknown values because we don't know how many
iterations while_loop will run.
Example 1::
def cond_fn(iter, x):
return iter.sum() < 10
def body_fn(iter, x):
return iter + 1, x.sin()
while_loop(cond_fn, body_fn, (torch.zeros(1), torch.randn(3, 4)))
Example 2::
def cond_fn(int_iter, x):
return 2 * int_iter < x.shape[0]
def body_fn(int_iter, x):
return int_iter + 1, x + int_iter
while_loop(cond_fn, body_fn, (0, torch.randn(3, 4)))
Restrictions:
- body_fn must return tensors or int with the same metadata (e.g.shape, dtype) as inputs.
- body_fn and cond_fn must not in-place mutate the carried_inputs. A clone before the mutation is required.
- body_fn and cond_fn must not mutate python variables (e.g. list/dict) created outside of the body_fn.
- body_fn and cond_fn's output cannot alias any of the inputs. A clone is required.
- During inference, body_fn and cond_fn can in-place mutate tensors that are not
carried_inputs, such as module buffers and captured tensors from the enclosing scope.
torch.windows
Python Library Documentation: package torch.signal.windows in torch.signal
NAME
torch.signal.windows
PACKAGE CONTENTS
windows
FUNCTIONS
bartlett(M: int, *, sym: bool = True, dtype: torch.dtype | None = None, layout: torch.layout = torch.strided, device: torch.device | None = None, requires_grad: bool = False) -> torch.Tensor
Computes the Bartlett window.
The Bartlett window is defined as follows:
.. math::
w_n = 1 - \left| \frac{2n}{M - 1} - 1 \right| = \begin{cases}
\frac{2n}{M - 1} & \text{if } 0 \leq n \leq \frac{M - 1}{2} \\
2 - \frac{2n}{M - 1} & \text{if } \frac{M - 1}{2} < n < M \\ \end{cases}
The window is normalized to 1 (maximum value is 1). However, the 1 doesn't appear if :attr:`M` is even and :attr:`sym` is `True`.
Arguments:
M (int): the length of the window.
In other words, the number of points of the returned window.
Keyword args:
sym (bool, optional): If `False`, returns a periodic window suitable for use in spectral analysis.
If `True`, returns a symmetric window suitable for use in filter design. Default: `True`.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Examples::
>>> # Generates a symmetric Bartlett window.
>>> torch.signal.windows.bartlett(10)
tensor([0.0000, 0.2222, 0.4444, 0.6667, 0.8889, 0.8889, 0.6667, 0.4444, 0.2222, 0.0000])
>>> # Generates a periodic Bartlett window.
>>> torch.signal.windows.bartlett(10, sym=False)
tensor([0.0000, 0.2000, 0.4000, 0.6000, 0.8000, 1.0000, 0.8000, 0.6000, 0.4000, 0.2000])
blackman(M: int, *, sym: bool = True, dtype: torch.dtype | None = None, layout: torch.layout = torch.strided, device: torch.device | None = None, requires_grad: bool = False) -> torch.Tensor
Computes the Blackman window.
The Blackman window is defined as follows:
.. math::
w_n = 0.42 - 0.5 \cos \left( \frac{2 \pi n}{M - 1} \right) + 0.08 \cos \left( \frac{4 \pi n}{M - 1} \right)
The window is normalized to 1 (maximum value is 1). However, the 1 doesn't appear if :attr:`M` is even and :attr:`sym` is `True`.
Arguments:
M (int): the length of the window.
In other words, the number of points of the returned window.
Keyword args:
sym (bool, optional): If `False`, returns a periodic window suitable for use in spectral analysis.
If `True`, returns a symmetric window suitable for use in filter design. Default: `True`.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Examples::
>>> # Generates a symmetric Blackman window.
>>> torch.signal.windows.blackman(5)
tensor([-1.4901e-08, 3.4000e-01, 1.0000e+00, 3.4000e-01, -1.4901e-08])
>>> # Generates a periodic Blackman window.
>>> torch.signal.windows.blackman(5, sym=False)
tensor([-1.4901e-08, 2.0077e-01, 8.4923e-01, 8.4923e-01, 2.0077e-01])
cosine(M: int, *, sym: bool = True, dtype: torch.dtype | None = None, layout: torch.layout = torch.strided, device: torch.device | None = None, requires_grad: bool = False) -> torch.Tensor
Computes a window with a simple cosine waveform, following the same implementation as SciPy.
This window is also known as the sine window.
The cosine window is defined as follows:
.. math::
w_n = \sin\left(\frac{\pi (n + 0.5)}{M}\right)
This formula differs from the typical cosine window formula by incorporating a 0.5 term in the numerator,
which shifts the sample positions. This adjustment results in a window that starts and ends with non-zero values.
The window is normalized to 1 (maximum value is 1). However, the 1 doesn't appear if :attr:`M` is even and :attr:`sym` is `True`.
Args:
M (int): the length of the window.
In other words, the number of points of the returned window.
Keyword args:
sym (bool, optional): If `False`, returns a periodic window suitable for use in spectral analysis.
If `True`, returns a symmetric window suitable for use in filter design. Default: `True`.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Examples::
>>> # Generates a symmetric cosine window.
>>> torch.signal.windows.cosine(10)
tensor([0.1564, 0.4540, 0.7071, 0.8910, 0.9877, 0.9877, 0.8910, 0.7071, 0.4540, 0.1564])
>>> # Generates a periodic cosine window.
>>> torch.signal.windows.cosine(10, sym=False)
tensor([0.1423, 0.4154, 0.6549, 0.8413, 0.9595, 1.0000, 0.9595, 0.8413, 0.6549, 0.4154])
exponential(M: int, *, center: float | None = None, tau: float = 1.0, sym: bool = True, dtype: torch.dtype | None = None, layout: torch.layout = torch.strided, device: torch.device | None = None, requires_grad: bool = False) -> torch.Tensor
Computes a window with an exponential waveform.
Also known as Poisson window.
The exponential window is defined as follows:
.. math::
w_n = \exp{\left(-\frac{|n - c|}{\tau}\right)}
where `c` is the ``center`` of the window.
The window is normalized to 1 (maximum value is 1). However, the 1 doesn't appear if :attr:`M` is even and :attr:`sym` is `True`.
Args:
M (int): the length of the window.
In other words, the number of points of the returned window.
Keyword args:
center (float, optional): where the center of the window will be located.
Default: `M / 2` if `sym` is `False`, else `(M - 1) / 2`.
tau (float, optional): the decay value.
Tau is generally associated with a percentage, that means, that the value should
vary within the interval (0, 100]. If tau is 100, it is considered the uniform window.
Default: 1.0.
sym (bool, optional): If `False`, returns a periodic window suitable for use in spectral analysis.
If `True`, returns a symmetric window suitable for use in filter design. Default: `True`.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Examples::
>>> # Generates a symmetric exponential window of size 10 and with a decay value of 1.0.
>>> # The center will be at (M - 1) / 2, where M is 10.
>>> torch.signal.windows.exponential(10)
tensor([0.0111, 0.0302, 0.0821, 0.2231, 0.6065, 0.6065, 0.2231, 0.0821, 0.0302, 0.0111])
>>> # Generates a periodic exponential window and decay factor equal to .5
>>> torch.signal.windows.exponential(10, sym=False,tau=.5)
tensor([4.5400e-05, 3.3546e-04, 2.4788e-03, 1.8316e-02, 1.3534e-01, 1.0000e+00, 1.3534e-01, 1.8316e-02, 2.4788e-03, 3.3546e-04])
gaussian(M: int, *, std: float = 1.0, sym: bool = True, dtype: torch.dtype | None = None, layout: torch.layout = torch.strided, device: torch.device | None = None, requires_grad: bool = False) -> torch.Tensor
Computes a window with a gaussian waveform.
The gaussian window is defined as follows:
.. math::
w_n = \exp{\left(-\left(\frac{n}{2\sigma}\right)^2\right)}
The window is normalized to 1 (maximum value is 1). However, the 1 doesn't appear if :attr:`M` is even and :attr:`sym` is `True`.
Args:
M (int): the length of the window.
In other words, the number of points of the returned window.
Keyword args:
std (float, optional): the standard deviation of the gaussian. It controls how narrow or wide the window is.
Default: 1.0.
sym (bool, optional): If `False`, returns a periodic window suitable for use in spectral analysis.
If `True`, returns a symmetric window suitable for use in filter design. Default: `True`.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Examples::
>>> # Generates a symmetric gaussian window with a standard deviation of 1.0.
>>> torch.signal.windows.gaussian(10)
tensor([4.0065e-05, 2.1875e-03, 4.3937e-02, 3.2465e-01, 8.8250e-01, 8.8250e-01, 3.2465e-01, 4.3937e-02, 2.1875e-03, 4.0065e-05])
>>> # Generates a periodic gaussian window and standard deviation equal to 0.9.
>>> torch.signal.windows.gaussian(10, sym=False,std=0.9)
tensor([1.9858e-07, 5.1365e-05, 3.8659e-03, 8.4658e-02, 5.3941e-01, 1.0000e+00, 5.3941e-01, 8.4658e-02, 3.8659e-03, 5.1365e-05])
general_cosine(M, *, a: collections.abc.Iterable, sym: bool = True, dtype: torch.dtype | None = None, layout: torch.layout = torch.strided, device: torch.device | None = None, requires_grad: bool = False) -> torch.Tensor
Computes the general cosine window.
The general cosine window is defined as follows:
.. math::
w_n = \sum^{M-1}_{i=0} (-1)^i a_i \cos{ \left( \frac{2 \pi i n}{M - 1}\right)}
The window is normalized to 1 (maximum value is 1). However, the 1 doesn't appear if :attr:`M` is even and :attr:`sym` is `True`.
Arguments:
M (int): the length of the window.
In other words, the number of points of the returned window.
Keyword args:
a (Iterable): the coefficients associated to each of the cosine functions.
sym (bool, optional): If `False`, returns a periodic window suitable for use in spectral analysis.
If `True`, returns a symmetric window suitable for use in filter design. Default: `True`.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Examples::
>>> # Generates a symmetric general cosine window with 3 coefficients.
>>> torch.signal.windows.general_cosine(10, a=[0.46, 0.23, 0.31], sym=True)
tensor([0.5400, 0.3376, 0.1288, 0.4200, 0.9136, 0.9136, 0.4200, 0.1288, 0.3376, 0.5400])
>>> # Generates a periodic general cosine window with 2 coefficients.
>>> torch.signal.windows.general_cosine(10, a=[0.5, 1 - 0.5], sym=False)
tensor([0.0000, 0.0955, 0.3455, 0.6545, 0.9045, 1.0000, 0.9045, 0.6545, 0.3455, 0.0955])
general_hamming(M, *, alpha: float = 0.54, sym: bool = True, dtype: torch.dtype | None = None, layout: torch.layout = torch.strided, device: torch.device | None = None, requires_grad: bool = False) -> torch.Tensor
Computes the general Hamming window.
The general Hamming window is defined as follows:
.. math::
w_n = \alpha - (1 - \alpha) \cos{ \left( \frac{2 \pi n}{M-1} \right)}
The window is normalized to 1 (maximum value is 1). However, the 1 doesn't appear if :attr:`M` is even and :attr:`sym` is `True`.
Arguments:
M (int): the length of the window.
In other words, the number of points of the returned window.
Keyword args:
alpha (float, optional): the window coefficient. Default: 0.54.
sym (bool, optional): If `False`, returns a periodic window suitable for use in spectral analysis.
If `True`, returns a symmetric window suitable for use in filter design. Default: `True`.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Examples::
>>> # Generates a symmetric Hamming window with the general Hamming window.
>>> torch.signal.windows.general_hamming(10, sym=True)
tensor([0.0800, 0.1876, 0.4601, 0.7700, 0.9723, 0.9723, 0.7700, 0.4601, 0.1876, 0.0800])
>>> # Generates a periodic Hann window with the general Hamming window.
>>> torch.signal.windows.general_hamming(10, alpha=0.5, sym=False)
tensor([0.0000, 0.0955, 0.3455, 0.6545, 0.9045, 1.0000, 0.9045, 0.6545, 0.3455, 0.0955])
hamming(M: int, *, sym: bool = True, dtype: torch.dtype | None = None, layout: torch.layout = torch.strided, device: torch.device | None = None, requires_grad: bool = False) -> torch.Tensor
Computes the Hamming window.
The Hamming window is defined as follows:
.. math::
w_n = \alpha - \beta\ \cos \left( \frac{2 \pi n}{M - 1} \right)
The window is normalized to 1 (maximum value is 1). However, the 1 doesn't appear if :attr:`M` is even and :attr:`sym` is `True`.
Arguments:
M (int): the length of the window.
In other words, the number of points of the returned window.
Keyword args:
sym (bool, optional): If `False`, returns a periodic window suitable for use in spectral analysis.
If `True`, returns a symmetric window suitable for use in filter design. Default: `True`.
alpha (float, optional): The coefficient :math:`\alpha` in the equation above.
beta (float, optional): The coefficient :math:`\beta` in the equation above.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Examples::
>>> # Generates a symmetric Hamming window.
>>> torch.signal.windows.hamming(10)
tensor([0.0800, 0.1876, 0.4601, 0.7700, 0.9723, 0.9723, 0.7700, 0.4601, 0.1876, 0.0800])
>>> # Generates a periodic Hamming window.
>>> torch.signal.windows.hamming(10, sym=False)
tensor([0.0800, 0.1679, 0.3979, 0.6821, 0.9121, 1.0000, 0.9121, 0.6821, 0.3979, 0.1679])
hann(M: int, *, sym: bool = True, dtype: torch.dtype | None = None, layout: torch.layout = torch.strided, device: torch.device | None = None, requires_grad: bool = False) -> torch.Tensor
Computes the Hann window.
The Hann window is defined as follows:
.. math::
w_n = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{M - 1} \right)\right] =
\sin^2 \left( \frac{\pi n}{M - 1} \right)
The window is normalized to 1 (maximum value is 1). However, the 1 doesn't appear if :attr:`M` is even and :attr:`sym` is `True`.
Arguments:
M (int): the length of the window.
In other words, the number of points of the returned window.
Keyword args:
sym (bool, optional): If `False`, returns a periodic window suitable for use in spectral analysis.
If `True`, returns a symmetric window suitable for use in filter design. Default: `True`.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Examples::
>>> # Generates a symmetric Hann window.
>>> torch.signal.windows.hann(10)
tensor([0.0000, 0.1170, 0.4132, 0.7500, 0.9698, 0.9698, 0.7500, 0.4132, 0.1170, 0.0000])
>>> # Generates a periodic Hann window.
>>> torch.signal.windows.hann(10, sym=False)
tensor([0.0000, 0.0955, 0.3455, 0.6545, 0.9045, 1.0000, 0.9045, 0.6545, 0.3455, 0.0955])
kaiser(M: int, *, beta: float = 12.0, sym: bool = True, dtype: torch.dtype | None = None, layout: torch.layout = torch.strided, device: torch.device | None = None, requires_grad: bool = False) -> torch.Tensor
Computes the Kaiser window.
The Kaiser window is defined as follows:
.. math::
w_n = I_0 \left( \beta \sqrt{1 - \left( {\frac{n - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )
where ``I_0`` is the zeroth order modified Bessel function of the first kind (see :func:`torch.special.i0`), and
``N = M - 1 if sym else M``.
The window is normalized to 1 (maximum value is 1). However, the 1 doesn't appear if :attr:`M` is even and :attr:`sym` is `True`.
Args:
M (int): the length of the window.
In other words, the number of points of the returned window.
Keyword args:
beta (float, optional): shape parameter for the window. Must be non-negative. Default: 12.0
sym (bool, optional): If `False`, returns a periodic window suitable for use in spectral analysis.
If `True`, returns a symmetric window suitable for use in filter design. Default: `True`.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Examples::
>>> # Generates a symmetric Kaiser window with a shape parameter of 12.0.
>>> torch.signal.windows.kaiser(5)
tensor([4.0065e-05, 2.1875e-03, 4.3937e-02, 3.2465e-01, 8.8250e-01, 8.8250e-01, 3.2465e-01, 4.3937e-02, 2.1875e-03, 4.0065e-05])
>>> # Generates a periodic Kaiser window and shape parameter equal to 0.9.
>>> torch.signal.windows.kaiser(5, sym=False, beta=0.9)
tensor([1.9858e-07, 5.1365e-05, 3.8659e-03, 8.4658e-02, 5.3941e-01, 1.0000e+00, 5.3941e-01, 8.4658e-02, 3.8659e-03, 5.1365e-05])
nuttall(M: int, *, sym: bool = True, dtype: torch.dtype | None = None, layout: torch.layout = torch.strided, device: torch.device | None = None, requires_grad: bool = False) -> torch.Tensor
Computes the minimum 4-term Blackman-Harris window according to Nuttall.
.. math::
w_n = 1 - 0.36358 \cos{(z_n)} + 0.48917 \cos{(2z_n)} - 0.13659 \cos{(3z_n)} + 0.01064 \cos{(4z_n)}
where :math:`z_n = \frac{2 \pi n}{M}`.
The window is normalized to 1 (maximum value is 1). However, the 1 doesn't appear if :attr:`M` is even and :attr:`sym` is `True`.
Arguments:
M (int): the length of the window.
In other words, the number of points of the returned window.
Keyword args:
sym (bool, optional): If `False`, returns a periodic window suitable for use in spectral analysis.
If `True`, returns a symmetric window suitable for use in filter design. Default: `True`.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
References::
- A. Nuttall, "Some windows with very good sidelobe behavior,"
IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. 29, no. 1, pp. 84-91,
Feb 1981. https://doi.org/10.1109/TASSP.1981.1163506
- Heinzel G. et al., "Spectrum and spectral density estimation by the Discrete Fourier transform (DFT),
including a comprehensive list of window functions and some new flat-top windows",
February 15, 2002 https://holometer.fnal.gov/GH_FFT.pdf
Examples::
>>> # Generates a symmetric Nuttall window.
>>> torch.signal.windows.general_hamming(5, sym=True)
tensor([3.6280e-04, 2.2698e-01, 1.0000e+00, 2.2698e-01, 3.6280e-04])
>>> # Generates a periodic Nuttall window.
>>> torch.signal.windows.general_hamming(5, sym=False)
tensor([3.6280e-04, 1.1052e-01, 7.9826e-01, 7.9826e-01, 1.1052e-01])
DATA
__all__ = ['bartlett', 'blackman', 'cosine', 'exponential', 'gaussian'...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\signal\windows\__init__.py
torch.xlogy
Python Library Documentation: built-in function xlogy in module torch
xlogy(...)
xlogy(input, other, *, out=None) -> Tensor
Alias for :func:`torch.special.xlogy`.
torch.xlogy_
Python Library Documentation: built-in function xlogy_ in module torch xlogy_(...)
torch.xpu
Python Library Documentation: package torch.xpu in torch
NAME
torch.xpu
DESCRIPTION
This package introduces support for the XPU backend, specifically tailored for
Intel GPU optimization.
This package is lazily initialized, so you can always import it, and use
:func:`is_available()` to determine if your system supports XPU.
PACKAGE CONTENTS
_gpu_trace
_utils
graphs
memory
random
streams
CLASSES
builtins.object
StreamContext
device
device_of
torch.xpu.graphs.graph
torch._utils._XPUGraph(builtins.object)
torch.xpu.graphs.XPUGraph
torch._utils._XPUMemPool(builtins.object)
torch.xpu.memory.MemPool
torch._utils._XpuEventBase(builtins.object)
torch.xpu.streams.Event
torch._utils._XpuStreamBase(builtins.object)
torch.xpu.streams.Stream
torch.xpu.memory._XPUAllocator(builtins.object)
torch.xpu.memory.XPUPluggableAllocator
class Event(torch._utils._XpuEventBase)
| Event(enable_timing=False)
|
| Wrapper around a XPU event.
|
| XPU events are synchronization markers that can be used to monitor the
| device's progress, and to synchronize XPU streams.
|
| The underlying XPU events are lazily initialized when the event is first
| recorded. After creation, only streams on the same device may record the
| event. However, streams on any device can wait on the event.
|
| Args:
| enable_timing (bool, optional): indicates if the event should measure time
| (default: ``False``)
|
| Method resolution order:
| Event
| torch._utils._XpuEventBase
| builtins.object
|
| Methods defined here:
|
| __repr__(self) -> 'str'
| Return repr(self).
|
| elapsed_time(self, end_event: 'Event')
| Return the time elapsed.
|
| Time reported in milliseconds after the event was recorded and
| before the end_event was recorded.
|
| Args:
| end_event (Event): the end event.
|
| query(self) -> 'bool'
| Check if all work currently captured by event has completed.
|
| Returns:
| A boolean indicating if all work currently captured by event has
| completed.
|
| record(self, stream: 'Stream | torch.Stream | None' = None) -> 'None'
| Record the event in a given stream.
|
| Args:
| stream (Stream, torch.Stream, optional): Uses ``torch.xpu.current_stream()`` if no stream is specified.
| The stream's device must match the event's device.
|
| synchronize(self) -> 'None'
| Wait for the event to complete.
|
| Waits until the completion of all work currently captured in this event.
| This prevents the CPU thread from proceeding until the event completes.
|
| wait(self, stream: 'Stream | torch.Stream | None' = None) -> 'None'
| Make all future work submitted to the given stream wait for this event.
|
| Args:
| stream (Stream, torch.Stream, optional): Uses ``torch.xpu.current_stream()`` if no stream is specified.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, enable_timing=False)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from torch._utils._XpuEventBase:
|
| __init__ = err_fn(obj, *args, **kwargs) from torch._utils._dummy_type.<locals>.get_err_fn.<locals>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._utils._XpuEventBase:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class MemPool(torch._utils._XPUMemPool)
| MemPool(allocator: torch._utils._xpu_XPUAllocator | None = None, use_on_oom: bool = False)
|
| MemPool represents a pool of memory in a caching allocator. Currently,
| it's just the ID of the pool object maintained in the XPUCachingAllocator.
|
| Args:
| allocator(torch._C._xpu_XPUAllocator, optional): a
| torch._C._xpu_XPUAllocator object that can be used to
| define how memory gets allocated in the pool. If :attr:`allocator`
| is ``None`` (default), memory allocation follows the default/
| current configuration of the XPUCachingAllocator.
| use_on_oom(bool): a bool that indicates if this pool can be used
| as a last resort if a memory allocation outside of the pool fails due
| to Out Of Memory. This is ``False`` by default.
|
| Method resolution order:
| MemPool
| torch._utils._XPUMemPool
| builtins.object
|
| Methods defined here:
|
| __init__(self, allocator: torch._utils._xpu_XPUAllocator | None = None, use_on_oom: bool = False)
| Initialize self. See help(type(self)) for accurate signature.
|
| snapshot(self)
| Return a snapshot of the XPU memory allocator pool state across all
| devices.
|
| Interpreting the output of this function requires familiarity with the
| memory allocator internals.
|
| use_count(self) -> int
| Returns the reference count of this pool.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| allocator
| Returns the allocator this MemPool routes allocations to.
|
| id
| Returns the ID of this pool as a tuple of two ints.
|
| ----------------------------------------------------------------------
| Static methods inherited from torch._utils._XPUMemPool:
|
| __new__ = err_fn(obj, *args, **kwargs) from torch._utils._dummy_type.<locals>.get_err_fn.<locals>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._utils._XPUMemPool:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class Stream(torch._utils._XpuStreamBase)
| Stream(device=None, priority=0, **kwargs)
|
| Wrapper around a XPU stream.
|
| A XPU stream is a linear sequence of execution that belongs to a specific
| device, independent from other streams. It supports with statement as a
| context manager to ensure the operators within the with block are running
| on the corresponding stream.
|
| Args:
| device(torch.device or int, optional): a device on which to allocate
| the stream. If :attr:`device` is ``None`` (default) or a negative
| integer, this will use the current device.
| priority(int, optional): priority of the stream, which can be positive, 0, or negative.
| A lower number indicates a higher priority. By default, the priority is set to 0.
| If the value falls outside of the allowed priority range, it will automatically be
| mapped to the nearest valid priority (lowest for large positive numbers or
| highest for large negative numbers).
|
| Method resolution order:
| Stream
| torch._utils._XpuStreamBase
| builtins.object
|
| Methods defined here:
|
| __eq__(self, o)
| Return self==value.
|
| __hash__(self)
| Return hash(self).
|
| __repr__(self) -> 'str'
| Return repr(self).
|
| query(self) -> 'bool'
| Check if all the work submitted has been completed.
|
| Returns:
| A boolean indicating if all kernels in this stream are completed.
|
| record_event(self, event: 'Event | torch.Event | None' = None)
| Record an event.
|
| Args:
| event (Event, torch.Event, optional): event to record. If not given, a new one
| will be allocated.
|
| Returns:
| Recorded event.
|
| synchronize(self) -> 'None'
| Wait for all the kernels in this stream to complete.
|
| wait_event(self, event: 'Event | torch.Event') -> 'None'
| Make all future work submitted to the stream wait for an event.
|
| Args:
| event (Event, torch.Event): an event to wait for.
|
| wait_stream(self, stream: 'Stream | torch.Stream') -> 'None'
| Synchronize with another stream.
|
| All future work submitted to this stream will wait until all kernels
| submitted to a given stream at the time of call complete.
|
| Args:
| stream (Stream, torch.Stream): a stream to synchronize.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, device=None, priority=0, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from torch._utils._XpuStreamBase:
|
| __init__ = err_fn(obj, *args, **kwargs) from torch._utils._dummy_type.<locals>.get_err_fn.<locals>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._utils._XpuStreamBase:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class StreamContext(builtins.object)
| StreamContext(stream: 'torch.xpu.Stream | None') -> 'None'
|
| Context-manager that selects a given stream.
|
| All XPU kernels queued within its context will be enqueued on a selected
| stream.
|
| Args:
| Stream (Stream): selected stream. This manager is a no-op if it's
| ``None``.
| .. note:: Streams are per-device.
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, type: 'Any', value: 'Any', traceback: 'Any')
|
| __init__(self, stream: 'torch.xpu.Stream | None') -> 'None'
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'cur_stream': 'torch.xpu.Stream | None'}
class XPUGraph(torch._utils._XPUGraph)
| XPUGraph(keep_graph: 'bool' = False) -> 'Self'
|
| Wrapper around a XPU graph.
|
| Arguments:
| keep_graph (bool, optional): If ``keep_graph=False``, the
| executable command graph will be instantiated on GPU at the end of
| ``capture_end`` and the underlying modifiable command graph will be
| destroyed. Note that the executable command graph will not be
| instantiated at the end of ``capture_end`` in this
| case. Instead, it will be instantiated via an explicit called
| to ``instantiate`` or automatically on the first call to
| ``replay`` if ``instantiate`` was not already called. Calling
| ``instantiate`` manually before ``replay`` is recommended to
| prevent increased latency on the first call to ``replay``.
|
| Method resolution order:
| XPUGraph
| torch._utils._XPUGraph
| builtins.object
|
| Methods defined here:
|
| capture_begin(self, pool: '_POOL_HANDLE | None' = None) -> 'None'
| Begin capturing XPU work on the current xpu stream.
|
| Typically, you shouldn't call ``capture_begin`` yourself.
| Use :class:`~torch.xpu.graph`, which call ``capture_begin`` internally.
|
| Arguments:
| pool (optional): Token (returned by :func:`~torch.xpu.graph_pool_handle` or
| :meth:`other_Graph_instance.pool()<torch.xpu.XPUGraph.pool>`) that hints this graph may share memory
| with the indicated pool.
|
| capture_end(self) -> 'None'
| End XPU graph capture on the current stream.
|
| After ``capture_end``, ``replay`` may be called on this instance.
|
| Typically, you shouldn't call ``capture_end`` yourself.
| Use :class:`~torch.xpu.graph`, which call ``capture_end`` internally.
|
| debug_dump(self, debug_path: 'str') -> 'None'
| Arguments:
| debug_path (required): Path to dump the graph to.
|
| Calls a debugging function to dump the graph if the debugging is
| enabled via XPUGraph.enable_debug_mode()
|
| enable_debug_mode(self) -> 'None'
| Enable debugging mode for XPUGraph.debug_dump.
|
| instantiate(self) -> 'None'
| Instantiate the XPU graph. Will be called by
| ``capture_end`` if ``keep_graph=False``, or by ``replay`` if
| ``keep_graph=True`` and ``instantiate`` has not already been
| explicitly called. Does not destroy the xpu modify command graph returned
| by ``raw_xpu_graph``.
|
| pool(self) -> '_POOL_HANDLE'
| Return an opaque token representing the id of this graph's memory pool.
|
| This id can optionally be passed to another graph's ``capture_begin``,
| which hints the other graph may share the same memory pool.
|
| raw_xpu_graph(self) -> 'int'
| Returns the underlying xpuGraph_t. ``keep_graph`` must be True.
|
| XPU doesn't provide APIs to manipulate this object.
|
| raw_xpu_graph_exec(self) -> 'int'
| Returns the underlying xpuGraphExec_t. ``instantiate`` must have been called if ``keep_graph`` is True, or ``capture_end`` must have been called if ``keep_graph`` is False. If you call ``instantiate()`` after ``raw_xpu_graph_exec()``, the previously returned xpuGraphExec_t will be destroyed. It is your responsibility not to use this object after destruction.
|
| XPU doesn't provide APIs to manipulate this object.
|
| replay(self) -> 'None'
| Replay the XPU work captured by this graph.
|
| reset(self) -> 'None'
| Delete the graph currently held by this instance.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, keep_graph: 'bool' = False) -> 'Self'
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from torch._utils._XPUGraph:
|
| __init__ = err_fn(obj, *args, **kwargs) from torch._utils._dummy_type.<locals>.get_err_fn.<locals>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch._utils._XPUGraph:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class XPUPluggableAllocator(_XPUAllocator)
| XPUPluggableAllocator(path_to_lib_file: str, alloc_fn_name: str, free_fn_name: str)
|
| XPU memory allocator loaded dynamically from a shared library.
|
| This lets users provide custom allocation and free functions implemented
| in a separate shared library. The allocator is registered and could become
| available for use via :func:`~torch.xpu.memory.change_current_allocator`.
|
| Arguments:
| path_to_lib_file (str):
| Filesystem path to the shared library file containing the allocation
| and free functions.
| alloc_fn_name (str):
| Name of the allocation function exported from the shared library.
| The function must have the signature:
|
| ``void* alloc_fn(size_t size, int device, sycl::queue* queue);``
|
| free_fn_name (str):
| Name of the free function exported from the shared library.
| The function must have the signature:
|
| ``void free_fn(void* ptr, size_t size, int device, sycl::queue* queue);``
|
| Method resolution order:
| XPUPluggableAllocator
| _XPUAllocator
| builtins.object
|
| Methods defined here:
|
| __init__(self, path_to_lib_file: str, alloc_fn_name: str, free_fn_name: str)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from _XPUAllocator:
|
| allocator(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from _XPUAllocator:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class device(builtins.object)
| device(device: 'Any') -> 'None'
|
| Context-manager that changes the selected device.
|
| Args:
| device (torch.device or int or str): device index to select. It's a no-op if
| this argument is a negative integer or ``None``.
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, type: 'Any', value: 'Any', traceback: 'Any')
|
| __init__(self, device: 'Any') -> 'None'
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class device_of(device)
| device_of(obj) -> 'None'
|
| Context-manager that changes the current device to that of given object.
|
| You can use both tensors and storages as arguments. If a given object is
| not allocated on a XPU, this is a no-op.
|
| Args:
| obj (Tensor or Storage): object allocated on the selected device.
|
| Method resolution order:
| device_of
| device
| builtins.object
|
| Methods defined here:
|
| __init__(self, obj) -> 'None'
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from device:
|
| __enter__(self)
|
| __exit__(self, type: 'Any', value: 'Any', traceback: 'Any')
|
| ----------------------------------------------------------------------
| Data descriptors inherited from device:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
class graph(builtins.object)
| graph(xpu_graph: 'XPUGraph', pool: '_POOL_HANDLE | None' = None, stream: 'torch.xpu.Stream | None' = None)
|
| Context-manager that captures XPU work into a :class:`torch.xpu.XPUGraph` object for later replay.
|
| Arguments:
| xpu_graph (torch.xpu.XPUGraph): Graph object used for capture.
| pool (optional): Opaque token (returned by a call to :func:`~torch.xpu.graph_pool_handle()` or
| :meth:`other_Graph_instance.pool()<torch.xpu.XPUGraph.pool>`) hinting this graph's capture
| may share memory from the specified pool.
| stream (torch.xpu.Stream, optional): If supplied, will be set as the current stream in the context.
| If not supplied, ``graph`` sets its own internal side stream as the current stream in the context.
|
| .. note::
| For effective memory sharing, if you pass a ``pool`` used by a previous capture and the previous capture
| used an explicit ``stream`` argument, you should pass the same ``stream`` argument to this capture.
|
| Methods defined here:
|
| __enter__(self) -> 'None'
|
| __exit__(self, *args: 'object') -> 'None'
|
| __init__(self, xpu_graph: 'XPUGraph', pool: '_POOL_HANDLE | None' = None, stream: 'torch.xpu.Stream | None' = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'default_capture_stream': 'torch.xpu.Stream | None'...
|
| default_capture_stream = None
FUNCTIONS
can_device_access_peer(device: 'Device', peer: 'Device') -> 'bool'
Query whether a device can access a peer device's memory.
Args:
device (torch.device or int or str): selected device.
peer (torch.device or int or str): peer device to query access to.
Returns:
bool: ``True`` if ``device`` can access ``peer``, ``False`` otherwise.
change_current_allocator(allocator: torch.xpu.memory._XPUAllocator) -> None
Change the currently used memory allocator to be the one provided.
.. note::
If the current allocator has already been used/initialized, this function will error.
Arguments:
allocator (torch.xpu.memory._XPUAllocator): allocator to be set as the active one.
clock_rate(device: 'Device' = None) -> 'float'
Return the GPU clock rate in MHz.
Args:
device (torch.device, str or int, optional): selected device. Uses the
current device, given by :func:`~torch.xpu.current_device`,
if ``None`` (default).
current_device() -> 'int'
Return the index of a currently selected device.
current_stream(device: 'Device' = None) -> 'Stream'
Return the currently selected :class:`Stream` for a given device.
Args:
device (torch.device or int, optional): selected device. Returns
the currently selected :class:`Stream` for the current device, given
by :func:`~torch.xpu.current_device`, if :attr:`device` is ``None``
(default).
device_count() -> 'int'
Return the number of XPU device available.
.. note:: This API will NOT poison fork if Level Zero Sysman discovery succeeds.
See :ref:`multiprocessing-poison-fork-note` for more details.
device_memory_used(device: 'Device' = None) -> 'int'
Return the current GPU used global (device) memory in bytes.
Args:
device (torch.device, str or int, optional): selected device. Uses the
current device, given by :func:`~torch.xpu.current_device`,
if ``None`` (default).
.. note:: This API may require elevated privileges (e.g. ``sudo``) to access GPU memory usage information.
empty_cache() -> None
Release all unoccupied cached memory currently held by the caching
allocator so that those can be used in other XPU application.
.. note::
:func:`~torch.xpu.empty_cache` doesn't increase the amount of XPU
memory available for PyTorch. However, it may help reduce fragmentation
of XPU memory in certain cases.
get_arch_list() -> 'list[str]'
Return list XPU architectures this library was compiled for.
get_device_capability(device: 'Device' = None) -> 'dict[str, Any]'
Get the xpu capability of a device.
Args:
device (torch.device or int or str, optional): device for which to
return the device capability. This function is a no-op if this
argument is a negative integer. It uses the current device, given by
:func:`~torch.xpu.current_device`, if :attr:`device` is ``None``
(default).
Returns:
dict[str, Any]: the xpu capability dictionary of the device
get_device_name(device: 'Device' = None) -> 'str'
Get the name of a device.
Args:
device (torch.device or int or str, optional): device for which to
return the name. This function is a no-op if this argument is a
negative integer. It uses the current device, given by :func:`~torch.xpu.current_device`,
if :attr:`device` is ``None`` (default).
Returns:
str: the name of the device
get_device_properties(device: 'Device' = None) -> '_XpuDeviceProperties'
Get the properties of a device. Returns _XpuDeviceProperties containing the following device properties:
- ``name`` (str): device name.
- ``platform_name`` (str): SYCL platform name.
- ``vendor`` (str): device vendor.
- ``device_id`` (int): device identifier (product ID).
- ``driver_version`` (str): driver version.
- ``version`` (str): runtime version.
- ``max_compute_units`` (int): number of parallel compute units.
- ``gpu_eu_count`` (int): number of EUs (Execution Unit).
- ``max_work_group_size``: (int): maximum number of work-items permitted in a work-group.
- ``max_num_sub_groups`` (int): maximum number of sub-groups supported in a work-group.
- ``memory_clock_rate`` (int) maximum clock rate of device's global memory in MHz.
- ``memory_bus_width`` (int) maximum bus width between device and memory in bits.
- ``sub_group_sizes``: (list[int]): a list of supported sub-group sizes.
- ``local_mem_size`` (int): device local memory capacity that can be allocated per work-group in bytes.
- ``last_level_cache_size`` (int): size in bytes of the device's last-level memory cache, shared across all Xe Cores (analogous to CUDA ``L2_cache_size``).
- ``has_fp16`` (bool): whether float16 dtype is supported.
- ``has_fp64`` (bool): whether float64 dtype is supported.
- ``has_atomic64`` (bool): whether 64-bit atomic operations are supported.
- ``has_bfloat16_conversions`` (bool): whether bfloat16 conversions are supported.
- ``has_subgroup_matrix_multiply_accumulate`` (bool): whether DPAS (Dot Product Accumulate Systolic) is supported.
- ``has_subgroup_matrix_multiply_accumulate_tensor_float32`` (bool): whether DPAS with tf32 inputs is supported.
- ``has_subgroup_2d_block_io`` (bool): whether 2D block I/O for efficient matrix multiplication is supported.
- ``is_integrated_gpu`` (bool): whether the device is an integrated GPU (iGPU).
- ``total_memory`` (int): device global memory in bytes.
- ``gpu_subslice_count`` (int): number of subslice.
- ``architecture`` (int): device architecture identifier (experimental).
- ``type`` (str): device type, e.g. 'cpu', 'gpu', accelerator', 'host', 'unknown'.
- ``uuid`` (Any): device UUID (Universal Unique ID), 16 bytes.
Args:
device (torch.device or int or str): device for which to return the
properties of the device.
Returns:
_XpuDeviceProperties: the properties of the device
get_gencode_flags() -> 'str'
Return XPU AOT(ahead-of-time) build flags this library was compiled with.
get_per_process_memory_fraction(device: torch.device | str | int | None = None) -> float
Retrieve the memory fraction currently set for a process on a given XPU device.
This fraction represents the portion of the total device memory that
the caching allocator is allowed to use. The allowed memory is calculated as:
.. math:: \text{allowed\_memory} = \text{total\_memory} \times \text{fraction}
Args:
device (torch.device or int or str, optional): selected device. It uses the current device,
given by :func:`~torch.xpu.current_device`, if :attr:`device` is ``None`` (default).
Returns:
float: The memory fraction in the range 0.0 to 1.0.
get_rng_state(device: int | str | torch.device = 'xpu') -> torch.Tensor
Return the random number generator state of the specified GPU as a ByteTensor.
Args:
device (torch.device or int, optional): The device to return the RNG state of.
Default: ``'xpu'`` (i.e., ``torch.device('xpu')``, the current XPU device).
.. warning::
This function eagerly initializes XPU.
get_rng_state_all() -> list[torch.Tensor]
Return a list of ByteTensor representing the random number states of all devices.
get_stream_from_external(data_ptr: 'int', device: 'Device' = None) -> 'Stream'
Return a :class:`Stream` from an external SYCL queue.
This function is used to wrap SYCL queue created in other libraries in order
to facilitate data exchange and multi-library interactions.
.. note:: This function doesn't manage the queue life-cycle, it is the user
responsibility to keep the referenced queue alive while this returned stream is
being used. The different SYCL queue pointers will result in distinct
:class:`Stream` objects, even if the SYCL queues they dereference are equivalent.
Args:
data_ptr(int): Integer representation of the `sycl::queue*` value passed externally.
device(torch.device or int, optional): the device where the queue was originally created.
It is the user responsibility to ensure the device is specified correctly.
graph_pool_handle() -> '_POOL_HANDLE'
Return an opaque token representing the id of a graph memory pool.
init() -> 'None'
Initialize PyTorch's XPU state.
This is a Python API about lazy initialization that avoids initializing
XPU until the first time it is accessed. Does nothing if the XPU state is
already initialized.
initial_seed() -> int
Return the current random seed of the current GPU.
.. warning::
This function eagerly initializes XPU.
is_available() -> 'bool'
Return a bool indicating if XPU is currently available.
is_bf16_supported(including_emulation: 'bool' = True) -> 'bool'
Return a bool indicating if the current XPU device supports dtype bfloat16.
is_current_stream_capturing() -> 'bool'
Return True if XPU graph capture is underway on the current XPU stream, False otherwise.
If a XPU context does not exist on the current device, returns False without initializing the context.
is_initialized()
Return whether PyTorch's XPU state has been initialized.
is_tf32_supported() -> 'bool'
Return a bool indicating if the current XPU device supports dtype tf32.
make_graphed_callables(callables: '_ModuleOrCallable | tuple[_ModuleOrCallable, ...]', sample_args: 'tuple[Tensor, ...] | tuple[tuple[Tensor, ...], ...]', num_warmup_iters: 'int' = 3, allow_unused_input: 'bool' = False, pool: '_POOL_HANDLE | None' = None) -> '_ModuleOrCallable | tuple[_ModuleOrCallable, ...]'
Accept callables (functions or :class:`nn.Module<torch.nn.Module>`\ s) and returns graphed versions.
Each graphed callable's forward pass runs its source callable's
forward XPU work as a XPU graph inside a single autograd node.
The graphed callable's forward pass also appends
a backward node to the autograd graph. During backward, this node runs the
callable's backward work as a XPU graph.
Therefore, each graphed callable should be a drop-in replacement for its source callable
in an autograd-enabled training loop.
See :ref:`Partial-network capture<partial-network-capture>` for detailed use and constraints.
If you pass a tuple of several callables, their captures will use the same memory pool.
Arguments:
callables (torch.nn.Module or Python function, or tuple of these): Callable or callables to graph.
If you pass a tuple of callables, their order in the tuple must be the same order they'll run
in the live workload.
sample_args (tuple of Tensors, or tuple of tuples of Tensors): Samples args for each callable.
If a single callable was passed, ``sample_args`` must be a single tuple of argument Tensors.
If a tuple of callables was passed, ``sample_args`` must be tuple of tuples of argument Tensors.
num_warmup_iters (int): The number of warmup iterations. Currently, ``DataDistributedParallel`` needs
11 iterations for warm up. Default: ``3``.
allow_unused_input (bool): If False, specifying inputs that were not used when computing outputs
(and therefore their grad is always zero) is an error. Defaults to False.
pool (optional): Token (returned by :func:`~torch.xpu.graph_pool_handle` or
:meth:`other_Graph_instance.pool()<torch.xpu.XPUGraph.pool>`) that hints this graph may share memory
with the indicated pool.
.. note::
The ``requires_grad`` state of each Tensor in ``sample_args`` must match the state
that's expected for the corresponding real input in the training loop.
.. warning::
This API is in beta and may change in future releases.
.. warning::
``sample_args`` for each callable must contain only Tensors. Other types are not allowed.
.. warning::
Returned callables do not support higher order differentiation (e.g., double backward).
.. warning::
In any :class:`~torch.nn.Module` passed to :func:`~make_graphed_callables`, only parameters
may be trainable. Buffers must have ``requires_grad=False``.
.. warning::
After you pass a :class:`torch.nn.Module` through :func:`~make_graphed_callables`,
you may not add or remove any of that Module's parameters or buffers.
.. warning::
:class:`torch.nn.Module`\s passed to :func:`~torch.xpu.make_graphed_callables` must not have module hooks
registered on them at the time they are passed. However, registering hooks on modules *after* passing them
through :func:`~torch.xpu.make_graphed_callables` is allowed.
.. warning::
When running a graphed callable, you must pass its arguments in the same order and format
they appeared in that callable's ``sample_args``.
.. warning::
The automatic mixed precision is supported in :func:`~torch.xpu.make_graphed_callables` only with disabled
caching. The context manager `torch.amp.autocast()` must have `cache_enabled=False`.
manual_seed(seed: int) -> None
Set the seed for generating random numbers for the current GPU.
It's safe to call this function if XPU is not available; in that case, it is silently ignored.
Args:
seed (int): The desired seed.
.. warning::
If you are working with a multi-GPU model, this function is insufficient
to get determinism. To seed all GPUs, use :func:`manual_seed_all`.
manual_seed_all(seed: int) -> None
Set the seed for generating random numbers on all GPUs.
It's safe to call this function if XPU is not available; in that case, it is silently ignored.
Args:
seed (int): The desired seed.
max_memory_allocated(device: torch.device | str | int | None = None) -> int
Return the maximum GPU memory occupied by tensors in bytes for a given device.
By default, this returns the peak allocated memory since the beginning of
this program. :func:`~torch.xpu.reset_peak_memory_stats` can be used to
reset the starting point in tracking this metric. For example, these two
functions can measure the peak allocated memory usage of each iteration in a
training loop.
Args:
device (torch.device or int or str, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.xpu.current_device`,
if :attr:`device` is ``None`` (default).
max_memory_reserved(device: torch.device | str | int | None = None) -> int
Return the maximum GPU memory managed by the caching allocator in bytes for a given device.
By default, this returns the peak cached memory since the beginning of this
program. :func:`~torch.xpu.reset_peak_memory_stats` can be used to reset
the starting point in tracking this metric. For example, these two functions
can measure the peak cached memory amount of each iteration in a training
loop.
Args:
device (torch.device or int or str, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.xpu.current_device`,
if :attr:`device` is ``None`` (default).
mem_get_info(device: torch.device | str | int | None = None) -> tuple[int, int]
Return the global free and total GPU memory for a given device.
Args:
device (torch.device or int or str, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.xpu.current_device`,
if :attr:`device` is ``None`` (default).
Returns:
tuple[int, int]: a tuple of two integers (free_memory, total_memory) in bytes.
The first value is the free memory on the device (available across all processes and applications),
The second value is the device's total hardware memory capacity.
memory_allocated(device: torch.device | str | int | None = None) -> int
Return the current GPU memory occupied by tensors in bytes for a given device.
Args:
device (torch.device or int or str, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.xpu.current_device`,
if :attr:`device` is ``None`` (default).
.. note::
This is likely less than the amount shown in `xpu-smi` since some
unused memory can be held by the caching allocator and some context
needs to be created on GPU.
memory_reserved(device: torch.device | str | int | None = None) -> int
Return the current GPU memory managed by the caching allocator in bytes for a given device.
Args:
device (torch.device or int or str, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.xpu.current_device`,
if :attr:`device` is ``None`` (default).
memory_snapshot(mempool_id: tuple[int, int] | None = None) -> list[dict[str, typing.Any]]
Return a snapshot of the XPU memory allocator state across all devices.
Provides detailed information for each memory segment managed by the allocator
including its size, owning pool, associated stream, call stack traces, and other relevant attributes.
Arguments:
mempool_id (tuple[int, int] or None, optional): The memory pool id. If None, the default memory pool is used.
Returns:
list[dict[str, Any]]: List of memory segments and their attributes.
memory_stats(device: torch.device | str | int | None = None) -> dict[str, typing.Any]
Return a dictionary of XPU memory allocator statistics for a given device.
The return value of this function is a dictionary of statistics, each of
which is a non-negative integer.
Core statistics:
- ``"allocated_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
amount of allocated memory.
- ``"reserved_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
amount of reserved memory.
- ``"active_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
amount of active memory.
- ``"requested_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"``:
memory requested by client code, compare this with allocated_bytes to check if
allocation rounding adds too much overhead.
For these core statistics, values are broken down as follows.
Pool type:
- ``all``: combined statistics across all memory pools.
- ``large_pool``: statistics for the large allocation pool (for size >= 1MB allocations).
- ``small_pool``: statistics for the small allocation pool (for size < 1MB allocations).
Metric type:
- ``current``: current value of this metric.
- ``peak``: maximum value of this metric.
- ``allocated``: historical total increase in this metric.
- ``freed``: historical total decrease in this metric.
Args:
device (torch.device or int or str, optional): selected device. Returns
statistics for the current device, given by :func:`~torch.xpu.current_device`,
if :attr:`device` is ``None`` (default).
memory_stats_as_nested_dict(device: torch.device | str | int | None = None) -> dict[str, typing.Any]
Return the result of :func:`~torch.xpu.memory_stats` as a nested dictionary.
memory_usage(device: 'Device' = None) -> 'float'
Return the GPU memory bandwidth usage as a percentage.
The value is computed by dividing the byte-transfer delta by the time delta
between two bandwidth-counter reads separated by a 100ms sampling interval,
then normalizing by the peak bandwidth reported by the hardware.
Args:
device (torch.device, str or int, optional): selected device. Uses the
current device, given by :func:`~torch.xpu.current_device`,
if ``None`` (default).
.. note:: This function blocks for approximately 100ms per call due to the
sampling interval required to compute an accurate bandwidth reading.
.. note:: This API may require elevated privileges (e.g. ``sudo``) to access GPU memory bandwidth usage information.
power_draw(device: 'Device' = None) -> 'float'
Return the GPU card power draw in watts.
The value is computed by dividing the energy delta by the time delta between
two energy-counter reads separated by a 100ms sampling interval.
Args:
device (torch.device, str or int, optional): selected device. Uses the
current device, given by :func:`~torch.xpu.current_device`,
if ``None`` (default).
.. note:: This function blocks for approximately 100ms per call due to the
sampling interval required to compute an accurate power reading.
.. note:: This API may require elevated privileges (e.g. ``sudo``) to access GPU power information.
reset_accumulated_memory_stats(device: torch.device | str | int | None = None) -> None
Reset the "accumulated" (historical) stats tracked by the XPU memory allocator.
See :func:`~torch.xpu.memory_stats` for details. Accumulated stats correspond to
the `"allocated"` and `"freed"` keys in each individual stat dict.
Args:
device (torch.device or int or str, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.xpu.current_device`,
if :attr:`device` is ``None`` (default).
reset_peak_memory_stats(device: torch.device | str | int | None = None) -> None
Reset the "peak" stats tracked by the XPU memory allocator.
See :func:`~torch.xpu.memory_stats` for details. Peak stats correspond to the
`"peak"` key in each individual stat dict.
Args:
device (torch.device or int or str, optional): selected device. Returns
statistic for the current device, given by :func:`~torch.xpu.current_device`,
if :attr:`device` is ``None`` (default).
seed() -> None
Set the seed for generating random numbers to a random number for the current GPU.
It's safe to call this function if XPU is not available; in that case, it is silently ignored.
.. warning::
If you are working with a multi-GPU model, this function will only initialize
the seed on one GPU. To initialize all GPUs, use :func:`seed_all`.
seed_all() -> None
Set the seed for generating random numbers to a random number on all GPUs.
It's safe to call this function if XPU is not available; in that case, it is silently ignored.
set_device(device: 'Device') -> 'None'
Set the current device.
Args:
device (torch.device or int or str): selected device. This function is a
no-op if this argument is negative.
set_per_process_memory_fraction(fraction: float, device: torch.device | str | int | None = None) -> None
Set the memory fraction for a single process on XPU device.
This function limits the amount of memory that the caching allocator can allocate
on the specified XPU device. The allowed memory is computed as:
.. math:: \text{allowed\_memory} = \text{total\_memory} \times \text{fraction}
If the process attempts to allocate more than this allowed memory,
an out-of-memory error will be raised by the allocator.
Arguments:
fraction (float): Range: 0~1. Allowed memory equals total_memory * fraction.
device (torch.device or int or str, optional): selected device. It uses the current device,
given by :func:`~torch.xpu.current_device`, if :attr:`device` is ``None`` (default).
.. note:: In general, the total available free memory is less than the total capacity.
set_rng_state(new_state: torch.Tensor, device: int | str | torch.device = 'xpu') -> None
Set the random number generator state of the specified GPU.
Args:
new_state (torch.ByteTensor): The desired state
device (torch.device or int, optional): The device to set the RNG state.
Default: ``'xpu'`` (i.e., ``torch.device('xpu')``, the current XPU device).
set_rng_state_all(new_states: collections.abc.Iterable[torch.Tensor]) -> None
Set the random number generator state of all devices.
Args:
new_states (Iterable of torch.ByteTensor): The desired state for each device.
set_stream(stream: 'Stream') -> 'None'
Set the current stream. This is a wrapper API to set the stream.
Usage of this function is discouraged in favor of the ``stream``
context manager.
Args:
stream (Stream): selected stream. This function is a no-op
if this argument is ``None``.
stream(stream: 'torch.xpu.Stream | None') -> 'StreamContext'
Wrap around the Context-manager StreamContext that selects a given stream.
Arguments:
stream (Stream): selected stream. This manager is a no-op if it's ``None``.
synchronize(device: 'Device' = None) -> 'None'
Wait for all kernels in all streams on a XPU device to complete.
Args:
device (torch.device or int, optional): device for which to synchronize.
It uses the current device, given by :func:`~torch.xpu.current_device`,
if :attr:`device` is ``None`` (default).
temperature(device: 'Device' = None) -> 'float'
Return the GPU temperature in degrees Celsius.
Args:
device (torch.device, str or int, optional): selected device. Uses the
current device, given by :func:`~torch.xpu.current_device`,
if ``None`` (default).
.. note:: This API may require elevated privileges (e.g. ``sudo``) to access GPU temperature information.
use_mem_pool(pool: torch.xpu.memory.MemPool, device: 'Device' = None)
A context manager that routes allocations to a given pool.
Args:
pool(torch.xpu.MemPool): a :class:`MemPool` object to be made active so that
allocations route to this pool.
device (torch.device or int, optional): selected device. Uses :class:`MemPool on
the current device, given by :func:`~torch.xpu.current_device`,
if :attr:`device` is ``None`` (default).
.. note::
This context manager makes only current thread's allocations route to
the given pool. If a new thread is spawned inside the context manager
(e.g. by calling backward) the allocations in that thread will not
route to the given pool.
utilization(device: 'Device' = None) -> 'float'
Return the GPU engine utilization as a percentage.
The value is computed by dividing the active-time delta by the time delta
between two engine-activity reads separated by a 100ms sampling interval.
Args:
device (torch.device, str or int, optional): selected device. Uses the
current device, given by :func:`~torch.xpu.current_device`,
if ``None`` (default).
.. note:: This function blocks for approximately 100ms per call due to the
sampling interval required to compute an accurate utilization reading.
.. note:: This API may require elevated privileges (e.g. ``sudo``) to access GPU utilization information.
DATA
__all__ = ['Event', 'Stream', 'StreamContext', 'XPUPluggableAllocator'...
__annotations__ = {'_cached_device_count': 'int | None', '_cached_zes_...
default_generators = ()
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\torch\xpu\__init__.py
torch.zero_
Python Library Documentation: built-in function zero_ in module torch zero_(...)
torch.zeros
Python Library Documentation: built-in function zeros in module torch
zeros(...)
zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a tensor filled with the scalar value `0`, with the shape defined
by the variable argument :attr:`size`.
Args:
size (int...): a sequence of integers defining the shape of the output tensor.
Can be a variable number of arguments or a collection like a list or tuple.
Keyword args:
out (Tensor, optional): the output tensor.
dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.
Default: if ``None``, uses a global default (see :func:`torch.set_default_dtype`).
layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.
Default: ``torch.strided``.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, uses the current device for the default tensor type
(see :func:`torch.set_default_device`). :attr:`device` will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.zeros(2, 3)
tensor([[ 0., 0., 0.],
[ 0., 0., 0.]])
>>> torch.zeros(5)
tensor([ 0., 0., 0., 0., 0.])
torch.zeros_like
Python Library Documentation: built-in function zeros_like in module torch
zeros_like(...)
zeros_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) -> Tensor
Returns a tensor filled with the scalar value `0`, with the same size as
:attr:`input`. ``torch.zeros_like(input)`` is equivalent to
``torch.zeros(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)``.
.. warning::
As of 0.4, this function does not support an :attr:`out` keyword. As an alternative,
the old ``torch.zeros_like(input, out=output)`` is equivalent to
``torch.zeros(input.size(), out=output)``.
Args:
input (Tensor): the size of :attr:`input` will determine size of the output tensor.
Keyword args:
dtype (:class:`torch.dtype`, optional): the desired data type of returned Tensor.
Default: if ``None``, defaults to the dtype of :attr:`input`.
layout (:class:`torch.layout`, optional): the desired layout of returned tensor.
Default: if ``None``, defaults to the layout of :attr:`input`.
device (:class:`torch.device`, optional): the desired device of returned tensor.
Default: if ``None``, defaults to the device of :attr:`input`.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
memory_format (:class:`torch.memory_format`, optional): the desired memory format of
returned Tensor. Default: ``torch.preserve_format``.
Example::
>>> input = torch.empty(2, 3)
>>> torch.zeros_like(input)
tensor([[ 0., 0., 0.],
[ 0., 0., 0.]])